Skip to content

Commit

Permalink
simplify json logic (#802)
Browse files Browse the repository at this point in the history
* simplifying the json logic

* trimming

* adding comment
  • Loading branch information
lemire authored and anonrig committed Jan 8, 2025
1 parent 6782e86 commit 6832441
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions tests/wpt_urlpattern_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,24 +111,21 @@ TEST(wpt_urlpattern_tests, urlpattern_test_data) {
}

ondemand::object main_object = element.get_object();

for (auto mainfield : main_object) {
auto key = mainfield.key().value();
auto value = mainfield.value();
auto value_type = value.type().value();

if (key == "expected_obj") {
if (value_type == ondemand::json_type::string &&
value.value() == "error") {
ondemand::array patterns;
ASSERT_FALSE(
main_object.find_field_unordered("pattern").get_array().get(
patterns));
auto init = parse_pattern_field(patterns);
std::cout << "patterns: " << patterns.raw_json().value()
<< std::endl;
ASSERT_FALSE(ada::parse_url_pattern(init));
}
// If we have a key with 'expected_obj' and the value is 'error', then
// we expect the pattern to be invalid. There should be a key with
// 'pattern' and the value should be an array.
std::string_view expected_obj;
if (!main_object["expected_obj"].get_string().get(expected_obj) &&
expected_obj == "error") {
ondemand::array patterns;
if (!main_object["pattern"].get_array().get(patterns)) {
auto init = parse_pattern_field(patterns);
std::cout << "patterns: " << patterns.raw_json().value() << std::endl;
ASSERT_FALSE(ada::parse_url_pattern(init));
} else {
std::cerr << "expected_obj does not have an array in pattern"
<< std::endl;
FAIL();
}
}
}
Expand Down

0 comments on commit 6832441

Please sign in to comment.