summaryrefslogtreecommitdiffstats
path: root/src/template_test.cc
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/template_test.cc35
1 files changed, 29 insertions, 6 deletions
diff --git a/src/template_test.cc b/src/template_test.cc
index db212d1..99b193b 100644
--- a/src/template_test.cc
+++ b/src/template_test.cc
@@ -32,12 +32,15 @@
#include "template.h"
+using namespace std::literals;
+
namespace nghttp2 {
namespace {
const MunitTest tests[]{
munit_void_test(test_template_immutable_string),
munit_void_test(test_template_string_ref),
+ munit_void_test(test_template_as_uint8_span),
munit_test_end(),
};
} // namespace
@@ -147,7 +150,7 @@ void test_template_immutable_string(void) {
void test_template_string_ref(void) {
StringRef empty;
- assert_stdstring_equal("", empty.str());
+ assert_stdsv_equal(""sv, empty);
assert_size(0, ==, empty.size());
// from std::string
@@ -162,9 +165,9 @@ void test_template_string_ref(void) {
assert_size(5, ==, ref.size());
// from string literal
- auto from_lit = StringRef::from_lit("alpha");
+ auto from_lit = "alpha"_sr;
- assert_stdstring_equal("alpha", from_lit.str());
+ assert_stdsv_equal("alpha"sv, from_lit);
assert_size(5, ==, from_lit.size());
// from ImmutableString
@@ -172,19 +175,19 @@ void test_template_string_ref(void) {
StringRef imref(im);
- assert_stdstring_equal("bravo", imref.str());
+ assert_stdsv_equal("bravo"sv, imref);
assert_size(5, ==, imref.size());
// from C-string
StringRef cstrref("charlie");
- assert_stdstring_equal("charlie", cstrref.str());
+ assert_stdsv_equal("charlie"sv, cstrref);
assert_size(7, ==, cstrref.size());
// from C-string and its length
StringRef cstrnref("delta", 5);
- assert_stdstring_equal("delta", cstrnref.str());
+ assert_stdsv_equal("delta"sv, cstrnref);
assert_size(5, ==, cstrnref.size());
// operator[]
@@ -213,4 +216,24 @@ void test_template_string_ref(void) {
}
}
+void test_template_as_uint8_span(void) {
+ uint32_t a[2];
+
+ memcpy(&a, "\xc0\xc1\xc2\xc3\xf0\xf1\xf2\xf3", sizeof(a));
+
+ // dynamic extent
+ auto s = as_uint8_span(std::span{a, 2});
+
+ assert_size(sizeof(a), ==, s.size());
+ assert_size(std::dynamic_extent, ==, s.extent);
+ assert_memory_equal(s.size(), &a, s.data());
+
+ // non-dynamic extent
+ auto t = as_uint8_span(std::span<uint32_t, 2>{a, 2});
+
+ assert_size(sizeof(a), ==, t.size());
+ assert_size(sizeof(a), ==, t.extent);
+ assert_memory_equal(t.size(), &a, t.data());
+}
+
} // namespace nghttp2