From ab4c0dd137f064b9a141d1341c546170b1c7272b Mon Sep 17 00:00:00 2001 From: Jacob Pratt Date: Sun, 19 Feb 2023 22:59:22 +0000 Subject: [PATCH] Add test for precise algorithm used --- compiler/rustc_span/src/edit_distance/tests.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/compiler/rustc_span/src/edit_distance/tests.rs b/compiler/rustc_span/src/edit_distance/tests.rs index 4b2373eb926..c9c7a1f1bf2 100644 --- a/compiler/rustc_span/src/edit_distance/tests.rs +++ b/compiler/rustc_span/src/edit_distance/tests.rs @@ -68,3 +68,13 @@ fn test_find_best_match_for_name() { ); }) } + +#[test] +fn test_precise_algorithm() { + // Not Levenshtein distance. + assert_ne!(edit_distance("ab", "ba", usize::MAX), Some(2)); + // Not unrestricted Damerau-Levenshtein distance. + assert_ne!(edit_distance("abde", "bcaed", usize::MAX), Some(3)); + // The current implementation is a restricted Damerau-Levenshtein distance. + assert_eq!(edit_distance("abde", "bcaed", usize::MAX), Some(4)); +}