Skip to content

Commit

Permalink
Move lookup_definition_by_name to tests crate
Browse files Browse the repository at this point in the history
  • Loading branch information
ggiraldez committed Nov 27, 2024
1 parent d8730de commit ad4e21e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
5 changes: 0 additions & 5 deletions crates/metaslang/bindings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,6 @@ impl<KT: KindTypes + 'static> Bindings<KT> {
.collect()
}

pub fn lookup_definition_by_name(&self, name: &str) -> Option<Definition<'_, KT>> {
self.all_definitions()
.find(|definition| definition.get_cursor().unwrap().node().unparse() == name)
}

pub fn get_context(&self) -> Option<Definition<'_, KT>> {
self.context.and_then(|handle| self.to_definition(handle))
}
Expand Down
8 changes: 7 additions & 1 deletion crates/solidity/outputs/cargo/tests/src/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::sync::Arc;

use anyhow::Result;
use semver::Version;
use slang_solidity::bindings::{self, Bindings};
use slang_solidity::bindings::{self, Bindings, Definition};
use slang_solidity::cst::TextIndex;
use slang_solidity::parser::Parser;
use slang_solidity::transform_built_ins_node;
Expand All @@ -26,3 +26,9 @@ pub fn create_bindings(version: &Version) -> Result<Bindings> {
bindings.add_system_file("built_ins.sol", built_ins_cursor);
Ok(bindings)
}

pub fn lookup_definition_by_name<'a>(bindings: &'a Bindings, name: &str) -> Option<Definition<'a>> {
bindings
.all_definitions()
.find(|definition| definition.get_cursor().unwrap().node().unparse() == name)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use semver::Version;
use slang_solidity::diagnostic;
use slang_solidity::parser::Parser;

use crate::bindings::create_bindings;
use crate::bindings::{create_bindings, lookup_definition_by_name};
use crate::bindings_assertions::assertions::{
check_assertions, collect_assertions_into, Assertions,
};
Expand Down Expand Up @@ -63,8 +63,7 @@ fn check_assertions_with_version(version: &Version, contents: &str) -> Result<()
}

if let Some(context) = multi_part.context {
let context_definition = bindings
.lookup_definition_by_name(context)
let context_definition = lookup_definition_by_name(&bindings, context)
.expect("context definition to be found")
.to_handle();
bindings.set_context(&context_definition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use slang_solidity::parser::{ParseOutput, Parser};
use super::graph::graphviz::render as render_graphviz_graph;
use super::graph::mermaid::render as render_mermaid_graph;
use super::renderer::render_bindings;
use crate::bindings::create_bindings;
use crate::bindings::{create_bindings, lookup_definition_by_name};
use crate::generated::VERSION_BREAKS;
use crate::multi_part_file::{split_multi_file, Part};

Expand Down Expand Up @@ -58,8 +58,7 @@ pub fn run(group_name: &str, test_name: &str) -> Result<()> {
}

if let Some(context) = multi_part.context {
let context_definition = bindings
.lookup_definition_by_name(context)
let context_definition = lookup_definition_by_name(&bindings, context)
.expect("context definition to be found")
.to_handle();
bindings.set_context(&context_definition);
Expand Down

0 comments on commit ad4e21e

Please sign in to comment.