Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix short circuiting logic when doing exact matches #32

Merged
merged 3 commits into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

# Unreleased

## Bugfixes

* when the needle is composed of a single char, return the score and index
of the best position instead of always returning the first matched character
in the haystack

# [0.2.1] - 2023-09-02

## Bugfixes
Expand Down
12 changes: 6 additions & 6 deletions matcher/src/exact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl Matcher {
max_pos = i as u32;
max_score = score;
// can't get better than this
if score >= self.config.bonus_boundary_white {
if bonus >= self.config.bonus_boundary_white {
break;
}
}
Expand All @@ -45,7 +45,7 @@ impl Matcher {
max_pos = i as u32;
max_score = score;
// can't get better than this
if score >= self.config.bonus_boundary_white {
if bonus >= self.config.bonus_boundary_white {
break;
}
}
Expand Down Expand Up @@ -88,7 +88,7 @@ impl Matcher {
max_pos = i;
max_score = score;
// can't get better than this
if score >= self.config.bonus_boundary_white {
if bonus >= self.config.bonus_boundary_white {
break;
}
}
Expand Down Expand Up @@ -163,7 +163,7 @@ impl Matcher {
max_pos = i;
max_score = score;
// can't get better than this
if score >= self.config.bonus_boundary_white {
if bonus >= self.config.bonus_boundary_white {
break;
}
}
Expand Down Expand Up @@ -207,7 +207,7 @@ impl Matcher {
max_pos = i as u32;
max_score = score;
// can't get better than this
if score >= self.config.bonus_boundary_white {
if bonus >= self.config.bonus_boundary_white {
break;
}
}
Expand Down Expand Up @@ -253,7 +253,7 @@ impl Matcher {
max_pos = i;
max_score = score;
// can't get better than this
if score >= self.config.bonus_boundary_white {
if bonus >= self.config.bonus_boundary_white {
break;
}
}
Expand Down
30 changes: 30 additions & 0 deletions matcher/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -668,3 +668,33 @@ fn test_prefer_prefix() {
],
);
}

#[test]
fn test_single_char_needle() {
assert_matches(
&[FuzzyOptimal],
false,
false,
false,
false,
&[(
"foO",
"o",
&[2],
BONUS_FIRST_CHAR_MULTIPLIER * BONUS_CAMEL123,
)],
);
assert_matches(
&[FuzzyOptimal],
false,
false,
false,
false,
&[(
"föÖ",
"ö",
&[2],
BONUS_FIRST_CHAR_MULTIPLIER * BONUS_CAMEL123,
)],
);
}