Browse Source

Add a test for merged Incrementable/Decrementable

Sam Jaffe 5 years ago
parent
commit
fab07db2ba
1 changed files with 9 additions and 1 deletions
  1. 9 1
      test/opaque_typedef_arithmatic_test.cxx

+ 9 - 1
test/opaque_typedef_arithmatic_test.cxx

@@ -7,7 +7,6 @@
 //
 
 #include <gmock/gmock.h>
-#include <cmath>
 
 #include "opaque_typedef/arithmatic.hpp"
 #include "opaque_typedef/opaque_typedef.hpp"
@@ -29,6 +28,7 @@ template <typename T> void operator--(T);
 using namespace types;
 using counter = opaque_typedef<uint32_t, struct counter_tag, Incrementable>;
 using countdown = opaque_typedef<uint32_t, struct countdown_tag, Decrementable>;
+using idx = opaque_typedef<uint32_t, struct idx_tag, Incrementable, Decrementable>;
 
 // Actual Test Bodies
 TEST(OpaqueTypedefDecrementableTest, CannotDecrement) {
@@ -66,3 +66,11 @@ TEST(OpaqueTypedefDecrementableTest, CanPreDecrement) {
   EXPECT_THAT(--c, testing::Eq(countdown{9}));
   EXPECT_THAT(c, testing::Eq(countdown{9}));
 }
+
+TEST(OpaqueTypedefArithmaticTest, CanMergeIncrementAndDecrement) {
+  idx i{1};
+  EXPECT_TRUE((testing::StaticAssertTypeEq<idx, decltype(i--)>()));
+  EXPECT_TRUE((testing::StaticAssertTypeEq<idx&, decltype(--i)>()));
+  EXPECT_TRUE((testing::StaticAssertTypeEq<idx, decltype(i++)>()));
+  EXPECT_TRUE((testing::StaticAssertTypeEq<idx&, decltype(++i)>()));
+}