0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-whatwg-url-domainto.js
Timothy Gu 91a1bbe305
url: update IDNA handling
Remove custom tests for invalid IDNA domains in url-idna.js in favor of
the more comprehensive official set.

PR-URL: https://github.com/nodejs/node/pull/13362
Refs: https://github.com/whatwg/url/pull/309
Refs: https://github.com/w3c/web-platform-tests/pull/5976
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
2017-06-06 23:33:56 -07:00

56 lines
1.9 KiB
JavaScript

'use strict';
const common = require('../common');
if (!common.hasIntl) {
common.skip('missing Intl');
return;
}
const assert = require('assert');
const { domainToASCII, domainToUnicode } = require('url');
// Tests below are not from WPT.
const tests = require('../fixtures/url-idna.js');
const wptToASCIITests = require('../fixtures/url-toascii.js');
{
const expectedError = common.expectsError(
{ code: 'ERR_MISSING_ARGS', type: TypeError });
assert.throws(() => domainToASCII(), expectedError);
assert.throws(() => domainToUnicode(), expectedError);
assert.strictEqual(domainToASCII(undefined), 'undefined');
assert.strictEqual(domainToUnicode(undefined), 'undefined');
}
{
for (const [i, { ascii, unicode }] of tests.entries()) {
assert.strictEqual(ascii, domainToASCII(unicode),
`domainToASCII(${i + 1})`);
assert.strictEqual(unicode, domainToUnicode(ascii),
`domainToUnicode(${i + 1})`);
assert.strictEqual(ascii, domainToASCII(domainToUnicode(ascii)),
`domainToASCII(domainToUnicode(${i + 1}))`);
assert.strictEqual(unicode, domainToUnicode(domainToASCII(unicode)),
`domainToUnicode(domainToASCII(${i + 1}))`);
}
}
{
for (const [i, test] of wptToASCIITests.entries()) {
if (typeof test === 'string')
continue; // skip comments
const { comment, input, output } = test;
let caseComment = `Case ${i + 1}`;
if (comment)
caseComment += ` (${comment})`;
if (output === null) {
assert.strictEqual(domainToASCII(input), '', caseComment);
assert.strictEqual(domainToUnicode(input), '', caseComment);
} else {
assert.strictEqual(domainToASCII(input), output, caseComment);
const roundtripped = domainToASCII(domainToUnicode(input));
assert.strictEqual(roundtripped, output, caseComment);
}
}
}