mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
6c213978b7
- Split the tests out to a separate file - Add invalid cases - Add tests for url.domainTo*() - Re-enable previously broken WPT URL parsing tests PR-URL: https://github.com/nodejs/node/pull/11549 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
42 lines
1.2 KiB
JavaScript
42 lines
1.2 KiB
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
|
|
if (!common.hasIntl) {
|
|
common.skip('missing Intl');
|
|
return;
|
|
}
|
|
|
|
const icu = process.binding('icu');
|
|
const assert = require('assert');
|
|
|
|
const tests = require('../fixtures/url-idna.js');
|
|
|
|
{
|
|
for (const [i, { ascii, unicode }] of tests.valid.entries()) {
|
|
assert.strictEqual(ascii, icu.toASCII(unicode), `toASCII(${i + 1})`);
|
|
assert.strictEqual(unicode, icu.toUnicode(ascii), `toUnicode(${i + 1})`);
|
|
assert.strictEqual(ascii, icu.toASCII(icu.toUnicode(ascii)),
|
|
`toASCII(toUnicode(${i + 1}))`);
|
|
assert.strictEqual(unicode, icu.toUnicode(icu.toASCII(unicode)),
|
|
`toUnicode(toASCII(${i + 1}))`);
|
|
}
|
|
}
|
|
|
|
{
|
|
const errorRe = {
|
|
ascii: /^Error: Cannot convert name to ASCII$/,
|
|
unicode: /^Error: Cannot convert name to Unicode$/
|
|
};
|
|
const convertFunc = {
|
|
ascii: icu.toASCII,
|
|
unicode: icu.toUnicode
|
|
};
|
|
|
|
for (const [i, { url, mode }] of tests.invalid.entries()) {
|
|
assert.throws(() => convertFunc[mode](url), errorRe[mode],
|
|
`Invalid case ${i + 1}`);
|
|
assert.doesNotThrow(() => convertFunc[mode](url, true),
|
|
`Invalid case ${i + 1} in lenient mode`);
|
|
}
|
|
}
|