diff --git a/crates/metaslang/bindings/src/lib.rs b/crates/metaslang/bindings/src/lib.rs index fc6066458..af852723b 100644 --- a/crates/metaslang/bindings/src/lib.rs +++ b/crates/metaslang/bindings/src/lib.rs @@ -268,11 +268,6 @@ impl Bindings { .collect() } - pub fn lookup_definition_by_name(&self, name: &str) -> Option> { - self.all_definitions() - .find(|definition| definition.get_cursor().unwrap().node().unparse() == name) - } - pub fn get_context(&self) -> Option> { self.context.and_then(|handle| self.to_definition(handle)) } diff --git a/crates/solidity/outputs/cargo/tests/src/bindings.rs b/crates/solidity/outputs/cargo/tests/src/bindings.rs index c346ab6af..40c354f01 100644 --- a/crates/solidity/outputs/cargo/tests/src/bindings.rs +++ b/crates/solidity/outputs/cargo/tests/src/bindings.rs @@ -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; @@ -26,3 +26,9 @@ pub fn create_bindings(version: &Version) -> Result { 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> { + bindings + .all_definitions() + .find(|definition| definition.get_cursor().unwrap().node().unparse() == name) +} diff --git a/crates/solidity/outputs/cargo/tests/src/bindings_assertions/runner.rs b/crates/solidity/outputs/cargo/tests/src/bindings_assertions/runner.rs index fc009f9a6..1c92493c1 100644 --- a/crates/solidity/outputs/cargo/tests/src/bindings_assertions/runner.rs +++ b/crates/solidity/outputs/cargo/tests/src/bindings_assertions/runner.rs @@ -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, }; @@ -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); diff --git a/crates/solidity/outputs/cargo/tests/src/bindings_output/runner.rs b/crates/solidity/outputs/cargo/tests/src/bindings_output/runner.rs index 80f0b05d0..031a1f9c7 100644 --- a/crates/solidity/outputs/cargo/tests/src/bindings_output/runner.rs +++ b/crates/solidity/outputs/cargo/tests/src/bindings_output/runner.rs @@ -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}; @@ -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);