aboutsummaryrefslogtreecommitdiff
path: root/absl/time/time_test.cc
diff options
context:
space:
mode:
Diffstat (limited to 'absl/time/time_test.cc')
-rw-r--r--absl/time/time_test.cc39
1 files changed, 39 insertions, 0 deletions
diff --git a/absl/time/time_test.cc b/absl/time/time_test.cc
index 052d8806..71f54d64 100644
--- a/absl/time/time_test.cc
+++ b/absl/time/time_test.cc
@@ -24,6 +24,11 @@
#endif
#include <chrono> // NOLINT(build/c++11)
+
+#ifdef __cpp_impl_three_way_comparison
+#include <compare>
+#endif // __cpp_impl_three_way_comparison
+
#include <cstring>
#include <ctime>
#include <iomanip>
@@ -207,6 +212,22 @@ TEST(Time, RelationalOperators) {
static_assert(t3 >= t2, "");
static_assert(t1 >= t1, "");
static_assert(t3 >= t1, "");
+
+#ifdef __cpp_impl_three_way_comparison
+
+ static_assert((t1 <=> t1) == std::strong_ordering::equal, "");
+ static_assert((t2 <=> t2) == std::strong_ordering::equal, "");
+ static_assert((t3 <=> t3) == std::strong_ordering::equal, "");
+
+ static_assert((t1 <=> t2) == std::strong_ordering::less, "");
+ static_assert((t2 <=> t3) == std::strong_ordering::less, "");
+ static_assert((t1 <=> t3) == std::strong_ordering::less, "");
+
+ static_assert((t2 <=> t1) == std::strong_ordering::greater, "");
+ static_assert((t3 <=> t2) == std::strong_ordering::greater, "");
+ static_assert((t3 <=> t1) == std::strong_ordering::greater, "");
+
+#endif // __cpp_impl_three_way_comparison
}
TEST(Time, Infinity) {
@@ -218,6 +239,15 @@ TEST(Time, Infinity) {
static_assert(ipast < ifuture, "");
static_assert(ifuture > ipast, "");
+#ifdef __cpp_impl_three_way_comparison
+
+ static_assert((ifuture <=> ifuture) == std::strong_ordering::equal, "");
+ static_assert((ipast <=> ipast) == std::strong_ordering::equal, "");
+ static_assert((ipast <=> ifuture) == std::strong_ordering::less, "");
+ static_assert((ifuture <=> ipast) == std::strong_ordering::greater, "");
+
+#endif // __cpp_impl_three_way_comparison
+
// Arithmetic saturates
EXPECT_EQ(ifuture, ifuture + absl::Seconds(1));
EXPECT_EQ(ifuture, ifuture - absl::Seconds(1));
@@ -233,6 +263,15 @@ TEST(Time, Infinity) {
static_assert(t < ifuture, "");
static_assert(t > ipast, "");
+#ifdef __cpp_impl_three_way_comparison
+
+ static_assert((t <=> ifuture) == std::strong_ordering::less, "");
+ static_assert((t <=> ipast) == std::strong_ordering::greater, "");
+ static_assert((ipast <=> t) == std::strong_ordering::less, "");
+ static_assert((ifuture <=> t) == std::strong_ordering::greater, "");
+
+#endif // __cpp_impl_three_way_comparison
+
EXPECT_EQ(ifuture, t + absl::InfiniteDuration());
EXPECT_EQ(ipast, t - absl::InfiniteDuration());
}