From 7625133102a757218c74d2aa3c95dbddc53a2b39 Mon Sep 17 00:00:00 2001 From: Riccardo Mazzarini Date: Sat, 28 Oct 2023 10:34:46 +0200 Subject: [PATCH] tests: add remaining fzf fuzzy tests from upstream --- tests/fzf_common.rs | 193 ++++++++++++++++++++++++++++++++++++++++++-- tests/fzf_v1.rs | 93 +++++++++++++++++---- tests/fzf_v2.rs | 93 +++++++++++++++++---- 3 files changed, 344 insertions(+), 35 deletions(-) diff --git a/tests/fzf_common.rs b/tests/fzf_common.rs index ce9e6a2..57bbc43 100644 --- a/tests/fzf_common.rs +++ b/tests/fzf_common.rs @@ -9,7 +9,7 @@ pub fn empty_query() { assert!(m.is_none()); } -pub fn upstream_1() { +pub fn upstream_fuzzy_1() { let (_, m) = fzf::(Insensitive, "oBZ", "fooBarbaz1"); let m = m.unwrap(); @@ -24,7 +24,7 @@ pub fn upstream_1() { assert_eq!(m.matched_ranges().sorted(), [2..4, 8..9]); } -pub fn upstream_2() { +pub fn upstream_fuzzy_2() { let (fzf, m) = fzf::(Insensitive, "fbb", "foo bar baz"); let m = m.unwrap(); @@ -42,7 +42,7 @@ pub fn upstream_2() { assert_eq!(m.matched_ranges().sorted(), [0..1, 4..5, 8..9]); } -pub fn upstream_3() { +pub fn upstream_fuzzy_3() { let (_, m) = fzf::(Insensitive, "rdoc", "/AutomatorDocument.icns"); let m = m.unwrap(); @@ -55,7 +55,7 @@ pub fn upstream_3() { assert_eq!(m.matched_ranges().sorted(), [9..13]); } -pub fn upstream_4() { +pub fn upstream_fuzzy_4() { let (fzf, m) = fzf::(Insensitive, "zhsc", "/man1/zshcompctl.1"); let m = m.unwrap(); @@ -70,7 +70,7 @@ pub fn upstream_4() { assert_eq!(m.matched_ranges().sorted(), [6..10]); } -pub fn upstream_5() { +pub fn upstream_fuzzy_5() { let (fzf, m) = fzf::(Insensitive, "zhsc", "/.oh-my-zsh/cache"); let m = m.unwrap(); @@ -86,7 +86,7 @@ pub fn upstream_5() { assert_eq!(m.matched_ranges().sorted(), [8..11, 12..13]); } -pub fn upstream_6() { +pub fn upstream_fuzzy_6() { let (_, m) = fzf::(Insensitive, "12356", "ab0123 456"); let m = m.unwrap(); @@ -101,7 +101,7 @@ pub fn upstream_6() { assert_eq!(m.matched_ranges().sorted(), [3..6, 8..10]); } -pub fn upstream_7() { +pub fn upstream_fuzzy_7() { let (_, m) = fzf::(Insensitive, "12356", "abc123 456"); let m = m.unwrap(); @@ -118,6 +118,185 @@ pub fn upstream_7() { assert_eq!(m.matched_ranges().sorted(), [3..6, 8..10]); } +pub fn upstream_fuzzy_8() { + let (fzf, m) = fzf::(Insensitive, "fbb", "foo/bar/baz"); + + let m = m.unwrap(); + + assert_eq!( + m.distance().into_score(), + 3 * bonus::MATCH + + bonus::FIRST_QUERY_CHAR_MULTIPLIER + * fzf.scheme().bonus_boundary_white + + 2 * fzf.scheme().bonus_boundary_delimiter + - 2 * penalty::GAP_START + - 4 * penalty::GAP_EXTENSION + ); + + assert_eq!(m.matched_ranges().sorted(), [0..1, 4..5, 8..9]); +} + +pub fn upstream_fuzzy_9() { + let (fzf, m) = fzf::(Insensitive, "fbb", "fooBarBaz"); + + let m = m.unwrap(); + + assert_eq!( + m.distance().into_score(), + 3 * bonus::MATCH + + bonus::FIRST_QUERY_CHAR_MULTIPLIER + * fzf.scheme().bonus_boundary_white + + 2 * bonus::CAMEL_123 + - 2 * penalty::GAP_START + - 4 * penalty::GAP_EXTENSION + ); + + assert_eq!(m.matched_ranges().sorted(), [0..1, 4..5, 8..9]); +} + +pub fn upstream_fuzzy_10() { + let (fzf, m) = fzf::(Insensitive, "fbb", "foo barbaz"); + + let m = m.unwrap(); + + assert_eq!( + m.distance().into_score(), + 3 * bonus::MATCH + + (bonus::FIRST_QUERY_CHAR_MULTIPLIER + 1) + * fzf.scheme().bonus_boundary_white + - 2 * penalty::GAP_START + - 3 * penalty::GAP_EXTENSION + ); + + assert_eq!(m.matched_ranges().sorted(), [0..1, 4..5, 7..8]); +} + +pub fn upstream_fuzzy_11() { + let (fzf, m) = fzf::(Insensitive, "foob", "fooBar Baz"); + + let m = m.unwrap(); + + assert_eq!( + m.distance().into_score(), + 4 * bonus::MATCH + + (bonus::FIRST_QUERY_CHAR_MULTIPLIER + 3) + * fzf.scheme().bonus_boundary_white + ); + + assert_eq!(m.matched_ranges().sorted(), [0..4]); +} + +pub fn upstream_fuzzy_12() { + let (_, m) = fzf::(Insensitive, "foo-b", "xFoo-Bar Baz"); + + let m = m.unwrap(); + + assert_eq!( + m.distance().into_score(), + 5 * bonus::MATCH + + (bonus::FIRST_QUERY_CHAR_MULTIPLIER + 2) * bonus::CAMEL_123 + + bonus::NON_WORD + + bonus::BOUNDARY + ); + + assert_eq!(m.matched_ranges().sorted(), [1..6]); +} + +pub fn upstream_fuzzy_13() { + let (_, m) = fzf::(Sensitive, "oBz", "fooBarbaz"); + + let m = m.unwrap(); + + assert_eq!( + m.distance().into_score(), + 3 * bonus::MATCH + bonus::CAMEL_123 + - penalty::GAP_START + - 3 * penalty::GAP_EXTENSION + ); + + assert_eq!(m.matched_ranges().sorted(), [2..4, 8..9]); +} + +pub fn upstream_fuzzy_14() { + let (fzf, m) = fzf::(Sensitive, "FBB", "Foo/Bar/Baz"); + + let m = m.unwrap(); + + assert_eq!( + m.distance().into_score(), + 3 * bonus::MATCH + + bonus::FIRST_QUERY_CHAR_MULTIPLIER + * fzf.scheme().bonus_boundary_white + + 2 * fzf.scheme().bonus_boundary_delimiter + - 2 * penalty::GAP_START + - 4 * penalty::GAP_EXTENSION + ); + + assert_eq!(m.matched_ranges().sorted(), [0..1, 4..5, 8..9]); +} + +pub fn upstream_fuzzy_15() { + let (fzf, m) = fzf::(Sensitive, "FBB", "FooBarBaz"); + + let m = m.unwrap(); + + assert_eq!( + m.distance().into_score(), + 3 * bonus::MATCH + + bonus::FIRST_QUERY_CHAR_MULTIPLIER + * fzf.scheme().bonus_boundary_white + + 2 * bonus::CAMEL_123 + - 2 * penalty::GAP_START + - 2 * penalty::GAP_EXTENSION + ); + + assert_eq!(m.matched_ranges().sorted(), [0..1, 3..4, 6..7]); +} + +pub fn upstream_fuzzy_16() { + let (fzf, m) = fzf::(Sensitive, "FooB", "FooBar Baz"); + + let m = m.unwrap(); + + assert_eq!( + m.distance().into_score(), + 4 * bonus::MATCH + + (bonus::FIRST_QUERY_CHAR_MULTIPLIER + 2) + * fzf.scheme().bonus_boundary_white + + bonus::CAMEL_123.max(fzf.scheme().bonus_boundary_white) + ); + + assert_eq!(m.matched_ranges().sorted(), [0..4]); +} + +pub fn upstream_fuzzy_17() { + let (_, m) = fzf::(Sensitive, "o-ba", "foo-bar"); + + let m = m.unwrap(); + + assert_eq!( + m.distance().into_score(), + 4 * bonus::MATCH + 3 * bonus::BOUNDARY + ); + + assert_eq!(m.matched_ranges().sorted(), [2..6]); +} + +pub fn upstream_fuzzy_18() { + let (_, m) = fzf::(Sensitive, "oBZ", "fooBarbaz"); + assert!(m.is_none()); +} + +pub fn upstream_fuzzy_19() { + let (_, m) = fzf::(Sensitive, "fbb", "Foo Bar Baz"); + assert!(m.is_none()); +} + +pub fn upstream_fuzzy_20() { + let (_, m) = fzf::(Sensitive, "fooBarbazz", "fooBarbaz"); + assert!(m.is_none()); +} + pub use utils::*; mod utils { diff --git a/tests/fzf_v1.rs b/tests/fzf_v1.rs index 9578ab8..8f53e9b 100644 --- a/tests/fzf_v1.rs +++ b/tests/fzf_v1.rs @@ -11,36 +11,101 @@ fn fzf_v1_empty_query() { } #[test] -fn fzf_v1_upstream_1() { - common::upstream_1::(); +fn fzf_v1_upstream_fuzzy_1() { + common::upstream_fuzzy_1::(); } #[test] -fn fzf_v1_upstream_2() { - common::upstream_2::(); +fn fzf_v1_upstream_fuzzy_2() { + common::upstream_fuzzy_2::(); } #[test] -fn fzf_v1_upstream_3() { - common::upstream_3::() +fn fzf_v1_upstream_fuzzy_3() { + common::upstream_fuzzy_3::() } #[test] -fn fzf_v1_upstream_4() { - common::upstream_4::() +fn fzf_v1_upstream_fuzzy_4() { + common::upstream_fuzzy_4::() } #[test] -fn fzf_v1_upstream_5() { - common::upstream_5::() +fn fzf_v1_upstream_fuzzy_5() { + common::upstream_fuzzy_5::() } #[test] -fn fzf_v1_upstream_6() { - common::upstream_6::() +fn fzf_v1_upstream_fuzzy_6() { + common::upstream_fuzzy_6::() } #[test] -fn fzf_v1_upstream_7() { - common::upstream_7::() +fn fzf_v1_upstream_fuzzy_7() { + common::upstream_fuzzy_7::() +} + +#[test] +fn fzf_v1_upstream_fuzzy_8() { + common::upstream_fuzzy_8::(); +} + +#[test] +fn fzf_v1_upstream_fuzzy_9() { + common::upstream_fuzzy_9::(); +} + +#[test] +fn fzf_v1_upstream_fuzzy_10() { + common::upstream_fuzzy_10::(); +} + +#[test] +fn fzf_v1_upstream_fuzzy_11() { + common::upstream_fuzzy_11::(); +} + +#[test] +fn fzf_v1_upstream_fuzzy_12() { + common::upstream_fuzzy_12::(); +} + +#[test] +fn fzf_v1_upstream_fuzzy_13() { + common::upstream_fuzzy_13::(); +} + +#[test] +fn fzf_v1_upstream_fuzzy_14() { + common::upstream_fuzzy_14::(); +} + +#[test] +fn fzf_v1_upstream_fuzzy_15() { + common::upstream_fuzzy_15::(); +} + +#[test] +fn fzf_v1_upstream_fuzzy_16() { + common::upstream_fuzzy_16::(); +} + +#[test] +fn fzf_v1_upstream_fuzzy_17() { + common::upstream_fuzzy_17::(); +} + +#[test] +fn fzf_v1_upstream_fuzzy_18() { + common::upstream_fuzzy_18::(); +} + +#[test] +fn fzf_v1_upstream_fuzzy_19() { + common::upstream_fuzzy_19::(); +} + +#[test] +fn fzf_v1_upstream_fuzzy_fuzzy_20() { + common::upstream_fuzzy_20::(); } diff --git a/tests/fzf_v2.rs b/tests/fzf_v2.rs index 0da7eb5..628b847 100644 --- a/tests/fzf_v2.rs +++ b/tests/fzf_v2.rs @@ -13,38 +13,103 @@ fn fzf_v2_empty_query() { } #[test] -fn fzf_v2_upstream_1() { - common::upstream_1::(); +fn fzf_v2_upstream_fuzzy_1() { + common::upstream_fuzzy_1::(); } #[test] -fn fzf_v2_upstream_2() { - common::upstream_2::(); +fn fzf_v2_upstream_fuzzy_2() { + common::upstream_fuzzy_2::(); } #[test] -fn fzf_v2_upstream_3() { - common::upstream_3::(); +fn fzf_v2_upstream_fuzzy_3() { + common::upstream_fuzzy_3::(); } #[test] -fn fzf_v2_upstream_4() { - common::upstream_4::(); +fn fzf_v2_upstream_fuzzy_4() { + common::upstream_fuzzy_4::(); } #[test] -fn fzf_v2_upstream_5() { - common::upstream_5::(); +fn fzf_v2_upstream_fuzzy_5() { + common::upstream_fuzzy_5::(); } #[test] -fn fzf_v2_upstream_6() { - common::upstream_6::(); +fn fzf_v2_upstream_fuzzy_6() { + common::upstream_fuzzy_6::(); } #[test] -fn fzf_v2_upstream_7() { - common::upstream_7::(); +fn fzf_v2_upstream_fuzzy_7() { + common::upstream_fuzzy_7::(); +} + +#[test] +fn fzf_v2_upstream_fuzzy_8() { + common::upstream_fuzzy_8::(); +} + +#[test] +fn fzf_v2_upstream_fuzzy_9() { + common::upstream_fuzzy_9::(); +} + +#[test] +fn fzf_v2_upstream_fuzzy_10() { + common::upstream_fuzzy_10::(); +} + +#[test] +fn fzf_v2_upstream_fuzzy_11() { + common::upstream_fuzzy_11::(); +} + +#[test] +fn fzf_v2_upstream_fuzzy_12() { + common::upstream_fuzzy_12::(); +} + +#[test] +fn fzf_v2_upstream_fuzzy_13() { + common::upstream_fuzzy_13::(); +} + +#[test] +fn fzf_v2_upstream_fuzzy_14() { + common::upstream_fuzzy_14::(); +} + +#[test] +fn fzf_v2_upstream_fuzzy_15() { + common::upstream_fuzzy_15::(); +} + +#[test] +fn fzf_v2_upstream_fuzzy_16() { + common::upstream_fuzzy_16::(); +} + +#[test] +fn fzf_v2_upstream_fuzzy_17() { + common::upstream_fuzzy_17::(); +} + +#[test] +fn fzf_v2_upstream_fuzzy_18() { + common::upstream_fuzzy_18::(); +} + +#[test] +fn fzf_v2_upstream_fuzzy_19() { + common::upstream_fuzzy_19::(); +} + +#[test] +fn fzf_v2_upstream_fuzzy_20() { + common::upstream_fuzzy_20::(); } #[test]