summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Rosdahl <joel@rosdahl.net>2022-10-05 20:57:41 +0200
committerJoel Rosdahl <joel@rosdahl.net>2022-10-05 21:18:02 +0200
commit425461ec69586e09c49229138e55267bc8d180fd (patch)
treeef296d86940c7a28734ceb002d85e06ebf1aab8b
parentfe9c0dfa93df290e974aa2dc6c29b163496db22e (diff)
downloadccache-425461ec69586e09c49229138e55267bc8d180fd.tar.gz
test: Add tests for util::to_string and util::to_string_view
-rw-r--r--unittest/test_util_string.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/unittest/test_util_string.cpp b/unittest/test_util_string.cpp
index 3d722029..2a45fbcd 100644
--- a/unittest/test_util_string.cpp
+++ b/unittest/test_util_string.cpp
@@ -20,6 +20,7 @@
#include <third_party/doctest.h>
+#include <ostream> // https://github.com/doctest/doctest/issues/618
#include <vector>
static bool
@@ -286,4 +287,20 @@ TEST_CASE("util::strip_whitespace")
CHECK(util::strip_whitespace(" x y ") == "x y");
}
+TEST_CASE("util::to_string")
+{
+ const char str[] = "foo";
+
+ CHECK(util::to_string(std::string(str)) == std::string(str));
+ CHECK(util::to_string(std::string_view(str)) == std::string(str));
+}
+
+TEST_CASE("util::to_string_view")
+{
+ uint8_t bytes[] = {'f', 'o', 'o'};
+ char str[] = "foo";
+
+ CHECK(util::to_string_view(nonstd::span(bytes)) == std::string(str));
+}
+
TEST_SUITE_END();