From 9f136678be8f58534607d6d8ea7c29cdf746da75 Mon Sep 17 00:00:00 2001 From: Andre Hartmann Date: Sat, 13 Jul 2019 08:45:26 +0200 Subject: [PATCH] FuzzyMatcher: Handle digits as camel hump Allow searching for "Fancy4PartThingy" with the more intuitive pattern "f4pt" as well as with the pattern "fpt" that already worked before. Fixes: QTCREATORBUG-22671 Change-Id: I3a7c1a5b7f57d2f2bdd7d0c6e23b46f6bbb64d77 Reviewed-by: Orgad Shaneh --- src/libs/utils/fuzzymatcher.cpp | 2 +- .../utils/fuzzymatcher/tst_fuzzymatcher.cpp | 21 ++++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/libs/utils/fuzzymatcher.cpp b/src/libs/utils/fuzzymatcher.cpp index 60b5d3aaa25..50c3fb7fba9 100644 --- a/src/libs/utils/fuzzymatcher.cpp +++ b/src/libs/utils/fuzzymatcher.cpp @@ -75,7 +75,7 @@ QRegularExpression FuzzyMatcher::createRegExp( const QLatin1String upperSnakeWordContinuation("[A-Z0-9]*_"); keyRegExp += "(?:"; for (const QChar &c : pattern) { - if (!c.isLetter()) { + if (!c.isLetterOrNumber()) { if (c == question) { keyRegExp += '.'; plainRegExp += ").("; diff --git a/tests/auto/utils/fuzzymatcher/tst_fuzzymatcher.cpp b/tests/auto/utils/fuzzymatcher/tst_fuzzymatcher.cpp index 65dd4c495e9..c59dbb0f58c 100644 --- a/tests/auto/utils/fuzzymatcher/tst_fuzzymatcher.cpp +++ b/tests/auto/utils/fuzzymatcher/tst_fuzzymatcher.cpp @@ -68,7 +68,12 @@ void tst_FuzzyMatcher::fuzzyMatcher_data() QTest::newRow("incorrect-hump") << "lyn" << "VeryLongCamelHump" << -1; QTest::newRow("humps") << "VL" << "VeryLongCamelHump" << 0; QTest::newRow("skipped-humps-upper") << "VH" << "VeryLongCamelHump" << -1; - QTest::newRow("numbers") << "4" << "Test4Fun" << 4; + QTest::newRow("numbers-searched") << "4" << "Test4Fun" << 4; + QTest::newRow("numbers-skipped") << "fpt" << "Fancy4PartThingy" << 0; + QTest::newRow("numbers-camel") << "f4pt" << "Fancy4PartThingy" << 0; + QTest::newRow("multi-numbers-camel") << "f4pt" << "Fancy4567PartThingy" << 0; + QTest::newRow("numbers-underscore") << "f4pt" << "fancy_4_part_thingy" << 0; + QTest::newRow("numbers-underscore-upper") << "f4pt" << "FANCY_4_PART_THINGY" << 0; QTest::newRow("question-wildcard") << "Lon?Ca" << "VeryLongCamelHump" << 4; QTest::newRow("unmatched-question-wildcard") << "Long?Ca" << "VeryLongCamelHump" << -1; QTest::newRow("asterisk-wildcard") << "Long*Ca" << "VeryLongCamelHump" << 4; @@ -136,8 +141,18 @@ void tst_FuzzyMatcher::highlighting_data() << Matches{{4, 2}, {8, 2}}; QTest::newRow("duplicate-match") << "som" << "SomeMatch" << Matches{{0, 3}}; - QTest::newRow("numbers") << "4" << "TestJust4Fun" - << Matches{{8, 1}}; + QTest::newRow("numbers-searched") << "4" << "TestJust4Fun" + << Matches{{8, 1}}; + QTest::newRow("numbers-plain") << "boot2qt" << "use_boot2qt_for_embedded" + << Matches{{4, 7}}; + QTest::newRow("numbers-skipped") << "fpt" << "Fancy4PartThingy" + << Matches{{0, 1}, {6, 1}, {10, 1}}; + QTest::newRow("numbers-camel") << "f4pt" << "Fancy4PartThingy" + << Matches{{0, 1}, {5, 2}, {10, 1}}; + QTest::newRow("numbers-snake") << "f4pt" << "fancy_4_part_thingy" + << Matches{{0, 1}, {6, 1}, {8, 1}, {13, 1}}; + QTest::newRow("numbers-snake-upper") << "f4pt" << "FANCY_4_PART_THINGY" + << Matches{{0, 1}, {6, 1}, {8, 1}, {13, 1}}; QTest::newRow("wildcard-asterisk") << "Lo*Hu" << "VeryLongCamelHump" << Matches{{4, 2}, {13, 2}}; QTest::newRow("wildcard-question") << "Lo?g" << "VeryLongCamelHump"