summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/text/qstringapisymmetry
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2020-04-01 15:28:29 +0200
committerMarc Mutz <marc.mutz@kdab.com>2020-06-06 02:07:28 +0000
commitee635571122e1dd9b77276afb0f642e7ac9a015a (patch)
tree0ce36e65579428711dde617a8caeb7fdf2822862 /tests/auto/corelib/text/qstringapisymmetry
parent832d3b482ece878ee0ded823f0a8fa23523cdc17 (diff)
QString/View: add tokenize() member functions
[ChangeLog][QtCore][QString, QStringView, QLatin1String] Added tokenize(). Change-Id: I5fbeab0ac1809ff2974e565129b61a6bdfb398bc Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'tests/auto/corelib/text/qstringapisymmetry')
-rw-r--r--tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp b/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp
index f3a7e93be2..aeaf317d75 100644
--- a/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp
+++ b/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp
@@ -1429,6 +1429,14 @@ void tst_QStringApiSymmetry::tok_data(bool rhsHasVariableLength)
split_data(rhsHasVariableLength);
}
+template <typename T> struct has_tokenize_method : std::false_type {};
+template <> struct has_tokenize_method<QString> : std::true_type {};
+template <> struct has_tokenize_method<QStringView> : std::true_type {};
+template <> struct has_tokenize_method<QLatin1String> : std::true_type {};
+
+template <typename T>
+constexpr inline bool has_tokenize_method_v = has_tokenize_method<std::decay_t<T>>::value;
+
template <typename Haystack, typename Needle>
void tst_QStringApiSymmetry::tok_impl() const
{
@@ -1475,6 +1483,21 @@ void tst_QStringApiSymmetry::tok_impl() const
QCOMPARE(toQStringList(tok), resultCS);
}
#endif // __cpp_deduction_guides
+
+ if constexpr (has_tokenize_method_v<Haystack>) {
+ QCOMPARE(toQStringList(haystack.tokenize(needle)), resultCS);
+ QCOMPARE(toQStringList(haystack.tokenize(needle, Qt::KeepEmptyParts, Qt::CaseSensitive)), resultCS);
+ QCOMPARE(toQStringList(haystack.tokenize(needle, Qt::CaseInsensitive, Qt::KeepEmptyParts)), resultCIS);
+ QCOMPARE(toQStringList(haystack.tokenize(needle, Qt::SkipEmptyParts, Qt::CaseSensitive)), skippedResultCS);
+ QCOMPARE(toQStringList(haystack.tokenize(needle, Qt::CaseInsensitive, Qt::SkipEmptyParts)), skippedResultCIS);
+
+ {
+ const auto tok = deepCopied(haystack).tokenize(deepCopied(needle));
+ // here, the temporaries returned from deepCopied() have already been destroyed,
+ // yet `tok` should have kept a copy alive as needed:
+ QCOMPARE(toQStringList(tok), resultCS);
+ }
+ }
}
void tst_QStringApiSymmetry::mid_data()