test/raw: Convert to googletest

Catch2 never really took off and googletest mostly gives us everything
we need.

Change-Id: I5988fa05b6a9ed09a15c063d62736135d2bd0f7d
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/test/raw.cpp b/test/raw.cpp
index 5e48419..5248b9f 100644
--- a/test/raw.cpp
+++ b/test/raw.cpp
@@ -1,10 +1,7 @@
 #include <array>
-#if __has_include(<catch2/catch.hpp>)
-#include <catch2/catch.hpp>
-#else
-#include <catch2/catch_test_macros.hpp>
-#endif
 #include <endian.h>
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
 #include <span>
 #include <stdexcept>
 #include <stdplus/raw.hpp>
@@ -18,36 +15,36 @@
 namespace
 {
 
-TEST_CASE("Equal", "[Equal]")
+TEST(Equal, Equal)
 {
     int a = 4;
     unsigned b = 4;
-    CHECK(equal(a, b));
+    EXPECT_TRUE(equal(a, b));
     b = 5;
-    CHECK(!equal(a, b));
+    EXPECT_FALSE(equal(a, b));
 }
 
-TEST_CASE("Copy From Empty", "[CopyFrom]")
+TEST(CopyFrom, Empty)
 {
     const std::string_view cs;
-    CHECK_THROWS_AS(copyFrom<int>(cs), std::runtime_error);
+    EXPECT_THROW(copyFrom<int>(cs), std::runtime_error);
     std::string_view s;
-    CHECK_THROWS_AS(copyFrom<int>(s), std::runtime_error);
+    EXPECT_THROW(copyFrom<int>(s), std::runtime_error);
 }
 
-TEST_CASE("Copy From Basic", "[CopyFrom]")
+TEST(CopyFrom, Basic)
 {
     int a = 4;
     const std::string_view s(reinterpret_cast<char*>(&a), sizeof(a));
-    CHECK(a == copyFrom<int>(s));
+    EXPECT_EQ(a, copyFrom<int>(s));
 }
 
-TEST_CASE("Copy From Partial", "[CopyFrom]")
+TEST(CopyFrom, Partial)
 {
     const std::vector<char> s = {'a', 'b', 'c'};
-    CHECK('a' == copyFrom<char>(s));
+    EXPECT_EQ('a', copyFrom<char>(s));
     const char s2[] = "def";
-    CHECK('d' == copyFrom<char>(s2));
+    EXPECT_EQ('d', copyFrom<char>(s2));
 }
 
 struct Int
@@ -60,176 +57,167 @@
     }
 };
 
-TEST_CASE("Ref From Empty", "[RefFrom]")
+TEST(RefFrom, Empty)
 {
     const std::string_view cs;
-    CHECK_THROWS_AS(refFrom<Int>(cs), std::runtime_error);
+    EXPECT_THROW(refFrom<Int>(cs), std::runtime_error);
     std::string_view s;
-    CHECK_THROWS_AS(refFrom<Int>(s), std::runtime_error);
+    EXPECT_THROW(refFrom<Int>(s), std::runtime_error);
 }
 
-TEST_CASE("Ref From Basic", "[RefFrom]")
+TEST(RefFrom, Basic)
 {
     Int a = {4, 0, 0, 4};
     const std::string_view s(reinterpret_cast<char*>(&a), sizeof(a));
-    CHECK(a == refFrom<Int>(s));
+    EXPECT_EQ(a, refFrom<Int>(s));
 }
 
-TEST_CASE("Ref From Partial", "[RefFrom]")
+TEST(RefFrom, Partial)
 {
     const std::vector<char> s = {'a', 'b', 'c'};
-    CHECK('a' == refFrom<char>(s));
+    EXPECT_EQ('a', refFrom<char>(s));
     const char s2[] = "def";
-    CHECK('d' == refFrom<char>(s2));
+    EXPECT_EQ('d', refFrom<char>(s2));
 }
 
-TEST_CASE("Extract Too Small", "[Extract]")
+TEST(Extract, TooSmall)
 {
     std::string_view s("a");
-    CHECK_THROWS_AS(extract<int>(s), std::runtime_error);
-    CHECK(1 == s.size());
+    EXPECT_THROW(extract<int>(s), std::runtime_error);
+    EXPECT_EQ("a", s);
 }
 
-TEST_CASE("Extract Basic", "[Extract]")
+TEST(Extract, Basic)
 {
     int a = 4;
     std::string_view s(reinterpret_cast<char*>(&a), sizeof(a));
-    CHECK(a == extract<int>(s));
-    CHECK(s.empty());
+    EXPECT_EQ(a, extract<int>(s));
+    EXPECT_TRUE(s.empty());
 }
 
