diff options
author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2023-03-07 12:17:44 +0100 |
---|---|---|
committer | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2023-03-09 18:26:59 +0100 |
commit | 057a3ddc174d7d99c8aa6f43003fd98542a79386 (patch) | |
tree | 9ddc6cf1970c1de48fe52a762927dbf6084be45f /tests/auto/corelib | |
parent | 054fb061d770205706e80e80b6937edf7c866da1 (diff) |
QRegularExpression: extend wildcard tests
Test for non-anchored wildcards too.
Change-Id: I98cb47d76861d145bc409112981f52e246beb0a7
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib')
-rw-r--r-- | tests/auto/corelib/text/qregularexpression/tst_qregularexpression.cpp | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/tests/auto/corelib/text/qregularexpression/tst_qregularexpression.cpp b/tests/auto/corelib/text/qregularexpression/tst_qregularexpression.cpp index 212e315a34..5a8dc2b373 100644 --- a/tests/auto/corelib/text/qregularexpression/tst_qregularexpression.cpp +++ b/tests/auto/corelib/text/qregularexpression/tst_qregularexpression.cpp @@ -2448,9 +2448,10 @@ void tst_QRegularExpression::wildcard_data() QTest::addColumn<QString>("string"); QTest::addColumn<bool>("matchesPathGlob"); QTest::addColumn<bool>("matchesNonPathGlob"); + QTest::addColumn<bool>("anchored"); - auto addRow = [](const char *pattern, const char *string, bool matchesPathGlob, bool matchesNonPathGlob) { - QTest::addRow("%s@%s", pattern, string) << pattern << string << matchesPathGlob << matchesNonPathGlob; + auto addRow = [](const char *pattern, const char *string, bool matchesPathGlob, bool matchesNonPathGlob, bool anchored = true) { + QTest::addRow("%s@%s", pattern, string) << pattern << string << matchesPathGlob << matchesNonPathGlob << anchored; }; addRow("*.html", "test.html", true, true); @@ -2490,7 +2491,13 @@ void tst_QRegularExpression::wildcard_data() addRow("foo/(?)/bar", "foo/(Q)/bar", true, true); addRow("foo*bar", "foo/fie/baz/bar", false, true); - addRow("fie*bar", "foo/fie/baz/bar", false, false); // regexp is anchored + + // different anchor modes + addRow("foo", "afoob", false, false, true); + addRow("foo", "afoob", true, true, false); + + addRow("fie*bar", "foo/fie/baz/bar", false, false, true); + addRow("fie*bar", "foo/fie/baz/bar", false, true, false); #ifdef Q_OS_WIN addRow("foo\\*\\bar", "foo\\baz\\bar", true, true); @@ -2517,13 +2524,18 @@ void tst_QRegularExpression::wildcard() QFETCH(QString, string); QFETCH(bool, matchesPathGlob); QFETCH(bool, matchesNonPathGlob); + QFETCH(bool, anchored); + + QRegularExpression::WildcardConversionOptions options = {}; + if (!anchored) + options |= QRegularExpression::UnanchoredWildcardConversion; { - QRegularExpression re(QRegularExpression::wildcardToRegularExpression(pattern)); + QRegularExpression re(QRegularExpression::wildcardToRegularExpression(pattern, options)); QCOMPARE(string.contains(re), matchesPathGlob); } { - QRegularExpression re(QRegularExpression::wildcardToRegularExpression(pattern, QRegularExpression::NonPathWildcardConversion)); + QRegularExpression re(QRegularExpression::wildcardToRegularExpression(pattern, options | QRegularExpression::NonPathWildcardConversion)); QCOMPARE(string.contains(re), matchesNonPathGlob); } } |