summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/urlpattern/resources/urlpattern-compare-tests.js
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/urlpattern/resources/urlpattern-compare-tests.js')
-rw-r--r--testing/web-platform/tests/urlpattern/resources/urlpattern-compare-tests.js26
1 files changed, 26 insertions, 0 deletions
diff --git a/testing/web-platform/tests/urlpattern/resources/urlpattern-compare-tests.js b/testing/web-platform/tests/urlpattern/resources/urlpattern-compare-tests.js
new file mode 100644
index 0000000000..b92b53ee45
--- /dev/null
+++ b/testing/web-platform/tests/urlpattern/resources/urlpattern-compare-tests.js
@@ -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...');