mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-04 05:20:30 +00:00
AK: Add (more) tests for String(View)::split*
This patchset adds some tests for String(View)::split*, hopefully documenting their behaviour in some cases.
This commit is contained in:
parent
dad22c5d5a
commit
681bb1fb23
Notes:
sideshowbarker
2024-07-19 04:27:50 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/681bb1fb23c Pull-request: https://github.com/SerenityOS/serenity/pull/2907 Reviewed-by: https://github.com/awesomekling
2 changed files with 37 additions and 13 deletions
|
@ -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)
|
||||
|
|
|
@ -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<StringView>({ "a", "b", "c", "d" }));
|
||||
EXPECT_EQ(test_string_view.split_view('x', true), Vector<StringView>({ "a", "", "b", "c", "d" }));
|
||||
EXPECT_EQ(test_string_view.split_view("x"), Vector<StringView>({ "a", "b", "c", "d" }));
|
||||
EXPECT_EQ(test_string_view.split_view("x", true), Vector<StringView>({ "a", "", "b", "c", "d" }));
|
||||
|
||||
test_string_view = "axxbx";
|
||||
EXPECT_EQ(test_string_view.split_view('x'), Vector<StringView>({ "a", "b" }));
|
||||
EXPECT_EQ(test_string_view.split_view('x', true), Vector<StringView>({ "a", "", "b", "" }));
|
||||
EXPECT_EQ(test_string_view.split_view("x"), Vector<StringView>({ "a", "b" }));
|
||||
EXPECT_EQ(test_string_view.split_view("x", true), Vector<StringView>({ "a", "", "b", "" }));
|
||||
|
||||
test_string_view = "axxbcxxdxx";
|
||||
EXPECT_EQ(test_string_view.split_view("xx"), Vector<StringView>({ "a", "bc", "d" }));
|
||||
EXPECT_EQ(test_string_view.split_view("xx", true), Vector<StringView>({ "a", "bc", "d", "" }));
|
||||
}
|
||||
|
||||
TEST_MAIN(StringView)
|
||||
|
|
Loading…
Reference in a new issue