From 9925fcdb648463012e70af07b18334c7ba4482d5 Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Thu, 21 Mar 2024 13:03:42 +0100 Subject: [PATCH] URL: tests for URL.parse() As per https://github.com/whatwg/url/issues/372. --- url/url-statics-parse.any.js | 50 ++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 url/url-statics-parse.any.js diff --git a/url/url-statics-parse.any.js b/url/url-statics-parse.any.js new file mode 100644 index 00000000000000..5b3bed2f9a36b2 --- /dev/null +++ b/url/url-statics-parse.any.js @@ -0,0 +1,50 @@ +// This intentionally does not use resources/urltestdata.json to preserve resources. +[ + { + "url": undefined, + "base": undefined, + "expected": false + }, + { + "url": "aaa:b", + "base": undefined, + "expected": true + }, + { + "url": undefined, + "base": "aaa:b", + "expected": false + }, + { + "url": "aaa:/b", + "base": undefined, + "expected": true + }, + { + "url": undefined, + "base": "aaa:/b", + "expected": true + }, + { + "url": "https://test:test", + "base": undefined, + "expected": false + }, + { + "url": "a", + "base": "https://b/", + "expected": true + } +].forEach(({ url, base, expected }) => { + test(() => { + if (expected == false) { + assert_equals(URL.parse(url, base), null); + } else { + assert_equals(URL.parse(url, base).href = new URL(url, base).href); + } + }, `URL.parse(${url}, ${base})`); +}); + +test(() => { + assert_not_equals(URL.parse("https://example/"), URL.parse("https://example/")); +}, `URL.parse() should return a unique object`);