|
1 | 1 | "use strict";
|
2 | 2 | const assert = require("assert");
|
3 | 3 | const URL = require("..").URL;
|
4 |
| -const testCases = require("./web-platform-tests/urltestdata.json"); |
5 |
| -const additionalTestCases = require("./to-upstream.json"); |
| 4 | +const parsingTestCases = require("./web-platform-tests/urltestdata.json"); |
| 5 | +const additionalParsingTestCases = require("./to-upstream.json"); |
| 6 | +const setterTestData = require("./web-platform-tests/setters_tests.json"); |
6 | 7 |
|
7 | 8 | function testURL(expected) {
|
8 | 9 | return () => {
|
@@ -32,24 +33,49 @@ function testURL(expected) {
|
32 | 33 | };
|
33 | 34 | }
|
34 | 35 |
|
35 |
| -describe("Web Platform Tests", () => { |
36 |
| - for (const expected of testCases) { |
| 36 | +function testSetterCase(testCase, propertyName) { |
| 37 | + return () => { |
| 38 | + const url = new URL(testCase.href); |
| 39 | + url[propertyName] = testCase.new_value; |
| 40 | + |
| 41 | + for (const expectedProperty in testCase.expected) { |
| 42 | + assert.equal(url[expectedProperty], testCase.expected[expectedProperty]); |
| 43 | + } |
| 44 | + }; |
| 45 | +} |
| 46 | + |
| 47 | +describe("Web Platform Tests: parsing", () => { |
| 48 | + for (const expected of parsingTestCases) { |
37 | 49 | if (typeof expected === "string") {
|
38 | 50 | // It's a "comment"; skip it.
|
39 | 51 | continue;
|
40 | 52 | }
|
41 | 53 |
|
42 |
| - it("Parsing: <" + expected.input + "> against <" + expected.base + ">", testURL(expected)); |
| 54 | + specify(`<${expected.input}> against <${expected.base}>`, testURL(expected)); |
| 55 | + } |
| 56 | +}); |
| 57 | + |
| 58 | +describe("Web Platform Tests: setters", () => { |
| 59 | + for (const key of Object.keys(setterTestData)) { |
| 60 | + if (key === "comment") { |
| 61 | + continue; |
| 62 | + } |
| 63 | + |
| 64 | + describe(key, () => { |
| 65 | + for (const testCase of setterTestData[key]) { |
| 66 | + specify(`<${testCase.href}>.${key} = "${testCase.new_value}" ${testCase.comment || ""}`, testSetterCase(testCase, key)); |
| 67 | + } |
| 68 | + }); |
43 | 69 | }
|
44 | 70 | });
|
45 | 71 |
|
46 |
| -describe("To-upstream tests", () => { |
47 |
| - for (const expected of additionalTestCases) { |
| 72 | +describe("To-upstream tests: parsing", () => { |
| 73 | + for (const expected of additionalParsingTestCases) { |
48 | 74 | if (typeof expected === "string") {
|
49 | 75 | // It's a "comment"; skip it.
|
50 | 76 | continue;
|
51 | 77 | }
|
52 | 78 |
|
53 |
| - it("Parsing: <" + expected.input + "> against <" + expected.base + ">", testURL(expected)); |
| 79 | + specify("<" + expected.input + "> against <" + expected.base + ">", testURL(expected)); |
54 | 80 | }
|
55 | 81 | });
|
0 commit comments