From ed6832f8da40272c342e08be1f295749b081365c Mon Sep 17 00:00:00 2001 From: Joao Duarte Date: Sat, 15 Jun 2024 16:48:29 -0300 Subject: [PATCH] test: add a sanity test --- Cargo.lock | 1 + matching/Cargo.toml | 1 + matching/tests/perfect_matching.rs | 55 ++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 matching/tests/perfect_matching.rs diff --git a/Cargo.lock b/Cargo.lock index 12af7ea..46ab217 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -343,6 +343,7 @@ dependencies = [ "log", "matching_handlers", "model", + "parsing", "pathfinding", "unordered-pair", "uuid", diff --git a/matching/Cargo.toml b/matching/Cargo.toml index 8058d77..6f00aa7 100644 --- a/matching/Cargo.toml +++ b/matching/Cargo.toml @@ -14,3 +14,4 @@ pathfinding = "4.9.1" [dev-dependencies] uuid = { workspace = true } +parsing = { path = "../parsing" } diff --git a/matching/tests/perfect_matching.rs b/matching/tests/perfect_matching.rs new file mode 100644 index 0000000..4bffd4d --- /dev/null +++ b/matching/tests/perfect_matching.rs @@ -0,0 +1,55 @@ +use matching::matching_configuration::MatchingConfiguration; +use model::language::Language; +use parsing::ParserConfiguration; + +#[test] +fn the_perfect_matching_calculation_is_correct() -> Result<(), Box> { + let config = ParserConfiguration::from(Language::Java); + let left = parsing::parse_string( + r#""" + public class Main { + static { + int x = 2; + } + + public static void main() { + int a = 0; + } + + public static void teste() { + + } + } + """#, + &config, + )?; + + let right = parsing::parse_string( + r#""" + public class Main { + public static void teste() { + + } + static { + int x = 2; + } + + public static void main() { + int a = 0; + + } + } + """#, + &config, + )?; + + let matching_configuration = MatchingConfiguration::from(Language::Java); + let matchings = matching::calculate_matchings(&left, &right, &matching_configuration); + assert!( + matchings + .get_matching_entry(&left, &right) + .unwrap() + .is_perfect_match + ); + Ok(()) +}