From 8f322d760cde8b6e2b360e36baec27e9c23c3340 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20Gro=C3=9Fe?= Date: Fri, 21 Feb 2025 09:56:40 +0100 Subject: [PATCH 1/2] test: add test for long haystack --- src/lib.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 9166b2c..2aef07d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -199,6 +199,18 @@ mod tests { assert_eq!(matches[3].index_in_haystack, 1); } + #[test] + fn test_long() { + let needle = "A"; + let long_word: String = std::iter::repeat("B").take(513).collect(); + let haystack = vec!["A",long_word.as_str()]; + + let matches = match_list(needle, &haystack, Options::default()); + assert_eq!(matches.len(), 2); + assert_eq!(matches[0].index_in_haystack, 0); + } + + #[test] fn test_no_typos() { let needle = "deadbe"; From a4bb8d645b53e0dcdf1a616b61cfedeb9a731af0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20Gro=C3=9Fe?= Date: Fri, 21 Feb 2025 10:02:25 +0100 Subject: [PATCH 2/2] test: adapt test to search for long word --- src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 2aef07d..1ceca2f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -201,13 +201,13 @@ mod tests { #[test] fn test_long() { - let needle = "A"; + let needle = "B"; let long_word: String = std::iter::repeat("B").take(513).collect(); let haystack = vec!["A",long_word.as_str()]; let matches = match_list(needle, &haystack, Options::default()); assert_eq!(matches.len(), 2); - assert_eq!(matches[0].index_in_haystack, 0); + assert_eq!(matches[0].index_in_haystack, 1); }