From c7fea71db576882463769b40d3968aa5f1bf42b4 Mon Sep 17 00:00:00 2001 From: Ted John Date: Thu, 22 Oct 2020 20:18:43 +0100 Subject: [PATCH] Add test for codepoint view --- test/tests/StringTest.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/tests/StringTest.cpp b/test/tests/StringTest.cpp index 6de13d7f24..f2f002244e 100644 --- a/test/tests/StringTest.cpp +++ b/test/tests/StringTest.cpp @@ -177,3 +177,29 @@ TEST_F(StringTest, strlogicalcmp) EXPECT_LT(strlogicalcmp("!", "A"), 0); EXPECT_LT(strlogicalcmp("!", "a"), 0); } + +class CodepointViewTest : public testing::Test +{ +}; + +static std::vector ToVector(std::string_view s) +{ + std::vector codepoints; + for (auto codepoint : CodepointView(s)) + { + codepoints.push_back(codepoint); + } + return codepoints; +} + +static void AssertCodepoints(std::string_view s, const std::vector& expected) +{ + ASSERT_EQ(ToVector(s), expected); +} + +TEST_F(CodepointViewTest, CodepointView_iterate) +{ + AssertCodepoints("test", { 't', 'e', 's', 't' }); + AssertCodepoints("ゲスト", { U'ゲ', U'ス', U'ト' }); + AssertCodepoints("<🎢>", { U'<', U'🎢', U'>' }); +}