mirror of
https://github.com/solaeus/nucleo.git
synced 2024-12-22 09:57:49 +00:00
fix short circuiting logic when doing exact matches (#32)
* fix short circuiting logic in the `exact` module * add tests for single char needles * add bugfix to the CHANGELOG
This commit is contained in:
parent
abf7454f4b
commit
b41c989daf
@ -1,5 +1,13 @@
|
|||||||
# Changelog
|
# 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
|
# [0.2.1] - 2023-09-02
|
||||||
|
|
||||||
## Bugfixes
|
## Bugfixes
|
||||||
|
@ -27,7 +27,7 @@ impl Matcher {
|
|||||||
max_pos = i as u32;
|
max_pos = i as u32;
|
||||||
max_score = score;
|
max_score = score;
|
||||||
// can't get better than this
|
// can't get better than this
|
||||||
if score >= self.config.bonus_boundary_white {
|
if bonus >= self.config.bonus_boundary_white {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -45,7 +45,7 @@ impl Matcher {
|
|||||||
max_pos = i as u32;
|
max_pos = i as u32;
|
||||||
max_score = score;
|
max_score = score;
|
||||||
// can't get better than this
|
// can't get better than this
|
||||||
if score >= self.config.bonus_boundary_white {
|
if bonus >= self.config.bonus_boundary_white {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -88,7 +88,7 @@ impl Matcher {
|
|||||||
max_pos = i;
|
max_pos = i;
|
||||||
max_score = score;
|
max_score = score;
|
||||||
// can't get better than this
|
// can't get better than this
|
||||||
if score >= self.config.bonus_boundary_white {
|
if bonus >= self.config.bonus_boundary_white {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -163,7 +163,7 @@ impl Matcher {
|
|||||||
max_pos = i;
|
max_pos = i;
|
||||||
max_score = score;
|
max_score = score;
|
||||||
// can't get better than this
|
// can't get better than this
|
||||||
if score >= self.config.bonus_boundary_white {
|
if bonus >= self.config.bonus_boundary_white {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -207,7 +207,7 @@ impl Matcher {
|
|||||||
max_pos = i as u32;
|
max_pos = i as u32;
|
||||||
max_score = score;
|
max_score = score;
|
||||||
// can't get better than this
|
// can't get better than this
|
||||||
if score >= self.config.bonus_boundary_white {
|
if bonus >= self.config.bonus_boundary_white {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -253,7 +253,7 @@ impl Matcher {
|
|||||||
max_pos = i;
|
max_pos = i;
|
||||||
max_score = score;
|
max_score = score;
|
||||||
// can't get better than this
|
// can't get better than this
|
||||||
if score >= self.config.bonus_boundary_white {
|
if bonus >= self.config.bonus_boundary_white {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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,
|
||||||
|
)],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user