-TEST_CASE("Extract Partial", "[Extract]")
+TEST(Extract, Partial)
 {
     std::string_view s("abc");
-    CHECK('a' == extract<char>(s));
-    CHECK(2 == s.size());
+    EXPECT_EQ('a', extract<char>(s));
+    EXPECT_EQ("bc", s);
 }
 
-TEST_CASE("Extract Ref Too Small", "[ExtractRef]")
+TEST(ExtractRef, TooSmall)
 {
     std::string_view s("a");
-    CHECK_THROWS_AS(extractRef<Int>(s), std::runtime_error);
-    CHECK(1 == s.size());
+    EXPECT_THROW(extractRef<Int>(s), std::runtime_error);
+    EXPECT_EQ("a", s);
 }
 
-TEST_CASE("Extract Ref Basic", "[ExtractRef]")
+TEST(ExtractRef, Basic)
 {
     Int a = {4, 0, 0, 4};
     std::string_view s(reinterpret_cast<char*>(&a), sizeof(a));
-    CHECK(a == extractRef<Int>(s));
-    CHECK(s.empty());
+    EXPECT_EQ(a, extractRef<Int>(s));
+    EXPECT_TRUE(s.empty());
 }
 
-TEST_CASE("Extract Ref Partial", "[ExtractRef]")
+TEST(ExtractRef, Partial)
 {
     std::string_view s("abc");
-    CHECK('a' == extractRef<char>(s));
-    CHECK(2 == s.size());
+    EXPECT_EQ('a', extractRef<char>(s));
+    EXPECT_EQ("bc", s);
 }
 
-TEST_CASE("As View Byte", "[AsView]")
+TEST(AsView, Byte)
 {
     int32_t a = 4;
     auto s = asView<uint8_t>(a);
-    CHECK(a == copyFrom<int>(s));
+    EXPECT_EQ(a, copyFrom<int>(s));
 }
 
-TEST_CASE("As View Int", "[AsView]")
+TEST(AsView, Int)
 {
     int32_t a = 4;
     auto s = asView<char16_t>(a);
-    CHECK(a == copyFrom<int>(s));
+    EXPECT_EQ(a, copyFrom<int>(s));
 }
 
-TEST_CASE("As View Arr", "[AsView]")
+using testing::ElementsAre;
+using testing::ElementsAreArray;
+
+TEST(AsView, Array)
 {
     std::vector<uint32_t> arr = {htole32(1), htole32(2)};
     auto s = asView<char16_t>(arr);
-    REQUIRE(4 == s.size());
-    CHECK(htole16(1) == s[0]);
-    CHECK(htole16(0) == s[1]);
-    CHECK(htole16(2) == s[2]);
-    CHECK(htole16(0) == s[3]);
+    EXPECT_THAT(s, ElementsAre(htole16(1), htole16(0), htole16(2), htole16(0)));
 }
 
-TEST_CASE("As View View", "[AsView]")
+TEST(AsView, StringView)
 {
     std::string_view sv = "ab";
     auto s = asView<uint8_t>(sv);
-    REQUIRE(s.size() == 2);
-    CHECK(s[0] == sv[0]);
-    CHECK(s[1] == sv[1]);
+    EXPECT_THAT(s, ElementsAreArray(sv));
 }
 
-TEST_CASE("Span Extract TooSmall", "[Extract]")
+TEST(SpanExtract, TooSmall)
 {
     const std::vector<char> v = {'c'};
     std::span<const char> s = v;
-    CHECK_THROWS_AS(extract<int>(s), std::runtime_error);
-    CHECK(1 == s.size());
+    EXPECT_THROW(extract<int>(s), std::runtime_error);
+    EXPECT_THAT(s, ElementsAreArray(v));
 }
 
-TEST_CASE("Span Extract Basic", "[Extract]")
+TEST(SpanExtract, Basic)
 {
     const std::vector<int> v = {4};
     std::span<const int> s = v;
-    CHECK(v[0] == extract<int>(s));
-    CHECK(s.empty());
+    EXPECT_EQ(v[0], extract<int>(s));
+    EXPECT_TRUE(s.empty());
 }
 
-TEST_CASE("Span Extract Larger", "[Extract]")
+TEST(SpanExtract, Larger)
 {
     const std::vector<int> v{3, 4, 5};
     std::span<const int> s = v;
-    CHECK(v[0] == extract<int>(s));
-    CHECK(v.size() - 1 == s.size());
+    EXPECT_EQ(v[0], extract<int>(s));
+    EXPECT_THAT(s, ElementsAre(v[1], v[2]));
 }
 
-TEST_CASE("Span Extract Ref TooSmall", "[ExtractRef]")
+TEST(SpanExtractRef, TooSmall)
 {
     const std::vector<char> v = {'c'};
     std::span<const char> s = v;
-    CHECK_THROWS_AS(extractRef<Int>(s), std::runtime_error);
-    CHECK(1 == s.size());
+    EXPECT_THROW(extractRef<Int>(s), std::runtime_error);
+    EXPECT_THAT(s, ElementsAreArray(v));
 }
 
-TEST_CASE("Span Extract Ref Basic", "[ExtractRef]")
+TEST(SpanExtractRef, Basic)
 {
     const std::vector<Int> v = {{4, 0, 0, 4}};
     std::span<const Int> s = v;
-    CHECK(v[0] == extractRef<Int>(s));
-    CHECK(s.empty());
+    EXPECT_EQ(v[0], extractRef<Int>(s));
+    EXPECT_TRUE(s.empty());
 }
 
-TEST_CASE("Span Extract Ref Larger", "[ExtractRef]")
+TEST(SpanExtractRef, Larger)
 {
     const std::vector<Int> v{{3}, {4}, {5}};
     std::span<const Int> s = v;
-    CHECK(v[0] == extractRef<Int>(s));
-    CHECK(v.size() - 1 == s.size());
+    EXPECT_EQ(v[0], extractRef<Int>(s));
+    EXPECT_THAT(s, ElementsAre(v[1], v[2]));
 }
 
-TEST_CASE("As Span const", "[AsSpan]")
+TEST(AsSpan, ConstInt)
 {
     const uint64_t data = htole64(0xffff0000);
     auto s = asSpan<uint32_t>(data);
-    CHECK(s.size() == 2);
-    CHECK(s[0] == htole32(0xffff0000));
-    CHECK(s[1] == htole32(0x00000000));
+    EXPECT_THAT(s, ElementsAre(htole32(0xffff0000), htole32(0x00000000)));
 }
 
-TEST_CASE("As Span Arr const", "[AsSpan]")
+TEST(AsSpan, ConstArray)
 {
     const std::vector<uint32_t> arr = {htole32(1), htole32(2)};
     auto s = asSpan<uint16_t>(arr);
-    REQUIRE(4 == s.size());
-    CHECK(htole16(1) == s[0]);
-    CHECK(htole16(0) == s[1]);
-    CHECK(htole16(2) == s[2]);
-    CHECK(htole16(0) == s[3]);
+    EXPECT_THAT(s, ElementsAre(htole16(1), htole16(0), htole16(2), htole16(0)));
 }
 
-TEST_CASE("As Span", "[AsSpan]")
+TEST(AsSpan, Int)
 {
     struct
     {
@@ -240,38 +228,29 @@
         }
     } data = {htole64(0xffff0000)};
     auto s = asSpan<uint16_t>(data);
-    CHECK(s.size() == 4);
+    EXPECT_THAT(s, ElementsAre(htole16(0x0000), htole16(0xffff),
+                               htole16(0x0000), htole16(0x0000)));
     s[2] = 0xfefe;
-    CHECK(s[0] == htole16(0x0000));
-    CHECK(s[1] == htole16(0xffff));
-    CHECK(s[2] == htole16(0xfefe));
-    CHECK(s[3] == htole16(0x0000));
+    EXPECT_THAT(s, ElementsAre(htole16(0x0000), htole16(0xffff),
+                               htole16(0xfefe), htole16(0x0000)));
 }
 
-TEST_CASE("As Span Arr", "[AsSpan]")
+TEST(AsSpan, Array)
 {
     std::vector<uint32_t> arr = {htole32(1), htole32(2)};
     auto s = asSpan<uint16_t>(arr);
-    REQUIRE(4 == s.size());
-    CHECK(htole16(1) == s[0]);
-    CHECK(htole16(0) == s[1]);
-    CHECK(htole16(2) == s[2]);
-    CHECK(htole16(0) == s[3]);
+    EXPECT_THAT(s, ElementsAre(htole16(1), htole16(0), htole16(2), htole16(0)));
 }
 
-TEST_CASE("As Span Span", "[AsSpan]")
+TEST(AsSpan, Span)
 {
     std::array<char, 2> arr = {'a', 'b'};
     auto sp1 = std::span<const char>(arr);
     auto s1 = asSpan<uint8_t>(sp1);
-    REQUIRE(s1.size() == 2);
-    CHECK(s1[0] == arr[0]);
-    CHECK(s1[1] == arr[1]);
+    EXPECT_THAT(s1, ElementsAreArray(arr));
     auto sp2 = std::span<char>(arr);
     auto s2 = asSpan<uint8_t>(sp2);
-    REQUIRE(s2.size() == 2);
-    CHECK(s2[0] == arr[0]);
-    CHECK(s2[1] == arr[1]);
+    EXPECT_THAT(s2, ElementsAreArray(arr));
 }
 
 } // namespace