summaryrefslogtreecommitdiff
path: root/Tests
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-09-18 18:02:41 +0200
committerAndreas Kling <kling@serenityos.org>2021-09-18 19:54:24 +0200
commit1be4cbd6395202183d7aa74119661aae71a8b8d9 (patch)
treef2593d9fee011da56f127b7583fba4eea4b8dd4e /Tests
parent291dbff2e1dbd1963e07fdc92779b5c25e635127 (diff)
downloadserenity-1be4cbd6395202183d7aa74119661aae71a8b8d9.zip
AK: Make Utf8View constructors inline and remove C string constructor
Using StringView instead of C strings is basically always preferable. The only reason to use a C string is because you are calling a C API.
Diffstat (limited to 'Tests')
-rw-r--r--Tests/AK/TestUtf8.cpp34
-rw-r--r--Tests/LibRegex/Regex.cpp2
2 files changed, 18 insertions, 18 deletions
diff --git a/Tests/AK/TestUtf8.cpp b/Tests/AK/TestUtf8.cpp
index 60690de967..7139c06aca 100644
--- a/Tests/AK/TestUtf8.cpp
+++ b/Tests/AK/TestUtf8.cpp
@@ -11,7 +11,7 @@
TEST_CASE(decode_ascii)
{
- Utf8View utf8 { "Hello World!11" };
+ Utf8View utf8 { "Hello World!11"sv };
EXPECT(utf8.validate());
u32 expected[] = { 72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33, 49, 49 };
@@ -28,7 +28,7 @@ TEST_CASE(decode_ascii)
TEST_CASE(decode_utf8)
{
- Utf8View utf8 { "Привет, мир! 😀 γειά σου κόσμος こんにちは世界" };
+ Utf8View utf8 { "Привет, мир! 😀 γειά σου κόσμος こんにちは世界"sv };
size_t valid_bytes;
EXPECT(utf8.validate(valid_bytes));
EXPECT(valid_bytes == (size_t)utf8.byte_length());
@@ -52,29 +52,29 @@ TEST_CASE(validate_invalid_ut8)
{
size_t valid_bytes;
char invalid_utf8_1[] = { 42, 35, (char)182, 9, 0 };
- Utf8View utf8_1 { invalid_utf8_1 };
+ Utf8View utf8_1 { StringView { invalid_utf8_1 } };
EXPECT(!utf8_1.validate(valid_bytes));
EXPECT(valid_bytes == 2);
char invalid_utf8_2[] = { 42, 35, (char)208, (char)208, 0 };
- Utf8View utf8_2 { invalid_utf8_2 };
+ Utf8View utf8_2 { StringView { invalid_utf8_2 } };
EXPECT(!utf8_2.validate(valid_bytes));
EXPECT(valid_bytes == 2);
char invalid_utf8_3[] = { (char)208, 0 };
- Utf8View utf8_3 { invalid_utf8_3 };
+ Utf8View utf8_3 { StringView { invalid_utf8_3 } };
EXPECT(!utf8_3.validate(valid_bytes));
EXPECT(valid_bytes == 0);
char invalid_utf8_4[] = { (char)208, 35, 0 };
- Utf8View utf8_4 { invalid_utf8_4 };
+ Utf8View utf8_4 { StringView { invalid_utf8_4 } };
EXPECT(!utf8_4.validate(valid_bytes));
EXPECT(valid_bytes == 0);
}
TEST_CASE(iterate_utf8)
{
- Utf8View view("Some weird characters \u00A9\u266A\uA755");
+ Utf8View view("Some weird characters \u00A9\u266A\uA755"sv);
Utf8CodePointIterator iterator = view.begin();
EXPECT(*iterator == 'S');
@@ -113,7 +113,7 @@ TEST_CASE(decode_invalid_ut8)
// Test case 1 : Getting an extension byte as first byte of the code point
{
char raw_data[] = { 'a', 'b', (char)0xA0, 'd', 0 };
- Utf8View view { raw_data };
+ Utf8View view { StringView { raw_data } };
u32 expected_characters[] = { 'a', 'b', 0xFFFD, 'd' };
String expected_underlying_bytes[] = { "a", "b", "\xA0", "d" };
size_t expected_size = sizeof(expected_characters) / sizeof(expected_characters[0]);
@@ -131,7 +131,7 @@ TEST_CASE(decode_invalid_ut8)
// Test case 2 : Getting a non-extension byte when an extension byte is expected
{
char raw_data[] = { 'a', 'b', (char)0xC0, 'd', 'e', 0 };
- Utf8View view { raw_data };
+ Utf8View view { StringView { raw_data } };
u32 expected_characters[] = { 'a', 'b', 0xFFFD, 'd', 'e' };
String expected_underlying_bytes[] = { "a", "b", "\xC0", "d", "e" };
size_t expected_size = sizeof(expected_characters) / sizeof(expected_characters[0]);
@@ -149,7 +149,7 @@ TEST_CASE(decode_invalid_ut8)
// Test case 3 : Not enough bytes before the end of the string
{
char raw_data[] = { 'a', 'b', (char)0x90, 'd', 0 };
- Utf8View view { raw_data };
+ Utf8View view { StringView { raw_data } };
u32 expected_characters[] = { 'a', 'b', 0xFFFD, 'd' };
String expected_underlying_bytes[] = { "a", "b", "\x90", "d" };
size_t expected_size = sizeof(expected_characters) / sizeof(expected_characters[0]);
@@ -167,7 +167,7 @@ TEST_CASE(decode_invalid_ut8)
// Test case 4 : Not enough bytes at the end of the string
{
char raw_data[] = { 'a', 'b', 'c', (char)0x90, 0 };
- Utf8View view { raw_data };
+ Utf8View view { StringView { raw_data } };
u32 expected_characters[] = { 'a', 'b', 'c', 0xFFFD };
String expected_underlying_bytes[] = { "a", "b", "c", "\x90" };
size_t expected_size = sizeof(expected_characters) / sizeof(expected_characters[0]);
@@ -185,33 +185,33 @@ TEST_CASE(decode_invalid_ut8)
TEST_CASE(trim)
{
- Utf8View whitespace { " " };
+ Utf8View whitespace { " "sv };
{
- Utf8View view { "word" };
+ Utf8View view { "word"sv };
EXPECT_EQ(view.trim(whitespace, TrimMode::Both).as_string(), "word");
EXPECT_EQ(view.trim(whitespace, TrimMode::Left).as_string(), "word");
EXPECT_EQ(view.trim(whitespace, TrimMode::Right).as_string(), "word");
}
{
- Utf8View view { " word" };
+ Utf8View view { " word"sv };
EXPECT_EQ(view.trim(whitespace, TrimMode::Both).as_string(), "word");
EXPECT_EQ(view.trim(whitespace, TrimMode::Left).as_string(), "word");
EXPECT_EQ(view.trim(whitespace, TrimMode::Right).as_string(), " word");
}
{
- Utf8View view { "word " };
+ Utf8View view { "word "sv };
EXPECT_EQ(view.trim(whitespace, TrimMode::Both).as_string(), "word");
EXPECT_EQ(view.trim(whitespace, TrimMode::Left).as_string(), "word ");
EXPECT_EQ(view.trim(whitespace, TrimMode::Right).as_string(), "word");
}
{
- Utf8View view { " word " };
+ Utf8View view { " word "sv };
EXPECT_EQ(view.trim(whitespace, TrimMode::Both).as_string(), "word");
EXPECT_EQ(view.trim(whitespace, TrimMode::Left).as_string(), "word ");
EXPECT_EQ(view.trim(whitespace, TrimMode::Right).as_string(), " word");
}
{
- Utf8View view { "\u180E" };
+ Utf8View view { "\u180E"sv };
EXPECT_EQ(view.trim(whitespace, TrimMode::Both).as_string(), "\u180E");
EXPECT_EQ(view.trim(whitespace, TrimMode::Left).as_string(), "\u180E");
EXPECT_EQ(view.trim(whitespace, TrimMode::Right).as_string(), "\u180E");
diff --git a/Tests/LibRegex/Regex.cpp b/Tests/LibRegex/Regex.cpp
index bd217501fc..5c3fe5d514 100644
--- a/Tests/LibRegex/Regex.cpp
+++ b/Tests/LibRegex/Regex.cpp
@@ -256,7 +256,7 @@ TEST_CASE(char_utf8)
Regex<PosixExtended> re("😀");
RegexResult result;
- EXPECT_EQ((result = match(Utf8View { "Привет, мир! 😀 γειά σου κόσμος 😀 こんにちは世界" }, re, PosixFlags::Global)).success, true);
+ EXPECT_EQ((result = match(Utf8View { "Привет, мир! 😀 γειά σου κόσμος 😀 こんにちは世界"sv }, re, PosixFlags::Global)).success, true);
EXPECT_EQ(result.count, 2u);
}