diff options
author | Andre Hartmann <aha_1980@gmx.de> | 2017-07-24 20:55:47 +0200 |
---|---|---|
committer | André Hartmann <aha_1980@gmx.de> | 2017-09-19 08:24:38 +0000 |
commit | 632f2a77098e57eeecdaac39efd32741dfc68e76 (patch) | |
tree | 80fa68fca6f958eadd0f095df02a48cb2e438d3f /tests | |
parent | 2fb54abd03d71e1e205a1dc6f94769688d1bc2e0 (diff) |
Locator: Add camel hump locator filter for C++, QML, and files
* Use the CamelHumpMatcher in the C++, QML, and files filters
* Supports matching against UpperCamelCase, lowerCamelCase
and snake_case strings
* Supports highlighting of matched characters
Task-number: QTCREATORBUG-3111
Started-by: David Kaspar <dkaspar@blackberry.com>
Change-Id: If6220191432ef965bde3c8dbe4a10d89e222ba6f
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/utils/camelhumpmatcher/tst_camelhumpmatcher.cpp | 61 | ||||
-rw-r--r-- | tests/cpplocators/testdata_basic/file1.cpp | 4 |
2 files changed, 65 insertions, 0 deletions
diff --git a/tests/auto/utils/camelhumpmatcher/tst_camelhumpmatcher.cpp b/tests/auto/utils/camelhumpmatcher/tst_camelhumpmatcher.cpp index b42a46cba7..dea71dbf23 100644 --- a/tests/auto/utils/camelhumpmatcher/tst_camelhumpmatcher.cpp +++ b/tests/auto/utils/camelhumpmatcher/tst_camelhumpmatcher.cpp @@ -35,6 +35,8 @@ class tst_CamelHumpMatcher : public QObject private slots: void camelHumpMatcher(); void camelHumpMatcher_data(); + void highlighting(); + void highlighting_data(); }; void tst_CamelHumpMatcher::camelHumpMatcher() @@ -75,5 +77,64 @@ void tst_CamelHumpMatcher::camelHumpMatcher_data() QTest::newRow("middle-continued") << "cahu" << "LongCamelHump" << 4; } +typedef QVector<int> MatchStart; +typedef QVector<int> MatchLength; + +void tst_CamelHumpMatcher::highlighting() +{ + QFETCH(QString, pattern); + QFETCH(QString, candidate); + QFETCH(MatchStart, matchStart); + QFETCH(MatchLength, matchLength); + + const QRegularExpression regExp = CamelHumpMatcher::createCamelHumpRegExp(pattern); + const QRegularExpressionMatch match = regExp.match(candidate); + const CamelHumpMatcher::HighlightingPositions positions = + CamelHumpMatcher::highlightingPositions(match); + + QCOMPARE(positions.starts.size(), matchStart.size()); + for (int i = 0; i < positions.starts.size(); ++i) { + QCOMPARE(positions.starts.at(i), matchStart.at(i)); + QCOMPARE(positions.lengths.at(i), matchLength.at(i)); + } +} + +void tst_CamelHumpMatcher::highlighting_data() +{ + QTest::addColumn<QString>("pattern"); + QTest::addColumn<QString>("candidate"); + QTest::addColumn<MatchStart>("matchStart"); + QTest::addColumn<MatchLength>("matchLength"); + + QTest::newRow("prefix-snake") << "very" << "very_long_camel_hump" + << MatchStart{0} << MatchLength{4}; + QTest::newRow("middle-snake") << "long" << "very_long_camel_hump" + << MatchStart{5} << MatchLength{4}; + QTest::newRow("suffix-snake") << "hump" << "very_long_camel_hump" + << MatchStart{16} << MatchLength{4}; + QTest::newRow("prefix-camel") << "very" << "VeryLongCamelHump" + << MatchStart{0} << MatchLength{4}; + QTest::newRow("middle-camel") << "Long" << "VeryLongCamelHump" + << MatchStart{4} << MatchLength{4}; + QTest::newRow("suffix-camel") << "Hump" << "VeryLongCamelHump" + << MatchStart{13} << MatchLength{4}; + QTest::newRow("humps-camel") << "vlch" << "VeryLongCamelHump" + << MatchStart{0, 4, 8, 13} << MatchLength{1, 1, 1, 1}; + QTest::newRow("humps-camel-lower") << "vlch" << "veryLongCamelHump" + << MatchStart{0, 4, 8, 13} << MatchLength{1, 1, 1, 1}; + QTest::newRow("humps-snake") << "vlch" << "very_long_camel_hump" + << MatchStart{0, 5, 10, 16} << MatchLength{1, 1, 1, 1}; + QTest::newRow("humps-middle") << "lc" << "VeryLongCamelHump" + << MatchStart{4, 8} << MatchLength{1, 1}; + QTest::newRow("humps-last") << "h" << "VeryLongCamelHump" + << MatchStart{13} << MatchLength{1}; + QTest::newRow("humps-continued") << "LoCa" << "VeryLongCamelHump" + << MatchStart{4, 8} << MatchLength{2, 2}; + QTest::newRow("wildcard-asterisk") << "Lo*Hu" << "VeryLongCamelHump" + << MatchStart{4, 13} << MatchLength{2, 2}; + QTest::newRow("wildcard-question") << "Lo?g" << "VeryLongCamelHump" + << MatchStart{4, 7} << MatchLength{2, 1}; +} + QTEST_APPLESS_MAIN(tst_CamelHumpMatcher) #include "tst_camelhumpmatcher.moc" diff --git a/tests/cpplocators/testdata_basic/file1.cpp b/tests/cpplocators/testdata_basic/file1.cpp index 98a5375237..5c1e3caff3 100644 --- a/tests/cpplocators/testdata_basic/file1.cpp +++ b/tests/cpplocators/testdata_basic/file1.cpp @@ -12,6 +12,10 @@ int myVariable; int myFunction(bool yesno, int number) {} +void pointOfService() {} +int getPosition() { return 0; } +int positiveNumber() { return 2; } + enum MyEnum { V1, V2 }; class MyClass |