Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b8b6e68

Browse filesBrowse files
anonriglemire
authored andcommitted
test: add WPT for URLPattern
Co-authored-by: Daniel Lemire <daniel@lemire.me> PR-URL: #56452 Reviewed-By: Daniel Lemire <daniel@lemire.me> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Jordan Harband <ljharb@gmail.com> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
1 parent bc97a90 commit b8b6e68
Copy full SHA for b8b6e68
Expand file treeCollapse file tree

15 files changed

+3308
-0
lines changed
Open diff view settings
Collapse file

‎test/fixtures/wpt/README.md‎

Copy file name to clipboardExpand all lines: test/fixtures/wpt/README.md
+1Lines changed: 1 addition & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Last update:
2929
- resources: https://github.com/web-platform-tests/wpt/tree/1e140d63ec/resources
3030
- streams: https://github.com/web-platform-tests/wpt/tree/bc9dcbbf1a/streams
3131
- url: https://github.com/web-platform-tests/wpt/tree/a23788b77a/url
32+
- urlpattern: https://github.com/web-platform-tests/wpt/tree/1b56d89a26/urlpattern
3233
- user-timing: https://github.com/web-platform-tests/wpt/tree/5ae85bf826/user-timing
3334
- wasm/jsapi: https://github.com/web-platform-tests/wpt/tree/cde25e7e3c/wasm/jsapi
3435
- wasm/webapi: https://github.com/web-platform-tests/wpt/tree/fd1b23eeaa/wasm/webapi
Collapse file
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
features:
2+
- name: urlpattern
3+
files: "**"
Collapse file
+152Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
[
2+
{
3+
"component": "pathname",
4+
"left": { "pathname": "/foo/a" },
5+
"right": { "pathname": "/foo/b" },
6+
"expected": -1
7+
},
8+
{
9+
"component": "pathname",
10+
"left": { "pathname": "/foo/b" },
11+
"right": { "pathname": "/foo/bar" },
12+
"expected": -1
13+
},
14+
{
15+
"component": "pathname",
16+
"left": { "pathname": "/foo/bar" },
17+
"right": { "pathname": "/foo/:bar" },
18+
"expected": 1
19+
},
20+
{
21+
"component": "pathname",
22+
"left": { "pathname": "/foo/" },
23+
"right": { "pathname": "/foo/:bar" },
24+
"expected": 1
25+
},
26+
{
27+
"component": "pathname",
28+
"left": { "pathname": "/foo/:bar" },
29+
"right": { "pathname": "/foo/*" },
30+
"expected": 1
31+
},
32+
{
33+
"component": "pathname",
34+
"left": { "pathname": "/foo/{bar}" },
35+
"right": { "pathname": "/foo/(bar)" },
36+
"expected": 1
37+
},
38+
{
39+
"component": "pathname",
40+
"left": { "pathname": "/foo/{bar}" },
41+
"right": { "pathname": "/foo/{bar}+" },
42+
"expected": 1
43+
},
44+
{
45+
"component": "pathname",
46+
"left": { "pathname": "/foo/{bar}+" },
47+
"right": { "pathname": "/foo/{bar}?" },
48+
"expected": 1
49+
},
50+
{
51+
"component": "pathname",
52+
"left": { "pathname": "/foo/{bar}?" },
53+
"right": { "pathname": "/foo/{bar}*" },
54+
"expected": 1
55+
},
56+
{
57+
"component": "pathname",
58+
"left": { "pathname": "/foo/(123)" },
59+
"right": { "pathname": "/foo/(12)" },
60+
"expected": 1
61+
},
62+
{
63+
"component": "pathname",
64+
"left": { "pathname": "/foo/:b" },
65+
"right": { "pathname": "/foo/:a" },
66+
"expected": 0
67+
},
68+
{
69+
"component": "pathname",
70+
"left": { "pathname": "*/foo" },
71+
"right": { "pathname": "*" },
72+
"expected": 1
73+
},
74+
{
75+
"component": "port",
76+
"left": { "port": "9" },
77+
"right": { "port": "100" },
78+
"expected": 1
79+
},
80+
{
81+
"component": "pathname",
82+
"left": { "pathname": "foo/:bar?/baz" },
83+
"right": { "pathname": "foo/{:bar}?/baz" },
84+
"expected": -1
85+
},
86+
{
87+
"component": "pathname",
88+
"left": { "pathname": "foo/:bar?/baz" },
89+
"right": { "pathname": "foo{/:bar}?/baz" },
90+
"expected": 0
91+
},
92+
{
93+
"component": "pathname",
94+
"left": { "pathname": "foo/:bar?/baz" },
95+
"right": { "pathname": "fo{o/:bar}?/baz" },
96+
"expected": 1
97+
},
98+
{
99+
"component": "pathname",
100+
"left": { "pathname": "foo/:bar?/baz" },
101+
"right": { "pathname": "foo{/:bar/}?baz" },
102+
"expected": -1
103+
},
104+
{
105+
"component": "pathname",
106+
"left": "https://a.example.com/b?a",
107+
"right": "https://b.example.com/a?b",
108+
"expected": 1
109+
},
110+
{
111+
"component": "pathname",
112+
"left": { "pathname": "/foo/{bar}/baz" },
113+
"right": { "pathname": "/foo/bar/baz" },
114+
"expected": 0
115+
},
116+
{
117+
"component": "protocol",
118+
"left": { "protocol": "a" },
119+
"right": { "protocol": "b" },
120+
"expected": -1
121+
},
122+
{
123+
"component": "username",
124+
"left": { "username": "a" },
125+
"right": { "username": "b" },
126+
"expected": -1
127+
},
128+
{
129+
"component": "password",
130+
"left": { "password": "a" },
131+
"right": { "password": "b" },
132+
"expected": -1
133+
},
134+
{
135+
"component": "hostname",
136+
"left": { "hostname": "a" },
137+
"right": { "hostname": "b" },
138+
"expected": -1
139+
},
140+
{
141+
"component": "search",
142+
"left": { "search": "a" },
143+
"right": { "search": "b" },
144+
"expected": -1
145+
},
146+
{
147+
"component": "hash",
148+
"left": { "hash": "a" },
149+
"right": { "hash": "b" },
150+
"expected": -1
151+
}
152+
]
Collapse file
+26Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
function runTests(data) {
2+
for (let entry of data) {
3+
test(function() {
4+
const left = new URLPattern(entry.left);
5+
const right = new URLPattern(entry.right);
6+
7+
assert_equals(URLPattern.compareComponent(entry.component, left, right), entry.expected);
8+
9+
// We have to coerce to an integer here in order to avoid asserting
10+
// that `+0` is `-0`.
11+
const reverse_expected = ~~(entry.expected * -1);
12+
assert_equals(URLPattern.compareComponent(entry.component, right, left), reverse_expected, "reverse order");
13+
14+
assert_equals(URLPattern.compareComponent(entry.component, left, left), 0, "left equality");
15+
assert_equals(URLPattern.compareComponent(entry.component, right, right), 0, "right equality");
16+
}, `Component: ${entry.component} ` +
17+
`Left: ${JSON.stringify(entry.left)} ` +
18+
`Right: ${JSON.stringify(entry.right)}`);
19+
}
20+
}
21+
22+
promise_test(async function() {
23+
const response = await fetch('resources/urlpattern-compare-test-data.json');
24+
const data = await response.json();
25+
runTests(data);
26+
}, 'Loading data...');
Collapse file
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
test(() => {
2+
assert_implements('hasRegExpGroups' in URLPattern.prototype, "hasRegExpGroups is not implemented");
3+
assert_false(new URLPattern({}).hasRegExpGroups, "match-everything pattern");
4+
for (let component of ['protocol', 'username', 'password', 'hostname', 'port', 'pathname', 'search', 'hash']) {
5+
assert_false(new URLPattern({[component]: '*'}).hasRegExpGroups, `wildcard in ${component}`);
6+
assert_false(new URLPattern({[component]: ':foo'}).hasRegExpGroups, `segment wildcard in ${component}`);
7+
assert_false(new URLPattern({[component]: ':foo?'}).hasRegExpGroups, `optional segment wildcard in ${component}`);
8+
assert_true(new URLPattern({[component]: ':foo(hi)'}).hasRegExpGroups, `named regexp group in ${component}`);
9+
assert_true(new URLPattern({[component]: '(hi)'}).hasRegExpGroups, `anonymous regexp group in ${component}`);
10+
if (component !== 'protocol' && component !== 'port') {
11+
// These components are more narrow in what they accept in any case.
12+
assert_false(new URLPattern({[component]: 'a-{:hello}-z-*-a'}).hasRegExpGroups, `wildcards mixed in with fixed text and wildcards in ${component}`);
13+
assert_true(new URLPattern({[component]: 'a-(hi)-z-(lo)-a'}).hasRegExpGroups, `regexp groups mixed in with fixed text and wildcards in ${component}`);
14+
}
15+
}
16+
assert_false(new URLPattern({pathname: '/a/:foo/:baz?/b/*'}).hasRegExpGroups, "complex pathname with no regexp");
17+
assert_true(new URLPattern({pathname: '/a/:foo/:baz([a-z]+)?/b/*'}).hasRegExpGroups, "complex pathname with regexp");
18+
}, '');

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.