diff options
Diffstat (limited to 'tests/auto/corelib/tools/qstring/tst_qstring.cpp')
-rw-r--r-- | tests/auto/corelib/tools/qstring/tst_qstring.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qstring/tst_qstring.cpp b/tests/auto/corelib/tools/qstring/tst_qstring.cpp index f75d74c4b0..acdd2a9b64 100644 --- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp @@ -1003,10 +1003,12 @@ void tst_QString::sprintf() a.sprintf("%s%n%s", "hello", &n1, "goodbye"); QCOMPARE(n1, 5); QCOMPARE(a, QString("hellogoodbye")); +#ifndef Q_CC_MINGW // does not know %ll qlonglong n2; a.sprintf("%s%s%lln%s", "foo", "bar", &n2, "whiz"); QCOMPARE((int)n2, 6); QCOMPARE(a, QString("foobarwhiz")); +#endif } /* @@ -1425,6 +1427,55 @@ void tst_QString::contains() QVERIFY(a.contains(QRegularExpression("[FG][HI]"))); QVERIFY(a.contains(QRegularExpression("[G][HE]"))); + { + QRegularExpressionMatch match; + QVERIFY(!match.hasMatch()); + + QVERIFY(a.contains(QRegularExpression("[FG][HI]"), &match)); + QVERIFY(match.hasMatch()); + QCOMPARE(match.capturedStart(), 6); + QCOMPARE(match.capturedEnd(), 8); + QCOMPARE(match.captured(), QStringLiteral("GH")); + + QVERIFY(a.contains(QRegularExpression("[G][HE]"), &match)); + QVERIFY(match.hasMatch()); + QCOMPARE(match.capturedStart(), 6); + QCOMPARE(match.capturedEnd(), 8); + QCOMPARE(match.captured(), QStringLiteral("GH")); + + QVERIFY(a.contains(QRegularExpression("[f](.*)[FG]"), &match)); + QVERIFY(match.hasMatch()); + QCOMPARE(match.capturedStart(), 10); + QCOMPARE(match.capturedEnd(), 15); + QCOMPARE(match.captured(), QString("fGEFG")); + QCOMPARE(match.capturedStart(1), 11); + QCOMPARE(match.capturedEnd(1), 14); + QCOMPARE(match.captured(1), QStringLiteral("GEF")); + + QVERIFY(a.contains(QRegularExpression("[f](.*)[F]"), &match)); + QVERIFY(match.hasMatch()); + QCOMPARE(match.capturedStart(), 10); + QCOMPARE(match.capturedEnd(), 14); + QCOMPARE(match.captured(), QString("fGEF")); + QCOMPARE(match.capturedStart(1), 11); + QCOMPARE(match.capturedEnd(1), 13); + QCOMPARE(match.captured(1), QStringLiteral("GE")); + + QVERIFY(!a.contains(QRegularExpression("ZZZ"), &match)); + // doesn't match, but ensure match didn't change + QVERIFY(match.hasMatch()); + QCOMPARE(match.capturedStart(), 10); + QCOMPARE(match.capturedEnd(), 14); + QCOMPARE(match.captured(), QStringLiteral("fGEF")); + QCOMPARE(match.capturedStart(1), 11); + QCOMPARE(match.capturedEnd(1), 13); + QCOMPARE(match.captured(1), QStringLiteral("GE")); + + // don't crash with a null pointer + QVERIFY(a.contains(QRegularExpression("[FG][HI]"), 0)); + QVERIFY(!a.contains(QRegularExpression("ZZZ"), 0)); + } + CREATE_REF(QLatin1String("FG")); QVERIFY(a.contains(ref)); QVERIFY(a.contains(ref, Qt::CaseInsensitive)); @@ -5187,6 +5238,9 @@ void tst_QString::QCharRefDetaching() const void tst_QString::sprintfZU() const { +#ifdef Q_CC_MINGW + QSKIP("MinGW does not support '%zu'."); +#else { QString string; size_t s = 6; @@ -5215,6 +5269,7 @@ void tst_QString::sprintfZU() const string.sprintf("%zu %s\n", s, "foo"); QCOMPARE(string, QString::fromLatin1("6 foo\n")); } +#endif // !Q_CC_MINGW } void tst_QString::repeatedSignature() const |