From aa85c5b4a8b947bf8a6fab1d306e2c980e4e39d3 Mon Sep 17 00:00:00 2001 From: heinrich5991 Date: Wed, 14 Mar 2018 03:04:41 +0100 Subject: [PATCH] Add string and nameban tests with Unicode characters --- src/test/name_ban.cpp | 1 + src/test/str.cpp | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/src/test/name_ban.cpp b/src/test/name_ban.cpp index e6ab205cb..1fd06babf 100644 --- a/src/test/name_ban.cpp +++ b/src/test/name_ban.cpp @@ -15,6 +15,7 @@ TEST(NameBan, Equality) ASSERT_TRUE(IsNameBanned(" abc", &Abc0, 1)); ASSERT_TRUE(IsNameBanned("abc ", &Abc0, 1)); ASSERT_TRUE(IsNameBanned("abc foo", &Abc0, 1)); // Maximum name length. + ASSERT_TRUE(IsNameBanned("äbc", &Abc0, 1)); // Confusables ASSERT_FALSE(IsNameBanned("def", &Abc0, 1)); ASSERT_FALSE(IsNameBanned("abcdef", &Abc0, 1)); } diff --git a/src/test/str.cpp b/src/test/str.cpp index 2e44d48d5..22c06ad70 100644 --- a/src/test/str.cpp +++ b/src/test/str.cpp @@ -20,8 +20,14 @@ TEST(Str, Dist) TEST(Str, Utf8Isspace) { + EXPECT_TRUE(str_utf8_isspace(0x200b)); // Zero-width space EXPECT_TRUE(str_utf8_isspace(' ')); EXPECT_FALSE(str_utf8_isspace('a')); + // Control characters. + for(char c = 0; c < 0x20; c++) + { + EXPECT_TRUE(str_utf8_isspace(c)); + } } TEST(Str, Utf8SkipWhitespaces) @@ -29,6 +35,7 @@ TEST(Str, Utf8SkipWhitespaces) EXPECT_STREQ(str_utf8_skip_whitespaces("abc"), "abc"); EXPECT_STREQ(str_utf8_skip_whitespaces("abc "), "abc "); EXPECT_STREQ(str_utf8_skip_whitespaces(" abc"), "abc"); + EXPECT_STREQ(str_utf8_skip_whitespaces("\xe2\x80\x8b abc"), "abc"); } TEST(Str, Utf8TrimRight) @@ -36,4 +43,5 @@ TEST(Str, Utf8TrimRight) char A1[] = "abc"; str_utf8_trim_right(A1); EXPECT_STREQ(A1, "abc"); char A2[] = " abc"; str_utf8_trim_right(A2); EXPECT_STREQ(A2, " abc"); char A3[] = "abc "; str_utf8_trim_right(A3); EXPECT_STREQ(A3, "abc"); + char A4[] = "abc \xe2\x80\x8b"; str_utf8_trim_right(A4); EXPECT_STREQ(A4, "abc"); }