summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/text/qstring/tst_qstring.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/text/qstring/tst_qstring.cpp')
-rw-r--r--tests/auto/corelib/text/qstring/tst_qstring.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/auto/corelib/text/qstring/tst_qstring.cpp b/tests/auto/corelib/text/qstring/tst_qstring.cpp
index eaf35c969e..010216e787 100644
--- a/tests/auto/corelib/text/qstring/tst_qstring.cpp
+++ b/tests/auto/corelib/text/qstring/tst_qstring.cpp
@@ -696,6 +696,8 @@ private slots:
void sliced();
void chopped();
void removeIf();
+
+ void std_stringview_conversion();
};
Q_DECLARE_OPERATORS_FOR_FLAGS(tst_QString::DataOptions)
@@ -8762,6 +8764,31 @@ void tst_QString::removeIf()
QCOMPARE(a.removeIf(removeA), u"BcbC");
}
+void tst_QString::std_stringview_conversion()
+{
+ static_assert(std::is_convertible_v<QString, std::u16string_view>);
+
+ QString s;
+ std::u16string_view sv(s);
+ QCOMPARE(sv, std::u16string_view());
+
+ s = u""_s;
+ sv = s;
+ QCOMPARE(s.size(), 0);
+ QCOMPARE(sv.size(), size_t(0));
+ QCOMPARE(sv, std::u16string_view());
+
+ s = u"Hello"_s;
+ sv = s;
+ QCOMPARE(sv, std::u16string_view(u"Hello"));
+
+ s = u"Hello\0world"_s;
+ sv = s;
+ QCOMPARE(s.size(), 11);
+ QCOMPARE(sv.size(), size_t(11));
+ QCOMPARE(sv, std::u16string_view(u"Hello\0world", 11));
+}
+
// QString's collation order is only supported during the lifetime as QCoreApplication
QTEST_GUILESS_MAIN(tst_QString)