helix-editor / nucleo

A fast and convenient fuzzy matcher library for rust
Mozilla Public License 2.0
899 stars 28 forks source link

Panic with simple pattern. #9

Closed markus-bauer closed 1 year ago

markus-bauer commented 1 year ago

I know you're still working on this. But I might as well report it. The example below panics with 'should have been caught by prefilter', .../git/checkouts/nucleo-fe29e1ee969779b0/9c4b710/matcher/src/fuzzy_optimal.rs:41:13

Has something to do with case, because it doesn't happen when ignore_case is false.

[dependencies]
nucleo = {version ="*", git="https://github.com/helix-editor/nucleo"}
use nucleo::*;

fn main() {
    let conf = MatcherConfig::DEFAULT;
    let mut matcher = Matcher::new(conf);

    let needle = "aB";
    let mut buf1 = Vec::new();
    let needle = Utf32Str::new(needle, &mut buf1);

    let haystack = "aaB";
    let mut buf2 = Vec::new();
    let haystack = Utf32Str::new(haystack, &mut buf2);

    let mut indices = Vec::new();
    let result = matcher.fuzzy_indices(haystack, needle, &mut indices);

    println!("{:?} {:?}", result, indices);
}
pascalkuthe commented 1 year ago

This is expected if you are doing case insenstivie matching you most provide the needle as entirely lowercase. Everything else is an API missuse and the panic is intentional in that case. This still needs better docs. I would reccomend using the Pattern high level API for matching instead since that will care of stuff like this automatically

markus-bauer commented 1 year ago

Okay, thanks. I just started playing around with this. I should have waited for a more official release.