From e5eccf4eaf6d9ac55bed1a0d8396f93ae0c3651b Mon Sep 17 00:00:00 2001 From: 0xMemoryGrinder <35138272+0xMemoryGrinder@users.noreply.github.com> Date: Tue, 9 Jan 2024 18:43:21 -0500 Subject: [PATCH] refactor(solidity/core/tests-positions-server): filter test functions based on foundry naming convention --- toolchains/solidity/core/Cargo.lock | 1 + .../solidity/core/crates/tests-positions-server/Cargo.toml | 3 ++- .../solidity/core/crates/tests-positions-server/src/main.rs | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/toolchains/solidity/core/Cargo.lock b/toolchains/solidity/core/Cargo.lock index e25237ce..45b0fec2 100644 --- a/toolchains/solidity/core/Cargo.lock +++ b/toolchains/solidity/core/Cargo.lock @@ -898,6 +898,7 @@ version = "0.3.0" dependencies = [ "osmium-libs-lsp-server-wrapper", "osmium-libs-solidity-ast-extractor", + "regex", "serde", "serde_json", "tokio", diff --git a/toolchains/solidity/core/crates/tests-positions-server/Cargo.toml b/toolchains/solidity/core/crates/tests-positions-server/Cargo.toml index 9be0d683..84aa3876 100644 --- a/toolchains/solidity/core/crates/tests-positions-server/Cargo.toml +++ b/toolchains/solidity/core/crates/tests-positions-server/Cargo.toml @@ -14,4 +14,5 @@ serde = { version = "1.0.149", features = ["derive"] } serde_json = "1.0.89" tokio = {version = "1.34.0", features = ["full"] } tower-lsp = "0.20.0" -osmium-libs-solidity-ast-extractor = { path = "../../../../../libs/ast-extractor", version = "0.1.2" } \ No newline at end of file +osmium-libs-solidity-ast-extractor = { path = "../../../../../libs/ast-extractor", version = "0.1.2" } +regex = "1.10.2" diff --git a/toolchains/solidity/core/crates/tests-positions-server/src/main.rs b/toolchains/solidity/core/crates/tests-positions-server/src/main.rs index a262db9d..63152c3f 100644 --- a/toolchains/solidity/core/crates/tests-positions-server/src/main.rs +++ b/toolchains/solidity/core/crates/tests-positions-server/src/main.rs @@ -59,12 +59,13 @@ impl Backend { pub fn extract_tests_positions(&self, ast: File) -> Result { let mut res = vec![]; + let re = regex::Regex::new(r"^test.*_.+").unwrap(); let contracts = retrieve_contract_nodes(&ast); for contract in contracts { let mut tests: Vec = vec![]; let mut functions = retrieve_functions_nodes(&contract); let contract_tests = functions.iter_mut().filter(|f| { - f.name.is_some() && f.name.as_ref().unwrap().as_string().starts_with("test") + f.name.is_some() && re.is_match(f.name.as_ref().unwrap().as_string().as_str()) }); for test in contract_tests { let name = match &test.name {