1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 21:47:45 +00:00

AK+Everywhere: Remove the null state of DeprecatedString

This commit removes DeprecatedString's "null" state, and replaces all
its users with one of the following:
- A normal, empty DeprecatedString
- Optional<DeprecatedString>

Note that null states of DeprecatedFlyString/StringView/etc are *not*
affected by this commit. However, DeprecatedString::empty() is now
considered equal to a null StringView.
This commit is contained in:
Ali Mohammad Pur 2023-10-10 15:00:58 +03:30 committed by Ali Mohammad Pur
parent daf6d8173c
commit aeee98b3a1
189 changed files with 597 additions and 652 deletions

View file

@ -41,7 +41,7 @@ TEST_CASE(enqueue_begin_being_moved_from)
DeprecatedString str { "test" };
strings.enqueue_begin(move(str));
EXPECT(str.is_null());
EXPECT(str.is_empty());
}
TEST_CASE(deque_end)

View file

@ -14,11 +14,9 @@
TEST_CASE(construct_empty)
{
EXPECT(DeprecatedString().is_null());
EXPECT(DeprecatedString().is_empty());
EXPECT(!DeprecatedString().characters());
EXPECT(DeprecatedString().characters() != nullptr);
EXPECT(!DeprecatedString("").is_null());
EXPECT(DeprecatedString("").is_empty());
EXPECT(DeprecatedString("").characters() != nullptr);
@ -29,7 +27,6 @@ TEST_CASE(construct_contents)
{
DeprecatedString test_string = "ABCDEF";
EXPECT(!test_string.is_empty());
EXPECT(!test_string.is_null());
EXPECT_EQ(test_string.length(), 6u);
EXPECT_EQ(test_string.length(), strlen(test_string.characters()));
EXPECT(test_string.characters() != nullptr);
@ -42,7 +39,7 @@ TEST_CASE(construct_contents)
TEST_CASE(equal)
{
EXPECT_NE(DeprecatedString::empty(), DeprecatedString {});
EXPECT_EQ(DeprecatedString::empty(), DeprecatedString {});
}
TEST_CASE(compare)
@ -116,7 +113,7 @@ TEST_CASE(move_string)
auto test_string_copy = test_string;
auto test_string_move = move(test_string_copy);
EXPECT_EQ(test_string, test_string_move);
EXPECT(test_string_copy.is_null());
EXPECT(test_string_copy.is_empty());
}
TEST_CASE(repeated)
@ -253,7 +250,6 @@ TEST_CASE(builder_zero_initial_capacity)
StringBuilder builder(0);
builder.append(""sv);
auto built = builder.to_deprecated_string();
EXPECT_EQ(built.is_null(), false);
EXPECT_EQ(built.length(), 0u);
}

View file

@ -49,7 +49,7 @@ TEST_CASE(range_loop)
int loop_counter = 0;
for (auto& it : number_to_string) {
EXPECT_EQ(it.value.is_null(), false);
EXPECT_EQ(it.value.is_empty(), false);
++loop_counter;
}
EXPECT_EQ(loop_counter, 3);

View file

@ -64,7 +64,7 @@ TEST_CASE(range_loop)
int loop_counter = 0;
for (auto& it : strings) {
EXPECT_EQ(it.is_null(), false);
EXPECT_EQ(it.is_empty(), false);
++loop_counter;
}
EXPECT_EQ(loop_counter, 3);

View file

@ -60,7 +60,6 @@ TEST_CASE(json_empty_string)
{
auto json = JsonValue::from_string("\"\""sv).value();
EXPECT_EQ(json.type(), JsonValue::Type::String);
EXPECT_EQ(json.as_string().is_null(), false);
EXPECT_EQ(json.as_string().is_empty(), true);
}
@ -68,7 +67,6 @@ TEST_CASE(json_string)
{
auto json = JsonValue::from_string("\"A\""sv).value();
EXPECT_EQ(json.type(), JsonValue::Type::String);
EXPECT_EQ(json.as_string().is_null(), false);
EXPECT_EQ(json.as_string().length(), size_t { 1 });
EXPECT_EQ(json.as_string() == "A", true);
}
@ -77,7 +75,6 @@ TEST_CASE(json_utf8_character)
{
auto json = JsonValue::from_string("\"\\u0041\""sv).value();
EXPECT_EQ(json.type(), JsonValue::Type::String);
EXPECT_EQ(json.as_string().is_null(), false);
EXPECT_EQ(json.as_string().length(), size_t { 1 });
EXPECT_EQ(json.as_string() == "A", true);
}
@ -92,7 +89,6 @@ TEST_CASE(json_utf8_multibyte)
auto& json = json_or_error.value();
EXPECT_EQ(json.type(), JsonValue::Type::String);
EXPECT_EQ(json.as_string().is_null(), false);
EXPECT_EQ(json.as_string().length(), size_t { 2 });
EXPECT_EQ(json.as_string() == "š", true);
EXPECT_EQ(json.as_string() == "\xc5\xa1", true);

View file

@ -44,14 +44,12 @@ TEST_CASE(strings)
int loop_counter = 0;
for (DeprecatedString const& string : strings) {
EXPECT(!string.is_null());
EXPECT(!string.is_empty());
++loop_counter;
}
loop_counter = 0;
for (auto& string : (const_cast<Vector<DeprecatedString> const&>(strings))) {
EXPECT(!string.is_null());
EXPECT(!string.is_empty());
++loop_counter;
}