From ad4e21efb4388f44c2708807253823410ff1f834 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustavo=20Gir=C3=A1ldez?= Date: Wed, 27 Nov 2024 15:45:15 -0500 Subject: [PATCH] Move `lookup_definition_by_name` to tests crate --- crates/metaslang/bindings/src/lib.rs | 5 ----- crates/solidity/outputs/cargo/tests/src/bindings.rs | 8 +++++++- .../outputs/cargo/tests/src/bindings_assertions/runner.rs | 5 ++--- .../outputs/cargo/tests/src/bindings_output/runner.rs | 5 ++--- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/crates/metaslang/bindings/src/lib.rs b/crates/metaslang/bindings/src/lib.rs index fc60664582..af852723b5 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 c346ab6afb..40c354f01e 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 fc009f9a68..1c92493c10 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 80f0b05d0e..031a1f9c7a 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);