File indexing completed on 2024-04-28 04:01:10

0001 /*
0002     SPDX-FileCopyrightText: 2007 Sebastian Pipping <webmaster@hartwork.org>
0003 
0004     SPDX-License-Identifier: MIT
0005 */
0006 
0007 #include <KSyntaxHighlighting/WildcardMatcher>
0008 
0009 #include <QObject>
0010 #include <QTest>
0011 
0012 class WildcardMatcherTest : public QObject
0013 {
0014     Q_OBJECT
0015 private Q_SLOTS:
0016     void testPositiveMatch_data()
0017     {
0018         QTest::addColumn<QString>("str");
0019         QTest::addColumn<QString>("pattern");
0020 
0021         QTest::newRow("*.txt") << "abc.txt"
0022                                << "*.txt";
0023 
0024         QTest::newRow("*Makefile* 1") << "Makefile.am"
0025                                       << "*Makefile*";
0026         QTest::newRow("*Makefile* 2") << "Makefile.am"
0027                                       << "Makefile*";
0028 
0029         QTest::newRow("control") << "control"
0030                                  << "control";
0031 
0032         QTest::newRow("a??d") << "abcd"
0033                               << "a??d";
0034 
0035         QTest::newRow("?") << "a"
0036                            << "?";
0037         QTest::newRow("*?*") << "a"
0038                              << "*?*";
0039         QTest::newRow("*") << "a"
0040                            << "*";
0041         QTest::newRow("**") << "a"
0042                             << "**";
0043         QTest::newRow("***") << "a"
0044                              << "***";
0045 
0046         QTest::newRow("empty 1") << ""
0047                                  << "*";
0048         QTest::newRow("empty 2") << ""
0049                                  << "**";
0050 
0051         QTest::newRow("a*") << "ab"
0052                             << "a*";
0053         QTest::newRow("*b") << "ab"
0054                             << "*b";
0055         QTest::newRow("a?") << "ab"
0056                             << "a?";
0057         QTest::newRow("?b") << "ab"
0058                             << "?b";
0059 
0060         QTest::newRow("a*b*c") << "aXXbXXbYYaYc"
0061                                << "a*b*c";
0062     }
0063 
0064     void testPositiveMatch()
0065     {
0066         QFETCH(QString, str);
0067         QFETCH(QString, pattern);
0068         QVERIFY(KSyntaxHighlighting::WildcardMatcher::exactMatch(str, pattern));
0069     }
0070 
0071     void testNegativeMatch_data()
0072     {
0073         QTest::addColumn<QString>("str");
0074         QTest::addColumn<QString>("pattern");
0075 
0076         QTest::newRow("*.cpp") << "abc.txt"
0077                                << "*.cpp";
0078         QTest::newRow("*Makefile* 3") << "Makefile.am"
0079                                       << "Makefile";
0080         QTest::newRow("?") << ""
0081                            << "?";
0082     }
0083 
0084     void testNegativeMatch()
0085     {
0086         QFETCH(QString, str);
0087         QFETCH(QString, pattern);
0088         QVERIFY(!KSyntaxHighlighting::WildcardMatcher::exactMatch(str, pattern));
0089     }
0090 };
0091 
0092 QTEST_GUILESS_MAIN(WildcardMatcherTest)
0093 
0094 #include "wildcardmatcher_test.moc"