tst_QAnyStringView: explicitly check the spaceship operator
We implicitly checked it, because, in C++20 builds, the non-equality relational operators are synthesized from it by the compiler, and we test those, but we didn't check that <=> returns strong_ordering. We now do. Pick-to: 6.4 6.3 6.2 Task-number: QTBUG-104108 Change-Id: Ieb19a2d4cb2d600d884f4e2e89e98c6187e23872 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
parent
de005e7976
commit
1b8b802455
@ -42,6 +42,14 @@
|
||||
# define ONLY_WIN(expr) QSKIP("This is a Windows-only test")
|
||||
#endif
|
||||
|
||||
#ifdef __cpp_impl_three_way_comparison
|
||||
# define ONLY_3WAY(expr) expr
|
||||
#else
|
||||
# define ONLY_3WAY(expr) \
|
||||
QSKIP("This test requires C++20 spaceship operator (<=>) " \
|
||||
"support enabled in the standard library.")
|
||||
#endif
|
||||
|
||||
using namespace Qt::StringLiterals;
|
||||
|
||||
template <typename T>
|
||||
@ -292,6 +300,7 @@ private Q_SLOTS:
|
||||
void fromQStringBuilder_QString_QString() const { fromQStringBuilder(u"1"_s % u"2"_s, u"12"); }
|
||||
|
||||
void comparison();
|
||||
void compare3way();
|
||||
|
||||
private:
|
||||
template <typename StringBuilder>
|
||||
@ -629,5 +638,27 @@ void tst_QAnyStringView::comparison()
|
||||
QVERIFY(QAnyStringView::compare(bb, aa) > 0);
|
||||
}
|
||||
|
||||
void tst_QAnyStringView::compare3way()
|
||||
{
|
||||
#define COMPARE_3WAY(lhs, rhs, res) \
|
||||
do { \
|
||||
const auto qt_3way_cmp_res = (lhs) <=> (rhs); \
|
||||
static_assert(std::is_same_v<decltype(qt_3way_cmp_res), decltype(res)>); \
|
||||
QCOMPARE(std::is_eq(qt_3way_cmp_res), std::is_eq(res)); \
|
||||
QCOMPARE(std::is_lt(qt_3way_cmp_res), std::is_lt(res)); \
|
||||
QCOMPARE(std::is_gt(qt_3way_cmp_res), std::is_gt(res)); \
|
||||
} while (false)
|
||||
|
||||
ONLY_3WAY(
|
||||
const QAnyStringView aa = u"aa";
|
||||
const QAnyStringView upperAa = u"AA";
|
||||
const QAnyStringView bb = u"bb";
|
||||
COMPARE_3WAY(aa, aa, std::strong_ordering::equal);
|
||||
COMPARE_3WAY(aa, bb, std::strong_ordering::less);
|
||||
COMPARE_3WAY(bb, aa, std::strong_ordering::greater)
|
||||
);
|
||||
#undef COMPARE_3WAY
|
||||
}
|
||||
|
||||
QTEST_APPLESS_MAIN(tst_QAnyStringView)
|
||||
#include "tst_qanystringview.moc"
|
||||
|
Loading…
Reference in New Issue
Block a user