]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
test: Add tests for util::to_string and util::to_string_view
authorJoel Rosdahl <joel@rosdahl.net>
Wed, 5 Oct 2022 18:57:41 +0000 (20:57 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Wed, 5 Oct 2022 19:18:02 +0000 (21:18 +0200)
unittest/test_util_string.cpp

index 3d7220298340127cd331d76ffe9444a898effb25..2a45fbcd9c425f28e7dda78e027073301ab5c58b 100644 (file)
@@ -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();