summaryrefslogtreecommitdiff
path: root/test/parallel/test-icu-punycode.js
blob: ba2014bdc85a2f1f77a858dcbca72e9107a06f89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
'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}))`);
  }
}

{
  for (const [i, url] of tests.invalid.entries()) {
    assert.throws(() => icu.toASCII(url),
                  /^Error: Cannot convert name to ASCII$/,
                  `ToASCII invalid case ${i + 1}`);
    assert.doesNotThrow(() => icu.toASCII(url, true),
                        `ToASCII invalid case ${i + 1} in lenient mode`);
    assert.doesNotThrow(() => icu.toUnicode(url),
                        `ToUnicode invalid case ${i + 1}`);
  }
}