Skip to content

Commit

Permalink
simplify parser and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig committed Jan 1, 2025
1 parent 821a65a commit 4386553
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 14 deletions.
10 changes: 2 additions & 8 deletions include/ada/url_pattern_helpers-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -488,18 +488,12 @@ std::string url_pattern_parser<F>::consume_text() {
}

template <url_pattern_encoding_callback F>
tl::expected<Token, url_pattern_errors>
url_pattern_parser<F>::consume_required_token(token_type type) {
bool url_pattern_parser<F>::consume_required_token(token_type type) {
ada_log("url_pattern_parser::consume_required_token called with type=",
to_string(type));
// Let result be the result of running try to consume a token given parser and
// type.
auto result = try_consume_token(type);
// If result is null, then throw a TypeError.
if (!result) {
return tl::unexpected(url_pattern_errors::type_error);
}
return *result;
return try_consume_token(type) != nullptr;
}

template <url_pattern_encoding_callback F>
Expand Down
3 changes: 1 addition & 2 deletions include/ada/url_pattern_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ class url_pattern_parser {
// @see https://urlpattern.spec.whatwg.org/#consume-text
std::string consume_text();
// @see https://urlpattern.spec.whatwg.org/#consume-a-required-token
tl::expected<Token, url_pattern_errors> consume_required_token(
token_type type);
bool consume_required_token(token_type type);
// @see
// https://urlpattern.spec.whatwg.org/#maybe-add-a-part-from-the-pending-fixed-value
std::optional<url_pattern_errors>
Expand Down
6 changes: 2 additions & 4 deletions tests/wpt_urlpattern_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ constexpr std::string_view URL_PATTERN_TEST_DATA =
"wpt/urlpatterntestdata.json";

TEST(wpt_urlpattern_tests, parser_tokenize_basic_tests) {
auto parser = ada::url_pattern_helpers::url_pattern_parser(
ada::url_pattern_helpers::canonicalize_protocol, ada::url_pattern_helpers::generate_segment_wildcard_regexp(ada::url_pattern_compile_component_options::DEFAULT));

auto tokenize_result = ada::url_pattern_helpers::tokenize("*", ada::url_pattern_helpers::token_policy::STRICT);
auto tokenize_result =
tokenize("*", ada::url_pattern_helpers::token_policy::STRICT);
ASSERT_TRUE(tokenize_result);
}

Expand Down

0 comments on commit 4386553

Please sign in to comment.