Skip to content

test: hand-coded MDN + WHATWG spec example tests#19

Merged
chad-loder merged 3 commits into
mainfrom
test/mdn-and-spec-examples
May 13, 2026
Merged

test: hand-coded MDN + WHATWG spec example tests#19
chad-loder merged 3 commits into
mainfrom
test/mdn-and-spec-examples

Conversation

@chad-loder
Copy link
Copy Markdown
Owner

Summary

  • Adds tests/test_spec_examples.py and tests/test_mdn_examples.py, exercising the canonical examples from the WHATWG URLPattern Standard and MDN.
  • 23 new test cases, all passing against yarlpattern as-is. No production code changes.

Why these tests are separate from the WPT-corpus suite

The WPT corpus exercises 469 conformance cases by construction, but those entries are terse JSON tuples and not human-readable. The examples written into the prose of the spec and the MDN guide deserve a separate, narrated surface so that:

  1. Regressions on the spec's headline examples surface as named failures.
  2. Readers landing in the test tree see, in Python, exactly the patterns and inputs the standard authors used to illustrate the feature.

What's covered

tests/test_spec_examples.py (7 cases)

WHATWG URLPattern Standard §1.2 shop example:

http{s}?://{:subdomain.}?shop.example/products/:id([0-9]+)#reviews
  • 3 positive matches (with and without subdomain, both schemes)
  • 4 negative matches: missing #reviews, explicit port disallowed, search disallowed, non-digit id

tests/test_mdn_examples.py (16 cases)

  • "Using multiple components": kitchen-sink protocol+username+password+hostname+pathname pattern with full-population and zero-optional input matches.
  • "Custom prefix and suffix modifiers": {:subdomain.}*example.com hostname wildcard with named-group expansion across 0–3 labels, plus 3 negative cases (leading dot, wrong eTLD, trailing dot).
  • "Pattern syntax — regex groups": /books/:id(\d+) digit-only constraint with 3 positive cases and 4 negative cases (letters, trailing junk, empty id, signed integers).

Test plan

  • uv run pytest tests/test_spec_examples.py tests/test_mdn_examples.py23 passed
  • uv run pytest -q603 passed, 19 skipped (was 580 before)
  • just lint — all green (ruff, ty, pyright, semgrep, shellcheck, rumdl, codespell, interrogate, validate-pyproject)
  • Signed commit (ED25519)

Part of the v0.2.0 roadmap.

Add two new test files that exercise the canonical examples readers
encounter first when learning URLPattern:

  tests/test_spec_examples.py
    - WHATWG URLPattern Standard §1.2 shop example:
      http{s}?://{:subdomain.}?shop.example/products/:id([0-9]+)#reviews
      3 positive matches + 4 negative matches (missing fragment, port
      disallowed, search disallowed, non-digit id).

  tests/test_mdn_examples.py
    - "Using multiple components": kitchen-sink protocol+username+
      password+hostname+pathname pattern with full and zero-optional
      input matches.
    - "Custom prefix and suffix modifiers": {:subdomain.}*example.com
      hostname wildcard with named-group expansion across 0–3 labels.
    - "Pattern syntax — regex groups": /books/:id(\d+) digit-only
      constraint, plus negative cases for letters, trailing junk,
      empty id, and signed integers.

23 new test cases, all passing against yarlpattern as-is. The WPT
corpus carries the conformance load; these files document the
pedagogical surface so spec / MDN regressions surface as named
failures.

Part of v0.2.0 roadmap.
@chad-loder chad-loder changed the title test: MDN + WHATWG spec example tests test: hand-coded MDN + WHATWG spec example tests May 13, 2026
@chad-loder chad-loder enabled auto-merge (squash) May 13, 2026 03:41
@chad-loder chad-loder merged commit 303e7e7 into main May 13, 2026
13 checks passed
@chad-loder chad-loder deleted the test/mdn-and-spec-examples branch May 13, 2026 03:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant