diff options
author | Joyee Cheung <joyeec9h3@gmail.com> | 2018-08-22 03:27:56 +0800 |
---|---|---|
committer | Joyee Cheung <joyeec9h3@gmail.com> | 2018-08-25 08:57:23 +0800 |
commit | 6dd694c1257ded6d8a9f3b48e8c9027c3986a285 (patch) | |
tree | 4c37b2936495c352676be7caaff33c9cb89c7ab8 /test/parallel/test-whatwg-url-custom-domainto.js | |
parent | 16cffb0d4890bf4b4ff8ad0bbd7731105fabe845 (diff) | |
download | android-node-v8-6dd694c1257ded6d8a9f3b48e8c9027c3986a285.tar.gz android-node-v8-6dd694c1257ded6d8a9f3b48e8c9027c3986a285.tar.bz2 android-node-v8-6dd694c1257ded6d8a9f3b48e8c9027c3986a285.zip |
test: move custom WHATWG URL tests into separate files
To enable automatic update of WPT, move all our custom
WHATWG URL tests that are not present in the upstream into
files starting with `test-whatwg-url-custom-`, so it's easier
to identify test cases that can be upstreamed and test cases
that should be rolled into our repo (possibly with automation).
PR-URL: https://github.com/nodejs/node/pull/22442
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
Diffstat (limited to 'test/parallel/test-whatwg-url-custom-domainto.js')
-rw-r--r-- | test/parallel/test-whatwg-url-custom-domainto.js | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/test/parallel/test-whatwg-url-custom-domainto.js b/test/parallel/test-whatwg-url-custom-domainto.js new file mode 100644 index 0000000000..556a3ff841 --- /dev/null +++ b/test/parallel/test-whatwg-url-custom-domainto.js @@ -0,0 +1,55 @@ +'use strict'; + +// Tests below are not from WPT. + +const common = require('../common'); + +if (!common.hasIntl) + common.skip('missing Intl'); + +const assert = require('assert'); +const { domainToASCII, domainToUnicode } = require('url'); + +const tests = require('../fixtures/url-idna'); +const wptToASCIITests = require('../fixtures/url-toascii'); + +{ + const expectedError = common.expectsError( + { code: 'ERR_MISSING_ARGS', type: TypeError }, 2); + 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); + } + } +} |