mirror of
https://github.com/nodejs/node.git
synced 2025-05-19 20:06:58 +00:00

To enable automatic update of WPT, move all our custom WHATWG URL tests that are not present in the upstream into files starting with `test-whatwg-url-custom-`, so it's easier to identify test cases that can be upstreamed and test cases that should be rolled into our repo (possibly with automation). PR-URL: https://github.com/nodejs/node/pull/22442 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
64 lines
1.9 KiB
JavaScript
64 lines
1.9 KiB
JavaScript
'use strict';
|
|
|
|
require('../common');
|
|
const { URL, URLSearchParams } = require('url');
|
|
const { test, assert_equals, assert_array_equals } = require('../common/wpt');
|
|
|
|
/* The following tests are copied from WPT. Modifications to them should be
|
|
upstreamed first. Refs:
|
|
https://github.com/w3c/web-platform-tests/blob/70a0898763/url/urlsearchparams-sort.html
|
|
License: http://www.w3.org/Consortium/Legal/2008/04-testsuite-copyright.html
|
|
*/
|
|
/* eslint-disable */
|
|
[
|
|
{
|
|
"input": "z=b&a=b&z=a&a=a",
|
|
"output": [["a", "b"], ["a", "a"], ["z", "b"], ["z", "a"]]
|
|
},
|
|
{
|
|
"input": "\uFFFD=x&\uFFFC&\uFFFD=a",
|
|
"output": [["\uFFFC", ""], ["\uFFFD", "x"], ["\uFFFD", "a"]]
|
|
},
|
|
{
|
|
"input": "ffi&🌈", // 🌈 > code point, but < code unit because two code units
|
|
"output": [["🌈", ""], ["ffi", ""]]
|
|
},
|
|
{
|
|
"input": "é&e\uFFFD&e\u0301",
|
|
"output": [["e\u0301", ""], ["e\uFFFD", ""], ["é", ""]]
|
|
},
|
|
{
|
|
"input": "z=z&a=a&z=y&a=b&z=x&a=c&z=w&a=d&z=v&a=e&z=u&a=f&z=t&a=g",
|
|
"output": [["a", "a"], ["a", "b"], ["a", "c"], ["a", "d"], ["a", "e"], ["a", "f"], ["a", "g"], ["z", "z"], ["z", "y"], ["z", "x"], ["z", "w"], ["z", "v"], ["z", "u"], ["z", "t"]]
|
|
}
|
|
].forEach((val) => {
|
|
test(() => {
|
|
let params = new URLSearchParams(val.input),
|
|
i = 0
|
|
params.sort()
|
|
for(let param of params) {
|
|
assert_array_equals(param, val.output[i])
|
|
i++
|
|
}
|
|
}, `Parse and sort: ${val.input}`)
|
|
|
|
test(() => {
|
|
let url = new URL(`?${val.input}`, "https://example/")
|
|
url.searchParams.sort()
|
|
let params = new URLSearchParams(url.search),
|
|
i = 0
|
|
for(let param of params) {
|
|
assert_array_equals(param, val.output[i])
|
|
i++
|
|
}
|
|
}, `URL parse and sort: ${val.input}`)
|
|
})
|
|
|
|
test(function() {
|
|
const url = new URL("http://example.com/?")
|
|
url.searchParams.sort()
|
|
assert_equals(url.href, "http://example.com/")
|
|
assert_equals(url.search, "")
|
|
}, "Sorting non-existent params removes ? from URL")
|
|
/* eslint-enable */
|