-
Notifications
You must be signed in to change notification settings - Fork 30.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Daniel Lemire <[email protected]>
- Loading branch information
Showing
15 changed files
with
3,308 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
features: | ||
- name: urlpattern | ||
files: "**" |
152 changes: 152 additions & 0 deletions
152
test/fixtures/wpt/urlpattern/resources/urlpattern-compare-test-data.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
[ | ||
{ | ||
"component": "pathname", | ||
"left": { "pathname": "/foo/a" }, | ||
"right": { "pathname": "/foo/b" }, | ||
"expected": -1 | ||
}, | ||
{ | ||
"component": "pathname", | ||
"left": { "pathname": "/foo/b" }, | ||
"right": { "pathname": "/foo/bar" }, | ||
"expected": -1 | ||
}, | ||
{ | ||
"component": "pathname", | ||
"left": { "pathname": "/foo/bar" }, | ||
"right": { "pathname": "/foo/:bar" }, | ||
"expected": 1 | ||
}, | ||
{ | ||
"component": "pathname", | ||
"left": { "pathname": "/foo/" }, | ||
"right": { "pathname": "/foo/:bar" }, | ||
"expected": 1 | ||
}, | ||
{ | ||
"component": "pathname", | ||
"left": { "pathname": "/foo/:bar" }, | ||
"right": { "pathname": "/foo/*" }, | ||
"expected": 1 | ||
}, | ||
{ | ||
"component": "pathname", | ||
"left": { "pathname": "/foo/{bar}" }, | ||
"right": { "pathname": "/foo/(bar)" }, | ||
"expected": 1 | ||
}, | ||
{ | ||
"component": "pathname", | ||
"left": { "pathname": "/foo/{bar}" }, | ||
"right": { "pathname": "/foo/{bar}+" }, | ||
"expected": 1 | ||
}, | ||
{ | ||
"component": "pathname", | ||
"left": { "pathname": "/foo/{bar}+" }, | ||
"right": { "pathname": "/foo/{bar}?" }, | ||
"expected": 1 | ||
}, | ||
{ | ||
"component": "pathname", | ||
"left": { "pathname": "/foo/{bar}?" }, | ||
"right": { "pathname": "/foo/{bar}*" }, | ||
"expected": 1 | ||
}, | ||
{ | ||
"component": "pathname", | ||
"left": { "pathname": "/foo/(123)" }, | ||
"right": { "pathname": "/foo/(12)" }, | ||
"expected": 1 | ||
}, | ||
{ | ||
"component": "pathname", | ||
"left": { "pathname": "/foo/:b" }, | ||
"right": { "pathname": "/foo/:a" }, | ||
"expected": 0 | ||
}, | ||
{ | ||
"component": "pathname", | ||
"left": { "pathname": "*/foo" }, | ||
"right": { "pathname": "*" }, | ||
"expected": 1 | ||
}, | ||
{ | ||
"component": "port", | ||
"left": { "port": "9" }, | ||
"right": { "port": "100" }, | ||
"expected": 1 | ||
}, | ||
{ | ||
"component": "pathname", | ||
"left": { "pathname": "foo/:bar?/baz" }, | ||
"right": { "pathname": "foo/{:bar}?/baz" }, | ||
"expected": -1 | ||
}, | ||
{ | ||
"component": "pathname", | ||
"left": { "pathname": "foo/:bar?/baz" }, | ||
"right": { "pathname": "foo{/:bar}?/baz" }, | ||
"expected": 0 | ||
}, | ||
{ | ||
"component": "pathname", | ||
"left": { "pathname": "foo/:bar?/baz" }, | ||
"right": { "pathname": "fo{o/:bar}?/baz" }, | ||
"expected": 1 | ||
}, | ||
{ | ||
"component": "pathname", | ||
"left": { "pathname": "foo/:bar?/baz" }, | ||
"right": { "pathname": "foo{/:bar/}?baz" }, | ||
"expected": -1 | ||
}, | ||
{ | ||
"component": "pathname", | ||
"left": "https://a.example.com/b?a", | ||
"right": "https://b.example.com/a?b", | ||
"expected": 1 | ||
}, | ||
{ | ||
"component": "pathname", | ||
"left": { "pathname": "/foo/{bar}/baz" }, | ||
"right": { "pathname": "/foo/bar/baz" }, | ||
"expected": 0 | ||
}, | ||
{ | ||
"component": "protocol", | ||
"left": { "protocol": "a" }, | ||
"right": { "protocol": "b" }, | ||
"expected": -1 | ||
}, | ||
{ | ||
"component": "username", | ||
"left": { "username": "a" }, | ||
"right": { "username": "b" }, | ||
"expected": -1 | ||
}, | ||
{ | ||
"component": "password", | ||
"left": { "password": "a" }, | ||
"right": { "password": "b" }, | ||
"expected": -1 | ||
}, | ||
{ | ||
"component": "hostname", | ||
"left": { "hostname": "a" }, | ||
"right": { "hostname": "b" }, | ||
"expected": -1 | ||
}, | ||
{ | ||
"component": "search", | ||
"left": { "search": "a" }, | ||
"right": { "search": "b" }, | ||
"expected": -1 | ||
}, | ||
{ | ||
"component": "hash", | ||
"left": { "hash": "a" }, | ||
"right": { "hash": "b" }, | ||
"expected": -1 | ||
} | ||
] |
26 changes: 26 additions & 0 deletions
26
test/fixtures/wpt/urlpattern/resources/urlpattern-compare-tests.tentative.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
function runTests(data) { | ||
for (let entry of data) { | ||
test(function() { | ||
const left = new URLPattern(entry.left); | ||
const right = new URLPattern(entry.right); | ||
|
||
assert_equals(URLPattern.compareComponent(entry.component, left, right), entry.expected); | ||
|
||
// We have to coerce to an integer here in order to avoid asserting | ||
// that `+0` is `-0`. | ||
const reverse_expected = ~~(entry.expected * -1); | ||
assert_equals(URLPattern.compareComponent(entry.component, right, left), reverse_expected, "reverse order"); | ||
|
||
assert_equals(URLPattern.compareComponent(entry.component, left, left), 0, "left equality"); | ||
assert_equals(URLPattern.compareComponent(entry.component, right, right), 0, "right equality"); | ||
}, `Component: ${entry.component} ` + | ||
`Left: ${JSON.stringify(entry.left)} ` + | ||
`Right: ${JSON.stringify(entry.right)}`); | ||
} | ||
} | ||
|
||
promise_test(async function() { | ||
const response = await fetch('resources/urlpattern-compare-test-data.json'); | ||
const data = await response.json(); | ||
runTests(data); | ||
}, 'Loading data...'); |
18 changes: 18 additions & 0 deletions
18
test/fixtures/wpt/urlpattern/resources/urlpattern-hasregexpgroups-tests.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
test(() => { | ||
assert_implements('hasRegExpGroups' in URLPattern.prototype, "hasRegExpGroups is not implemented"); | ||
assert_false(new URLPattern({}).hasRegExpGroups, "match-everything pattern"); | ||
for (let component of ['protocol', 'username', 'password', 'hostname', 'port', 'pathname', 'search', 'hash']) { | ||
assert_false(new URLPattern({[component]: '*'}).hasRegExpGroups, `wildcard in ${component}`); | ||
assert_false(new URLPattern({[component]: ':foo'}).hasRegExpGroups, `segment wildcard in ${component}`); | ||
assert_false(new URLPattern({[component]: ':foo?'}).hasRegExpGroups, `optional segment wildcard in ${component}`); | ||
assert_true(new URLPattern({[component]: ':foo(hi)'}).hasRegExpGroups, `named regexp group in ${component}`); | ||
assert_true(new URLPattern({[component]: '(hi)'}).hasRegExpGroups, `anonymous regexp group in ${component}`); | ||
if (component !== 'protocol' && component !== 'port') { | ||
// These components are more narrow in what they accept in any case. | ||
assert_false(new URLPattern({[component]: 'a-{:hello}-z-*-a'}).hasRegExpGroups, `wildcards mixed in with fixed text and wildcards in ${component}`); | ||
assert_true(new URLPattern({[component]: 'a-(hi)-z-(lo)-a'}).hasRegExpGroups, `regexp groups mixed in with fixed text and wildcards in ${component}`); | ||
} | ||
} | ||
assert_false(new URLPattern({pathname: '/a/:foo/:baz?/b/*'}).hasRegExpGroups, "complex pathname with no regexp"); | ||
assert_true(new URLPattern({pathname: '/a/:foo/:baz([a-z]+)?/b/*'}).hasRegExpGroups, "complex pathname with regexp"); | ||
}, ''); |
Oops, something went wrong.