Add tests to Utils::wildcardToRegularExpression

It was unclear if the new non-filepath version that is added to Qt is
similar enough to replace our own version, so just add the new tests
from Qt to check.

Change-Id: I9ac2739500ab3b8557c0e6223489e0fdddd79091
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Eike Ziller
2023-02-21 10:03:11 +01:00
parent b9a24753a0
commit c2266981c9

View File

@@ -77,6 +77,8 @@ private slots:
void testJoinStrings();
void testTrim_data();
void testTrim();
void testWildcardToRegularExpression_data();
void testWildcardToRegularExpression();
private:
TestMacroExpander mx;
@@ -330,6 +332,78 @@ void tst_StringUtils::testTrim()
QCOMPARE(Utils::trim(data.input, data.ch), data.bothSides);
}
void tst_StringUtils::testWildcardToRegularExpression_data()
{
QTest::addColumn<QString>("pattern");
QTest::addColumn<QString>("string");
QTest::addColumn<bool>("matches");
auto addRow = [](const char *pattern, const char *string, bool matchesNonPathGlob) {
QTest::addRow("%s@%s", pattern, string) << pattern << string << matchesNonPathGlob;
};
addRow("*.html", "test.html", true);
addRow("*.html", "test.htm", false);
addRow("*bar*", "foobarbaz", true);
addRow("*", "Qt Rocks!", true);
addRow("*.h", "test.cpp", false);
addRow("*.???l", "test.html", true);
addRow("*?", "test.html", true);
addRow("*?ml", "test.html", true);
addRow("*[*]", "test.html", false);
addRow("*[?]", "test.html", false);
addRow("*[?]ml", "test.h?ml", true);
addRow("*[[]ml", "test.h[ml", true);
addRow("*[]]ml", "test.h]ml", true);
addRow("*.h[a-z]ml", "test.html", true);
addRow("*.h[A-Z]ml", "test.html", false);
addRow("*.h[A-Z]ml", "test.hTml", true);
addRow("*.h[!A-Z]ml", "test.hTml", false);
addRow("*.h[!A-Z]ml", "test.html", true);
addRow("*.h[!T]ml", "test.hTml", false);
addRow("*.h[!T]ml", "test.html", true);
addRow("*.h[!T]m[!L]", "test.htmL", false);
addRow("*.h[!T]m[!L]", "test.html", true);
addRow("*.h[][!]ml", "test.h]ml", true);
addRow("*.h[][!]ml", "test.h[ml", true);
addRow("*.h[][!]ml", "test.h!ml", true);
addRow("foo/*/bar", "foo/baz/bar", true);
addRow("foo/*/bar", "foo/fie/baz/bar", true);
addRow("foo?bar", "foo/bar", true);
addRow("foo/(*)/bar", "foo/baz/bar", false);
addRow("foo/(*)/bar", "foo/(baz)/bar", true);
addRow("foo/?/bar", "foo/Q/bar", true);
addRow("foo/?/bar", "foo/Qt/bar", false);
addRow("foo/(?)/bar", "foo/Q/bar", false);
addRow("foo/(?)/bar", "foo/(Q)/bar", true);
addRow("foo\\*\\bar", "foo\\baz\\bar", true);
addRow("foo\\*\\bar", "foo/baz/bar", false);
addRow("foo\\*\\bar", "foo/baz\\bar", false);
addRow("foo\\*\\bar", "foo\\fie\\baz\\bar", true);
addRow("foo\\*\\bar", "foo/fie/baz/bar", false);
addRow("foo/*/bar", "foo\\baz\\bar", false);
addRow("foo/*/bar", "foo/baz/bar", true);
addRow("foo/*/bar", "foo\\fie\\baz\\bar", false);
addRow("foo/*/bar", "foo/fie/baz/bar", true);
addRow("foo\\(*)\\bar", "foo\\baz\\bar", false);
addRow("foo\\(*)\\bar", "foo\\(baz)\\bar", true);
addRow("foo\\?\\bar", "foo\\Q\\bar", true);
addRow("foo\\?\\bar", "foo\\Qt\\bar", false);
addRow("foo\\(?)\\bar", "foo\\Q\\bar", false);
addRow("foo\\(?)\\bar", "foo\\(Q)\\bar", true);
addRow("foo*bar", "foo/fie/baz/bar", true);
addRow("fie*bar", "foo/fie/baz/bar", false);
}
void tst_StringUtils::testWildcardToRegularExpression()
{
QFETCH(QString, pattern);
QFETCH(QString, string);
QFETCH(bool, matches);
const QRegularExpression re(Utils::wildcardToRegularExpression(pattern));
QCOMPARE(string.contains(re), matches);
}
QTEST_GUILESS_MAIN(tst_StringUtils)
#include "tst_stringutils.moc"