mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 02:07:36 +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:
parent
daf6d8173c
commit
aeee98b3a1
189 changed files with 597 additions and 652 deletions
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ static constexpr char PATH_LOREM_250[] = "This-is-an-annoyingly-long-name-that-s
|
|||
|
||||
static constexpr size_t ITERATION_DEPTH = 17;
|
||||
|
||||
static void check_result(char const* what, DeprecatedString const& expected, char const* actual)
|
||||
static void check_result(char const* what, StringView expected, char const* actual)
|
||||
{
|
||||
if (expected != actual)
|
||||
FAIL(DeprecatedString::formatted("Expected {} to be \"{}\" ({} characters)", what, actual, actual ? strlen(actual) : 0));
|
||||
|
|
|
@ -337,7 +337,7 @@ static Result<TestMetadata, DeprecatedString> extract_metadata(StringView source
|
|||
failed_message = "Failed to find phase in negative attributes";
|
||||
break;
|
||||
}
|
||||
if (metadata.type.is_null()) {
|
||||
if (metadata.type.is_empty()) {
|
||||
failed_message = "Failed to find type in negative attributes";
|
||||
break;
|
||||
}
|
||||
|
@ -640,7 +640,7 @@ int main(int argc, char** argv)
|
|||
auto collect_output = [&] {
|
||||
fflush(stdout);
|
||||
auto nread = read(stdout_pipe[0], buffer, BUFFER_SIZE);
|
||||
DeprecatedString value;
|
||||
Optional<DeprecatedString> value;
|
||||
|
||||
if (nread > 0) {
|
||||
value = DeprecatedString { buffer, static_cast<size_t>(nread) };
|
||||
|
@ -743,15 +743,16 @@ int main(int argc, char** argv)
|
|||
auto result = run_test(original_contents, path, metadata);
|
||||
DISARM_TIMER();
|
||||
|
||||
DeprecatedString first_output = collect_output();
|
||||
if (!first_output.is_null())
|
||||
result_object.set("output", first_output);
|
||||
auto first_output = collect_output();
|
||||
if (first_output.has_value())
|
||||
result_object.set("output", *first_output);
|
||||
|
||||
passed = verify_test(result, metadata, result_object);
|
||||
auto output = first_output.value_or("");
|
||||
if (metadata.is_async && !s_parse_only) {
|
||||
if (!first_output.contains("Test262:AsyncTestComplete"sv) || first_output.contains("Test262:AsyncTestFailure"sv)) {
|
||||
if (!output.contains("Test262:AsyncTestComplete"sv) || output.contains("Test262:AsyncTestFailure"sv)) {
|
||||
result_object.set("async_fail", true);
|
||||
if (first_output.is_null())
|
||||
if (!first_output.has_value())
|
||||
result_object.set("output", JsonValue { AK::JsonValue::Type::Null });
|
||||
|
||||
passed = false;
|
||||
|
@ -766,15 +767,17 @@ int main(int argc, char** argv)
|
|||
auto result = run_test(with_strict, path, metadata);
|
||||
DISARM_TIMER();
|
||||
|
||||
DeprecatedString first_output = collect_output();
|
||||
if (!first_output.is_null())
|
||||
result_object.set("strict_output", first_output);
|
||||
auto first_output = collect_output();
|
||||
if (first_output.has_value())
|
||||
result_object.set("strict_output", *first_output);
|
||||
|
||||
passed = verify_test(result, metadata, result_object);
|
||||
auto output = first_output.value_or("");
|
||||
|
||||
if (metadata.is_async && !s_parse_only) {
|
||||
if (!first_output.contains("Test262:AsyncTestComplete"sv) || first_output.contains("Test262:AsyncTestFailure"sv)) {
|
||||
if (!output.contains("Test262:AsyncTestComplete"sv) || output.contains("Test262:AsyncTestFailure"sv)) {
|
||||
result_object.set("async_fail", true);
|
||||
if (first_output.is_null())
|
||||
if (!first_output.has_value())
|
||||
result_object.set("output", JsonValue { AK::JsonValue::Type::Null });
|
||||
|
||||
passed = false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue