From c0510325785fb052b5fd6b5fc6b10dcdc714f805 Mon Sep 17 00:00:00 2001 From: Simon Hauser Date: Fri, 18 Feb 2022 18:09:04 +0100 Subject: [PATCH] fix: invert or `a | !a` --- src/fzf.c | 6 +++++- test/fzf_lib_spec.lua | 6 ++++++ test/test.c | 6 ++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/fzf.c b/src/fzf.c index 6973b24..1bf6ef4 100644 --- a/src/fzf.c +++ b/src/fzf.c @@ -1177,7 +1177,11 @@ int32_t fzf_get_score(const char *text, fzf_pattern_t *pattern, } if (term->inv) { - current_score = 0; + if (term_set->size > 1) { + current_score = 1; + } else { + current_score = 0; + } matched = true; } } diff --git a/test/fzf_lib_spec.lua b/test/fzf_lib_spec.lua index f5ccdae..6e23180 100644 --- a/test/fzf_lib_spec.lua +++ b/test/fzf_lib_spec.lua @@ -54,6 +54,12 @@ describe("fzf", function() fzf.free_pattern(p) end) + it("can get the score for issue 52", function() + local p = fzf.parse_pattern("a | !a", 0) + eq(1, fzf.get_score("test/minrc.vim", p, slab)) + fzf.free_pattern(p) + end) + it("can get the pos for simple pattern", function() local p = fzf.parse_pattern("fzf", 0) eq({ 7, 6, 5 }, fzf.get_pos("src/fzf", p, slab)) diff --git a/test/test.c b/test/test.c index c22961a..5f7b228 100644 --- a/test/test.c +++ b/test/test.c @@ -643,6 +643,12 @@ TEST(ScoreIntegration, invertAnd) { score_wrapper("!fzf !test", input, expected); } +TEST(ScoreIntegration, invertOr) { + char *input[] = {"Makefile", "test/minrc", NULL}; + int expected[] = {16, 1}; + score_wrapper("a | !a", input, expected); +} + TEST(ScoreIntegration, withEscapedSpace) { char *input[] = {"file ", "file lua", "lua", NULL}; int expected[] = {0, 200, 0};