@@ -105,12 +105,17 @@ TEST(wpt_urlpattern_tests, has_regexp_groups) {
105
105
SUCCEED ();
106
106
}
107
107
108
- ada::url_pattern_init parse_init (ondemand::object& object) {
108
+ std::variant<ada::url_pattern_init, ada::url_pattern_options> parse_init (
109
+ ondemand::object& object) {
109
110
ada::url_pattern_init init{};
110
111
for (auto field : object) {
111
112
auto key = field.key ().value ();
112
113
std::string_view value;
113
- EXPECT_FALSE (field.value ().get_string (value));
114
+ if (field.value ().get_string (value)) {
115
+ bool value_true;
116
+ EXPECT_FALSE (field.value ().get_bool ().get (value_true));
117
+ return ada::url_pattern_options{.ignore_case = value_true};
118
+ }
114
119
if (key == " protocol" ) {
115
120
init.protocol = std::string (value);
116
121
} else if (key == " username" ) {
@@ -177,8 +182,14 @@ parse_pattern_field(ondemand::array& patterns) {
177
182
} else {
178
183
EXPECT_TRUE (pattern.type () == ondemand::json_type::object);
179
184
ondemand::object object = pattern.get_object ();
180
- // TODO: URLPattern({ ignoreCase: true }) should also work...
181
- init_obj = parse_init (object);
185
+ auto init_result = parse_init (object);
186
+ if (std::holds_alternative<ada::url_pattern_init>(init_result)) {
187
+ init_obj = std::get<ada::url_pattern_init>(init_result);
188
+ } else {
189
+ init_obj = {};
190
+ options = std::get<ada::url_pattern_options>(init_result);
191
+ return std::tuple (*init_obj, base_url, options);
192
+ }
182
193
}
183
194
} else if (pattern_size == 1 ) {
184
195
// The second value can be a base url or an option.
@@ -253,7 +264,8 @@ std::variant<std::string, ada::url_pattern_init> parse_inputs_array(
253
264
254
265
ondemand::object attribute;
255
266
EXPECT_FALSE (input.get_object ().get (attribute));
256
- return parse_init (attribute);
267
+ // We always know that this function is called with url pattern init.
268
+ return std::get<ada::url_pattern_init>(parse_init (attribute));
257
269
}
258
270
259
271
return ada::url_pattern_init{};
@@ -368,15 +380,15 @@ TEST(wpt_urlpattern_tests, urlpattern_test_data) {
368
380
}
369
381
}
370
382
371
- ondemand::array inputs;
372
- if (!main_object[" inputs" ].get_array ().get (inputs)) {
373
- // Expected match can be:
374
- // - "error"
375
- // - null
376
- // - {} // response here.
377
- auto input_value = parse_inputs_array (inputs);
378
- // TODO: Parse "expected_match" field here.
379
- }
383
+ // ondemand::array inputs;
384
+ // if (!main_object["inputs"].get_array().get(inputs)) {
385
+ // // Expected match can be:
386
+ // // - "error"
387
+ // // - null
388
+ // // - {} // response here.
389
+ // auto input_value = parse_inputs_array(inputs);
390
+ // // TODO: Parse "expected_match" field here.
391
+ // }
380
392
}
381
393
} catch (simdjson_error& error) {
382
394
std::cerr << " JSON error: " << error.what () << " near "
0 commit comments