Skip to content

Commit

Permalink
Add additional host parsing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebmaster committed Sep 10, 2017
1 parent 2a2d33d commit bc21933
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
3 changes: 1 addition & 2 deletions scripts/get-latest-platform-tests.js
Expand Up @@ -25,8 +25,7 @@ const commitHash = "785ec55ddc2dc2e5dfecac65832d68c82f72e50b";
const urlPrefix = `https://rawgit.com/w3c/web-platform-tests/${commitHash}/url/`;
const targetDir = path.resolve(__dirname, "..", "test", "web-platform-tests");

// TODO: enable toascii.json
for (const file of ["urltestdata.json", "setters_tests.json"]) {
for (const file of ["urltestdata.json", "setters_tests.json", "toascii.json"]) {
request(`${urlPrefix}${file}`)
.pipe(fs.createWriteStream(path.resolve(targetDir, file)));
}
Expand Down
47 changes: 47 additions & 0 deletions test/web-platform.js
Expand Up @@ -9,6 +9,7 @@ const testharness = require("./testharness");
const parsingTestCases = require("./web-platform-tests/urltestdata.json");
const additionalParsingTestCases = require("./to-upstream.json");
const setterTestData = require("./web-platform-tests/setters_tests.json");
const toASCIITestCases = require("./web-platform-tests/toascii.json");

const wptDir = path.join(__dirname, "web-platform-tests");

Expand Down Expand Up @@ -71,6 +72,36 @@ function testSetterCase(testCase, propertyName) {
};
}

function testToASCII(testCase) {
return () => {
if (testCase.output !== null) {
const url = new URL(`https://${testCase.input}/x`);
assert.equal(url.host, testCase.output);
assert.equal(url.hostname, testCase.output);
assert.equal(url.pathname, "/x");
assert.equal(url.href, `https://${testCase.output}/x`);

const url2 = new URL("https://x/x");
url2.hostname = testCase.input;
assert.equal(url2.hostname, testCase.output);

const url3 = new URL("https://x/x");
url3.host = testCase.input;
assert.equal(url3.host, testCase.output);
} else {
assert.throws(() => new URL(`https://${testCase.input}/x`), TypeError);

const url2 = new URL("https://x/x");
url2.hostname = testCase.input;
assert.equal(url2.hostname, "x");

const url3 = new URL("https://x/x");
url3.host = testCase.input;
assert.equal(url3.host, "x");
}
};
}

describe("Web platform tests", () => {
describe("parsing", () => {
for (const expected of parsingTestCases) {
Expand Down Expand Up @@ -109,6 +140,22 @@ describe("Web platform tests", () => {
}
}
});

describe("toASCII", () => {
for (const testCase of toASCIITestCases) {
if (typeof testCase === "string") {
// It's a "comment"; skip it.
continue;
}

let description = testCase.input;
if (testCase.comment) {
description += ` (${testCase.comment})`;
}

specify(description, testToASCII(testCase));
}
});
});

describe("To-upstream tests", () => {
Expand Down

0 comments on commit bc21933

Please sign in to comment.