summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/text/qregularexpression/tst_qregularexpression.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/text/qregularexpression/tst_qregularexpression.cpp')
-rw-r--r--tests/auto/corelib/text/qregularexpression/tst_qregularexpression.cpp138
1 files changed, 89 insertions, 49 deletions
diff --git a/tests/auto/corelib/text/qregularexpression/tst_qregularexpression.cpp b/tests/auto/corelib/text/qregularexpression/tst_qregularexpression.cpp
index 7f3bef66e6..72c49d2a9c 100644
--- a/tests/auto/corelib/text/qregularexpression/tst_qregularexpression.cpp
+++ b/tests/auto/corelib/text/qregularexpression/tst_qregularexpression.cpp
@@ -1,6 +1,6 @@
// Copyright (C) 2015 Giuseppe D'Angelo <dangelog@gmail.com>.
// Copyright (C) 2015 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <qstring.h>
@@ -1874,12 +1874,14 @@ void tst_QRegularExpression::captureNamesNul()
QString captureName("name");
QCOMPARE(m.captured(captureName), "456");
QCOMPARE(m.captured(QStringView(captureName)), "456");
+ QCOMPARE(m.captured(QAnyStringView(captureName)), "456");
QCOMPARE(m.captured(qToStringViewIgnoringNull(captureName)), "456");
QCOMPARE(m.captured(u"name"), "456");
captureName = "anotherName";
QCOMPARE(m.captured(captureName), "789");
QCOMPARE(m.captured(QStringView(captureName)), "789");
+ QCOMPARE(m.captured(QAnyStringView(captureName)), "789");
QCOMPARE(m.captured(qToStringViewIgnoringNull(captureName)), "789");
QCOMPARE(m.captured(u"anotherName"), "789");
}
@@ -2389,6 +2391,10 @@ void tst_QRegularExpression::threadSafety_data()
void tst_QRegularExpression::threadSafety()
{
+#if defined(Q_OS_WASM)
+ QSKIP("This test misbehaves on WASM. Investigation needed (QTBUG-110067)");
+#endif
+
QFETCH(QString, pattern);
QFETCH(QString, subject);
@@ -2446,55 +2452,79 @@ void tst_QRegularExpression::wildcard_data()
{
QTest::addColumn<QString>("pattern");
QTest::addColumn<QString>("string");
- QTest::addColumn<qsizetype>("foundIndex");
+ QTest::addColumn<bool>("matchesPathGlob");
+ QTest::addColumn<bool>("matchesNonPathGlob");
+ QTest::addColumn<bool>("anchored");
- auto addRow = [](const char *pattern, const char *string, qsizetype foundIndex) {
- QTest::newRow(pattern) << pattern << string << foundIndex;
+ 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", 0);
- addRow("*.html", "test.htm", -1);
- addRow("*bar*", "foobarbaz", 0);
- addRow("*", "Qt Rocks!", 0);
- addRow("*.html", "test.html", 0);
- addRow("*.h", "test.cpp", -1);
- addRow("*.???l", "test.html", 0);
- addRow("*?", "test.html", 0);
- addRow("*?ml", "test.html", 0);
- addRow("*[*]", "test.html", -1);
- addRow("*[?]","test.html", -1);
- addRow("*[?]ml","test.h?ml", 0);
- addRow("*[[]ml","test.h[ml", 0);
- addRow("*[]]ml","test.h]ml", 0);
- addRow("*.h[a-z]ml", "test.html", 0);
- addRow("*.h[A-Z]ml", "test.html", -1);
- addRow("*.h[A-Z]ml", "test.hTml", 0);
- addRow("*.h[!A-Z]ml", "test.hTml", -1);
- addRow("*.h[!A-Z]ml", "test.html", 0);
- addRow("*.h[!T]ml", "test.hTml", -1);
- addRow("*.h[!T]ml", "test.html", 0);
- addRow("*.h[!T]m[!L]", "test.htmL", -1);
- addRow("*.h[!T]m[!L]", "test.html", 0);
- addRow("*.h[][!]ml", "test.h]ml", 0);
- addRow("*.h[][!]ml", "test.h[ml", 0);
- addRow("*.h[][!]ml", "test.h!ml", 0);
-
- addRow("foo/*/bar", "foo/baz/bar", 0);
- addRow("foo/(*)/bar", "foo/baz/bar", -1);
- addRow("foo/(*)/bar", "foo/(baz)/bar", 0);
- addRow("foo/?/bar", "foo/Q/bar", 0);
- addRow("foo/?/bar", "foo/Qt/bar", -1);
- addRow("foo/(?)/bar", "foo/Q/bar", -1);
- addRow("foo/(?)/bar", "foo/(Q)/bar", 0);
+ addRow("*.html", "test.html", true, true);
+ addRow("*.html", "test.htm", false, false);
+ addRow("*bar*", "foobarbaz", true, true);
+ addRow("*", "Qt Rocks!", true, true);
+ addRow("*.h", "test.cpp", false, false);
+ addRow("*.???l", "test.html", true, true);
+ addRow("*?", "test.html", true, true);
+ addRow("*?ml", "test.html", true, true);
+ addRow("*[*]", "test.html", false, false);
+ addRow("*[?]","test.html", false, false);
+ addRow("*[?]ml","test.h?ml", true, true);
+ addRow("*[[]ml","test.h[ml", true, true);
+ addRow("*[]]ml","test.h]ml", true, true);
+ addRow("*.h[a-z]ml", "test.html", true, true);
+ addRow("*.h[A-Z]ml", "test.html", false, false);
+ addRow("*.h[A-Z]ml", "test.hTml", true, true);
+ addRow("*.h[!A-Z]ml", "test.hTml", false, false);
+ addRow("*.h[!A-Z]ml", "test.html", true, true);
+ addRow("*.h[!T]ml", "test.hTml", false, false);
+ addRow("*.h[!T]ml", "test.html", true, true);
+ addRow("*.h[!T]m[!L]", "test.htmL", false, false);
+ addRow("*.h[!T]m[!L]", "test.html", true, true);
+ addRow("*.h[][!]ml", "test.h]ml", true, true);
+ addRow("*.h[][!]ml", "test.h[ml", true, true);
+ addRow("*.h[][!]ml", "test.h!ml", true, true);
+
+ addRow("foo/*/bar", "foo/baz/bar", true, true);
+ addRow("foo/*/bar", "foo/fie/baz/bar", false, true);
+ addRow("foo?bar", "foo/bar", false, true);
+ addRow("foo/(*)/bar", "foo/baz/bar", false, false);
+ addRow("foo/(*)/bar", "foo/(baz)/bar", true, true);
+ addRow("foo/?/bar", "foo/Q/bar", true, true);
+ addRow("foo/?/bar", "foo/Qt/bar", false, false);
+ addRow("foo/(?)/bar", "foo/Q/bar", false, false);
+ addRow("foo/(?)/bar", "foo/(Q)/bar", true, true);
+
+ addRow("foo*bar", "foo/fie/baz/bar", false, true);
+ addRow("foo*bar", "foo bar", true, true);
+ addRow("foo*bar", "foo\tbar", true, true);
+ addRow("foo*bar", "foo\nbar", true, true);
+ addRow("foo*bar", "foo\r\nbar", true, true);
+
+ // 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", 0);
- addRow("foo\\(*)\\bar", "foo\\baz\\bar", -1);
- addRow("foo\\(*)\\bar", "foo\\(baz)\\bar", 0);
- addRow("foo\\?\\bar", "foo\\Q\\bar", 0);
- addRow("foo\\?\\bar", "foo\\Qt\\bar", -1);
- addRow("foo\\(?)\\bar", "foo\\Q\\bar", -1);
- addRow("foo\\(?)\\bar", "foo\\(Q)\\bar", 0);
+ addRow("foo\\*\\bar", "foo\\baz\\bar", true, true);
+ addRow("foo\\*\\bar", "foo/baz/bar", true, false);
+ addRow("foo\\*\\bar", "foo/baz\\bar", true, false);
+ addRow("foo\\*\\bar", "foo\\fie\\baz\\bar", false, true);
+ addRow("foo\\*\\bar", "foo/fie/baz/bar", false, false);
+ addRow("foo/*/bar", "foo\\baz\\bar", true, false);
+ addRow("foo/*/bar", "foo/baz/bar", true, true);
+ addRow("foo/*/bar", "foo\\fie\\baz\\bar", false, false);
+ addRow("foo/*/bar", "foo/fie/baz/bar", false, true);
+ addRow("foo\\(*)\\bar", "foo\\baz\\bar", false, false);
+ addRow("foo\\(*)\\bar", "foo\\(baz)\\bar", true, true);
+ addRow("foo\\?\\bar", "foo\\Q\\bar", true, true);
+ addRow("foo\\?\\bar", "foo\\Qt\\bar", false, false);
+ addRow("foo\\(?)\\bar", "foo\\Q\\bar", false, false);
+ addRow("foo\\(?)\\bar", "foo\\(Q)\\bar", true, true);
#endif
}
@@ -2502,12 +2532,22 @@ void tst_QRegularExpression::wildcard()
{
QFETCH(QString, pattern);
QFETCH(QString, string);
- QFETCH(qsizetype, foundIndex);
+ QFETCH(bool, matchesPathGlob);
+ QFETCH(bool, matchesNonPathGlob);
+ QFETCH(bool, anchored);
- QRegularExpression re(QRegularExpression::wildcardToRegularExpression(pattern));
- QRegularExpressionMatch match = re.match(string);
+ QRegularExpression::WildcardConversionOptions options = {};
+ if (!anchored)
+ options |= QRegularExpression::UnanchoredWildcardConversion;
- QCOMPARE(match.capturedStart(), foundIndex);
+ {
+ QRegularExpression re(QRegularExpression::wildcardToRegularExpression(pattern, options));
+ QCOMPARE(string.contains(re), matchesPathGlob);
+ }
+ {
+ QRegularExpression re(QRegularExpression::wildcardToRegularExpression(pattern, options | QRegularExpression::NonPathWildcardConversion));
+ QCOMPARE(string.contains(re), matchesNonPathGlob);
+ }
}
void tst_QRegularExpression::testInvalidWildcard_data()