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:
AnotherTest 2020-07-29 03:25:23 +04:30 committed by Andreas Kling
parent dad22c5d5a
commit 681bb1fb23
Notes: sideshowbarker 2024-07-19 04:27:50 +09:00
2 changed files with 37 additions and 13 deletions

View file

@ -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)

View file

@ -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)