Add string and nameban tests with Unicode characters

This commit is contained in:
heinrich5991 2018-03-14 03:04:41 +01:00
parent c65ffeb4ae
commit aa85c5b4a8
2 changed files with 9 additions and 0 deletions

View file

@ -15,6 +15,7 @@ TEST(NameBan, Equality)
ASSERT_TRUE(IsNameBanned(" abc", &Abc0, 1)); ASSERT_TRUE(IsNameBanned(" abc", &Abc0, 1));
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("abc foo", &Abc0, 1)); // Maximum name length.
ASSERT_TRUE(IsNameBanned("äbc", &Abc0, 1)); // Confusables
ASSERT_FALSE(IsNameBanned("def", &Abc0, 1)); ASSERT_FALSE(IsNameBanned("def", &Abc0, 1));
ASSERT_FALSE(IsNameBanned("abcdef", &Abc0, 1)); ASSERT_FALSE(IsNameBanned("abcdef", &Abc0, 1));
} }

View file

@ -20,8 +20,14 @@ TEST(Str, Dist)
TEST(Str, Utf8Isspace) TEST(Str, Utf8Isspace)
{ {
EXPECT_TRUE(str_utf8_isspace(0x200b)); // Zero-width space
EXPECT_TRUE(str_utf8_isspace(' ')); EXPECT_TRUE(str_utf8_isspace(' '));
EXPECT_FALSE(str_utf8_isspace('a')); EXPECT_FALSE(str_utf8_isspace('a'));
// Control characters.
for(char c = 0; c < 0x20; c++)
{
EXPECT_TRUE(str_utf8_isspace(c));
}
} }
TEST(Str, Utf8SkipWhitespaces) 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("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) TEST(Str, Utf8TrimRight)
@ -36,4 +43,5 @@ TEST(Str, Utf8TrimRight)
char A1[] = "abc"; str_utf8_trim_right(A1); EXPECT_STREQ(A1, "abc"); 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 A2[] = " abc"; str_utf8_trim_right(A2); EXPECT_STREQ(A2, " abc");
char A3[] = "abc "; str_utf8_trim_right(A3); EXPECT_STREQ(A3, "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");
} }