From 5dd4bb62b138c576b7085c029d82873d8cbd2b31 Mon Sep 17 00:00:00 2001 From: Andre Hartmann Date: Sat, 13 Jul 2019 19:51:52 +0200 Subject: [PATCH] FuzzyMatcher: Match mixed uppercase words and humps "htvideoele" did not match "HTMLVideoElement" before. This can easily be achieved by modifying the uppercase snake matcher and thus making the underscore between the letters optional. Fixes: QTCREATORBUG-19838 Change-Id: I821a68b20d40fb0843c12f43f47133833c75cb9b Reviewed-by: Orgad Shaneh Reviewed-by: Eike Ziller --- src/libs/utils/fuzzymatcher.cpp | 2 +- tests/auto/utils/fuzzymatcher/tst_fuzzymatcher.cpp | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/libs/utils/fuzzymatcher.cpp b/src/libs/utils/fuzzymatcher.cpp index 50c3fb7fba9..819c723f6d3 100644 --- a/src/libs/utils/fuzzymatcher.cpp +++ b/src/libs/utils/fuzzymatcher.cpp @@ -72,7 +72,7 @@ QRegularExpression FuzzyMatcher::createRegExp( const QLatin1String lowercaseWordFirst("(?<=\\b|[A-Z0-9_])"); const QLatin1String uppercaseWordContinuation("[a-z0-9_]*"); const QLatin1String lowercaseWordContinuation("(?:[a-zA-Z0-9]*_)?"); - const QLatin1String upperSnakeWordContinuation("[A-Z0-9]*_"); + const QLatin1String upperSnakeWordContinuation("[A-Z0-9]*_?"); keyRegExp += "(?:"; for (const QChar &c : pattern) { if (!c.isLetterOrNumber()) { diff --git a/tests/auto/utils/fuzzymatcher/tst_fuzzymatcher.cpp b/tests/auto/utils/fuzzymatcher/tst_fuzzymatcher.cpp index c59dbb0f58c..3a64524d591 100644 --- a/tests/auto/utils/fuzzymatcher/tst_fuzzymatcher.cpp +++ b/tests/auto/utils/fuzzymatcher/tst_fuzzymatcher.cpp @@ -86,6 +86,7 @@ void tst_FuzzyMatcher::fuzzyMatcher_data() QTest::newRow("middle-no-hump") << "window" << "mainwindow.cpp" << 4; QTest::newRow("case-insensitive") << "window" << "MAINWINDOW.cpp" << 4; QTest::newRow("case-insensitive-2") << "wINDow" << "MainwiNdow.cpp" << 4; + QTest::newRow("uppercase-word-and-humps") << "htvideoele" << "HTMLVideoElement" << 0; } typedef QVector> Matches; @@ -159,6 +160,8 @@ void tst_FuzzyMatcher::highlighting_data() << Matches{{4, 2}, {7, 1}}; QTest::newRow("middle-no-hump") << "window" << "mainwindow.cpp" << Matches{{4, 6}}; + QTest::newRow("uppercase-word-and-humps") << "htvideoele" << "HTMLVideoElement" + << Matches{{0, 2}, {4, 8}}; } QTEST_APPLESS_MAIN(tst_FuzzyMatcher)