From 6d79ade01976ddca7d6bace2a22a92a599b9b991 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 14 Nov 2016 19:14:09 +0000 Subject: [PATCH] Tweak RankedMatch behaviour and fix bug in its comparison function casting TestableFlag to UnderlyingType was going through bool conversion... Not sure how things worked earlier. --- src/flags.hh | 1 + src/ranked_match.cc | 2 ++ src/ranked_match.hh | 12 ++++++------ 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/flags.hh b/src/flags.hh index 824d37ca..d9755efa 100644 --- a/src/flags.hh +++ b/src/flags.hh @@ -37,6 +37,7 @@ struct TestableFlags Flags value; constexpr operator bool() const { return (UnderlyingType)value; } constexpr operator Flags() const { return value; } + constexpr operator UnderlyingType() const { return (UnderlyingType)value; } bool operator==(const TestableFlags& other) const { return value == other.value; } bool operator!=(const TestableFlags& other) const { return value != other.value; } diff --git a/src/ranked_match.cc b/src/ranked_match.cc index d9ea35c9..1c8021c5 100644 --- a/src/ranked_match.cc +++ b/src/ranked_match.cc @@ -216,6 +216,8 @@ UnitTest test_ranked_match{[] { kak_assert(not (RankedMatch{"source", "so"} < RankedMatch{"source", "so"})); kak_assert(RankedMatch{"single/word", "wo"} < RankedMatch{"multiw/ord", "wo"}); kak_assert(RankedMatch{"foo/bar/foobar", "foobar"} < RankedMatch{"foo/bar/baz", "foobar"}); + kak_assert(RankedMatch{"delete-buffer", "db"} < RankedMatch{"debug", "db"}); + kak_assert(RankedMatch{"create_task", "ct"} < RankedMatch{"constructor", "ct"}); }}; UnitTest test_used_letters{[]() diff --git a/src/ranked_match.hh b/src/ranked_match.hh index 183834a9..91169202 100644 --- a/src/ranked_match.hh +++ b/src/ranked_match.hh @@ -37,12 +37,12 @@ private: { None = 0, // Order is important, the highest bit has precedence for comparison - OnlyWordBoundary = 1 << 0, - FirstCharMatch = 1 << 1, - Prefix = 1 << 2, - SingleWord = 1 << 3, - Contiguous = 1 << 4, - FullMatch = 1 << 5, + FirstCharMatch = 1 << 0, + SingleWord = 1 << 1, + Contiguous = 1 << 2, + OnlyWordBoundary = 1 << 3, + Prefix = 1 << 4, + FullMatch = 1 << 5, }; StringView m_candidate;