diff options
author | Sona Kurazyan <sona.kurazyan@qt.io> | 2022-03-02 09:30:34 +0100 |
---|---|---|
committer | Sona Kurazyan <sona.kurazyan@qt.io> | 2022-03-09 15:58:47 +0100 |
commit | 30d28810ee73052338e478a5472933c7b9c7d725 (patch) | |
tree | ef862951f799dca9404363956f2c05e5bcf3505e /tests | |
parent | 567c31e8ee92a8071c731aac6fc6729d16d7439b (diff) |
Add QLatin1String::count(needle)
[ChangeLog][QtCore][QLatin1String] Added QLatin1String::count(needle).
Task-number: QTBUG-98433
Change-Id: I31c9fdf14fd81500722ff9f5998eadf0e6cedc5c
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/corelib/text/qlatin1string/tst_qlatin1string.cpp | 31 | ||||
-rw-r--r-- | tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp | 13 |
2 files changed, 44 insertions, 0 deletions
diff --git a/tests/auto/corelib/text/qlatin1string/tst_qlatin1string.cpp b/tests/auto/corelib/text/qlatin1string/tst_qlatin1string.cpp index c1ca1f74c0..aebd60ded2 100644 --- a/tests/auto/corelib/text/qlatin1string/tst_qlatin1string.cpp +++ b/tests/auto/corelib/text/qlatin1string/tst_qlatin1string.cpp @@ -55,6 +55,7 @@ private Q_SLOTS: void iterators(); void relationalOperators_data(); void relationalOperators(); + void count(); }; void tst_QLatin1String::constExpr() @@ -398,6 +399,36 @@ void tst_QLatin1String::relationalOperators() #undef CHECK } +void tst_QLatin1String::count() +{ + QLatin1String a("ABCDEFGHIEfGEFG"); + QCOMPARE(a.size(), 15); + QCOMPARE(a.count('A'), 1); + QCOMPARE(a.count('Z'), 0); + QCOMPARE(a.count('E'), 3); + QCOMPARE(a.count('F'), 2); + QCOMPARE(a.count('F', Qt::CaseInsensitive), 3); + QCOMPARE(a.count(QLatin1String("FG")), 2); + QCOMPARE(a.count(QLatin1String("FG"), Qt::CaseInsensitive), 3); + QCOMPARE(a.count(QLatin1String(), Qt::CaseInsensitive), 16); + QCOMPARE(a.count(QLatin1String(""), Qt::CaseInsensitive), 16); + + QLatin1String nullStr; + QCOMPARE(nullStr.count('A'), 0); + QCOMPARE(nullStr.count(QLatin1String("AB")), 0); + QCOMPARE(nullStr.count(QLatin1String()), 1); + QCOMPARE(nullStr.count(QLatin1String("")), 1); + + QLatin1String emptyStr(""); + QCOMPARE(emptyStr.count('A'), 0); + QCOMPARE(emptyStr.count(QLatin1String("AB")), 0); + QCOMPARE(emptyStr.count(QLatin1String()), 1); + QCOMPARE(emptyStr.count(QLatin1String("")), 1); + + using namespace Qt::Literals::StringLiterals; + QCOMPARE("a\0b"_L1.count(QChar::SpecialCharacter::LineSeparator), 0); +} + QTEST_APPLESS_MAIN(tst_QLatin1String) #include "tst_qlatin1string.moc" diff --git a/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp b/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp index 56bb74d3c7..32d5e014bd 100644 --- a/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp +++ b/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp @@ -748,6 +748,19 @@ private Q_SLOTS: void count_QStringView_char16_t_data() { count_data(); } void count_QStringView_char16_t() { count_impl<QStringView, char16_t>(); } + void count_QLatin1String_QString_data() { count_data(); } + void count_QLatin1String_QString() { count_impl<QLatin1String, QString>(); } + void count_QLatin1String_QLatin1String_data() { count_data(); } + void count_QLatin1String_QLatin1String() { count_impl<QLatin1String, QLatin1String>(); } + void count_QLatin1String_QStringView_data() { count_data(); } + void count_QLatin1String_QStringView() { count_impl<QLatin1String, QStringView>(); } + void count_QLatin1String_QChar_data() { count_data(); } + void count_QLatin1String_QChar() { count_impl<QLatin1String, QChar>(); } + void count_QLatin1String_char16_t_data() { count_data(); } + void count_QLatin1String_char16_t() { count_impl<QLatin1String, char16_t>(); } + void count_QLatin1String_QLatin1Char_data() { count_data(); } + void count_QLatin1String_QLatin1Char() { count_impl<QLatin1String, QLatin1Char>(); } + // // UTF-16-only checks: // |