mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-02 22:30:31 +00:00
Tests: Add a test for moving an object out of a JSON value
I recently questioned whether this would work as expected: JsonValue value { JsonObject {} }; auto object = move(value.as_object()); So this just adds a unit test to ensure that it does.
This commit is contained in:
parent
2ac16320c9
commit
1e841cd453
Notes:
github-actions[bot]
2025-02-24 17:07:31 +00:00
Author: https://github.com/trflynn89
Commit: 1e841cd453
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3666
Reviewed-by: https://github.com/AtkinsSJ
1 changed files with 24 additions and 0 deletions
|
@ -615,3 +615,27 @@ TEST_CASE(json_value_as_integer)
|
||||||
EXPECT(!very_large_value.is_integer<i32>());
|
EXPECT(!very_large_value.is_integer<i32>());
|
||||||
EXPECT(very_large_value.is_integer<i64>());
|
EXPECT(very_large_value.is_integer<i64>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE(json_object_move_from_value)
|
||||||
|
{
|
||||||
|
JsonArray array;
|
||||||
|
array.must_append(false);
|
||||||
|
array.must_append("string"sv);
|
||||||
|
|
||||||
|
JsonObject object;
|
||||||
|
object.set("foo"sv, "bar"sv);
|
||||||
|
object.set("baz"sv, move(array));
|
||||||
|
|
||||||
|
JsonValue value { move(object) };
|
||||||
|
object = move(value.as_object());
|
||||||
|
|
||||||
|
EXPECT(value.is_object());
|
||||||
|
EXPECT(value.as_object().is_empty());
|
||||||
|
|
||||||
|
EXPECT_EQ(object.size(), 2uz);
|
||||||
|
EXPECT_EQ(object.get_string("foo"sv), "bar"sv);
|
||||||
|
|
||||||
|
auto array2 = object.get_array("baz"sv);
|
||||||
|
EXPECT_EQ(array2->at(0).as_bool(), false);
|
||||||
|
EXPECT_EQ(array2->at(1).as_string(), "string"sv);
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue