raw: Fix span and string_view construnction from views
Change-Id: Iba65d73e4e87a792ef75360326ac76d437dd1a91
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/test/raw.cpp b/test/raw.cpp
index 8be8b7b..2e054bc 100644
--- a/test/raw.cpp
+++ b/test/raw.cpp
@@ -146,6 +146,15 @@
CHECK(htole16(0) == s[3]);
}
+TEST_CASE("As View View", "[AsView]")
+{
+ 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]);
+}
+
#ifdef STDPLUS_SPAN_TYPE
TEST_CASE("Span Extract TooSmall", "[Extract]")
{
@@ -238,6 +247,21 @@
CHECK(htole16(0) == s[3]);
}
+TEST_CASE("As Span Span", "[AsSpan]")
+{
+ std::array<char, 2> arr = {'a', 'b'};
+ auto sp1 = span<const char>(arr);
+ auto s1 = asSpan<uint8_t>(sp1);
+ REQUIRE(s1.size() == 2);
+ CHECK(s1[0] == arr[0]);
+ CHECK(s1[1] == arr[1]);
+ auto sp2 = span<char>(arr);
+ auto s2 = asSpan<uint8_t>(sp2);
+ REQUIRE(s2.size() == 2);
+ CHECK(s2[0] == arr[0]);
+ CHECK(s2[1] == arr[1]);
+}
+
#endif
} // namespace