diff --git a/AK/Tests/TestString.cpp b/AK/Tests/TestString.cpp index 7620af49a24..f42ba3a928c 100644 --- a/AK/Tests/TestString.cpp +++ b/AK/Tests/TestString.cpp @@ -87,8 +87,8 @@ TEST_CASE(starts_with) EXPECT(!test_string.starts_with('B')); EXPECT(test_string.starts_with("ABCDEF")); EXPECT(!test_string.starts_with("DEF")); - EXPECT(test_string.starts_with("abc", CaseSensitivity::CaseInsensitive)); - EXPECT(!test_string.starts_with("abc", CaseSensitivity::CaseSensitive)); + EXPECT(test_string.starts_with("abc", CaseSensitivity::CaseInsensitive)); + EXPECT(!test_string.starts_with("abc", CaseSensitivity::CaseSensitive)); } TEST_CASE(ends_with) @@ -99,8 +99,8 @@ TEST_CASE(ends_with) EXPECT(!test_string.ends_with('E')); EXPECT(test_string.ends_with("ABCDEF")); EXPECT(!test_string.ends_with("ABC")); - EXPECT(test_string.ends_with("def", CaseSensitivity::CaseInsensitive)); - EXPECT(!test_string.ends_with("def", CaseSensitivity::CaseSensitive)); + EXPECT(test_string.ends_with("def", CaseSensitivity::CaseInsensitive)); + EXPECT(!test_string.ends_with("def", CaseSensitivity::CaseSensitive)); } TEST_CASE(copy_string) @@ -225,15 +225,21 @@ TEST_CASE(split) EXPECT_EQ(parts[2], ""); EXPECT_EQ(parts[3], ""); EXPECT_EQ(parts[4], "b"); + + test = "axxbx"; + EXPECT_EQ(test.split('x').size(), 2u); + EXPECT_EQ(test.split('x', true).size(), 4u); + EXPECT_EQ(test.split_view('x').size(), 2u); + EXPECT_EQ(test.split_view('x', true).size(), 4u); } TEST_CASE(builder_zero_initial_capacity) { - StringBuilder builder(0); - builder.append(""); - auto built = builder.build(); - EXPECT_EQ(built.is_null(), false); - EXPECT_EQ(built.length(), 0u); + StringBuilder builder(0); + builder.append(""); + auto built = builder.build(); + EXPECT_EQ(built.is_null(), false); + EXPECT_EQ(built.length(), 0u); } TEST_MAIN(String) diff --git a/AK/Tests/TestStringView.cpp b/AK/Tests/TestStringView.cpp index 021be691b22..56cf440720e 100644 --- a/AK/Tests/TestStringView.cpp +++ b/AK/Tests/TestStringView.cpp @@ -68,8 +68,8 @@ TEST_CASE(starts_with) EXPECT(test_string_view.starts_with("AB")); EXPECT(test_string_view.starts_with("ABCDEF")); EXPECT(!test_string_view.starts_with("DEF")); - EXPECT(test_string_view.starts_with("abc", CaseSensitivity::CaseInsensitive)); - EXPECT(!test_string_view.starts_with("abc", CaseSensitivity::CaseSensitive)); + EXPECT(test_string_view.starts_with("abc", CaseSensitivity::CaseInsensitive)); + EXPECT(!test_string_view.starts_with("abc", CaseSensitivity::CaseSensitive)); } TEST_CASE(ends_with) @@ -82,8 +82,8 @@ TEST_CASE(ends_with) EXPECT(test_string_view.ends_with("ABCDEF")); EXPECT(!test_string_view.ends_with("ABCDE")); EXPECT(!test_string_view.ends_with("ABCDEFG")); - EXPECT(test_string_view.ends_with("def", CaseSensitivity::CaseInsensitive)); - EXPECT(!test_string_view.ends_with("def", CaseSensitivity::CaseSensitive)); + EXPECT(test_string_view.ends_with("def", CaseSensitivity::CaseInsensitive)); + EXPECT(!test_string_view.ends_with("def", CaseSensitivity::CaseSensitive)); } TEST_CASE(lines) @@ -157,5 +157,23 @@ TEST_CASE(find_last_of) EXPECT_EQ(test_string_view.find_last_of("fghi").has_value(), false); } +TEST_CASE(split_view) +{ + StringView test_string_view = "axxbxcxd"; + EXPECT_EQ(test_string_view.split_view('x'), Vector({ "a", "b", "c", "d" })); + EXPECT_EQ(test_string_view.split_view('x', true), Vector({ "a", "", "b", "c", "d" })); + EXPECT_EQ(test_string_view.split_view("x"), Vector({ "a", "b", "c", "d" })); + EXPECT_EQ(test_string_view.split_view("x", true), Vector({ "a", "", "b", "c", "d" })); + + test_string_view = "axxbx"; + EXPECT_EQ(test_string_view.split_view('x'), Vector({ "a", "b" })); + EXPECT_EQ(test_string_view.split_view('x', true), Vector({ "a", "", "b", "" })); + EXPECT_EQ(test_string_view.split_view("x"), Vector({ "a", "b" })); + EXPECT_EQ(test_string_view.split_view("x", true), Vector({ "a", "", "b", "" })); + + test_string_view = "axxbcxxdxx"; + EXPECT_EQ(test_string_view.split_view("xx"), Vector({ "a", "bc", "d" })); + EXPECT_EQ(test_string_view.split_view("xx", true), Vector({ "a", "bc", "d", "" })); +} TEST_MAIN(StringView)