Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simplify json logic #802

Merged
merged 3 commits into from
Dec 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading