Skip to content

Commit

Permalink
tests: add more fzf tests from upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
noib3 committed Oct 27, 2023
1 parent 9c3efaf commit d7a2217
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 1 deletion.
76 changes: 76 additions & 0 deletions tests/fzf_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,82 @@ pub fn upstream_2<F: Fzf>() {
assert_eq!(m.matched_ranges().sorted(), [0..1, 4..5, 8..9]);
}

pub fn upstream_3<F: Fzf>() {
let (_, m) = fzf::<F>(Insensitive, "rdoc", "/AutomatorDocument.icns");

let m = m.unwrap();

assert_eq!(
m.distance().into_score(),
4 * bonus::MATCH + 2 * bonus::CONSECUTIVE + bonus::CAMEL_123
);

assert_eq!(m.matched_ranges().sorted(), [9..13]);
}

pub fn upstream_4<F: Fzf>() {
let (fzf, m) = fzf::<F>(Insensitive, "zhsc", "/man1/zshcompctl.1");

let m = m.unwrap();

assert_eq!(
m.distance().into_score(),
4 * bonus::MATCH
+ (bonus::FIRST_QUERY_CHAR_MULTIPLIER + 3)
* fzf.scheme().bonus_boundary_delimiter
);

assert_eq!(m.matched_ranges().sorted(), [6..10]);
}

pub fn upstream_5<F: Fzf>() {
let (fzf, m) = fzf::<F>(Insensitive, "zhsc", "/.oh-my-zsh/cache");

let m = m.unwrap();

assert_eq!(
m.distance().into_score(),
4 * bonus::MATCH
+ (bonus::FIRST_QUERY_CHAR_MULTIPLIER + 2) * bonus::BOUNDARY
+ fzf.scheme().bonus_boundary_delimiter
- penalty::GAP_START
);

assert_eq!(m.matched_ranges().sorted(), [8..11, 12..13]);
}

pub fn upstream_6<F: Fzf>() {
let (_, m) = fzf::<F>(Insensitive, "12356", "ab0123 456");

let m = m.unwrap();

assert_eq!(
m.distance().into_score(),
5 * bonus::MATCH + 3 * bonus::CONSECUTIVE
- penalty::GAP_START
- penalty::GAP_EXTENSION
);

assert_eq!(m.matched_ranges().sorted(), [3..6, 8..10]);
}

pub fn upstream_7<F: Fzf>() {
let (_, m) = fzf::<F>(Insensitive, "12356", "abc123 456");

let m = m.unwrap();

assert_eq!(
m.distance().into_score(),
5 * bonus::MATCH
+ (bonus::FIRST_QUERY_CHAR_MULTIPLIER + 2) * bonus::CAMEL_123
+ bonus::CONSECUTIVE
- penalty::GAP_START
- penalty::GAP_EXTENSION
);

assert_eq!(m.matched_ranges().sorted(), [3..6, 8..10]);
}

pub use utils::*;

mod utils {
Expand Down
25 changes: 25 additions & 0 deletions tests/fzf_v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,28 @@ fn fzf_v1_upstream_1() {
fn fzf_v1_upstream_2() {
common::upstream_2::<FzfV1>();
}

#[test]
fn fzf_v1_upstream_3() {
common::upstream_3::<FzfV1>()
}

#[test]
fn fzf_v1_upstream_4() {
common::upstream_4::<FzfV1>()
}

#[test]
fn fzf_v1_upstream_5() {
common::upstream_5::<FzfV1>()
}

#[test]
fn fzf_v1_upstream_6() {
common::upstream_6::<FzfV1>()
}

#[test]
fn fzf_v1_upstream_7() {
common::upstream_7::<FzfV1>()
}
27 changes: 26 additions & 1 deletion tests/fzf_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,35 @@ fn fzf_v2_upstream_1() {
}

#[test]
fn fzf_v1_upstream_2() {
fn fzf_v2_upstream_2() {
common::upstream_2::<FzfV2>();
}

#[test]
fn fzf_v2_upstream_3() {
common::upstream_3::<FzfV2>();
}

#[test]
fn fzf_v2_upstream_4() {
common::upstream_4::<FzfV2>();
}

#[test]
fn fzf_v2_upstream_5() {
common::upstream_5::<FzfV2>();
}

#[test]
fn fzf_v2_upstream_6() {
common::upstream_6::<FzfV2>();
}

#[test]
fn fzf_v2_upstream_7() {
common::upstream_7::<FzfV2>();
}

#[test]
fn fzf_v2_score_1() {
let mut fzf = FzfV2::new()
Expand Down

0 comments on commit d7a2217

Please sign in to comment.