From: Joel Rosdahl Date: Wed, 5 Oct 2022 18:57:41 +0000 (+0200) Subject: test: Add tests for util::to_string and util::to_string_view X-Git-Tag: v4.7~23 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=425461ec69586e09c49229138e55267bc8d180fd;p=thirdparty%2Fccache.git test: Add tests for util::to_string and util::to_string_view --- diff --git a/unittest/test_util_string.cpp b/unittest/test_util_string.cpp index 3d7220298..2a45fbcd9 100644 --- a/unittest/test_util_string.cpp +++ b/unittest/test_util_string.cpp @@ -20,6 +20,7 @@ #include +#include // https://github.com/doctest/doctest/issues/618 #include 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();