11cb0ef41Sopenharmony_ci// Flags: --pending-deprecation 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ci// Copyright Joyent, Inc. and other Node contributors. 41cb0ef41Sopenharmony_ci// 51cb0ef41Sopenharmony_ci// Permission is hereby granted, free of charge, to any person obtaining a 61cb0ef41Sopenharmony_ci// copy of this software and associated documentation files (the 71cb0ef41Sopenharmony_ci// "Software"), to deal in the Software without restriction, including 81cb0ef41Sopenharmony_ci// without limitation the rights to use, copy, modify, merge, publish, 91cb0ef41Sopenharmony_ci// distribute, sublicense, and/or sell copies of the Software, and to permit 101cb0ef41Sopenharmony_ci// persons to whom the Software is furnished to do so, subject to the 111cb0ef41Sopenharmony_ci// following conditions: 121cb0ef41Sopenharmony_ci// 131cb0ef41Sopenharmony_ci// The above copyright notice and this permission notice shall be included 141cb0ef41Sopenharmony_ci// in all copies or substantial portions of the Software. 151cb0ef41Sopenharmony_ci// 161cb0ef41Sopenharmony_ci// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 171cb0ef41Sopenharmony_ci// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 181cb0ef41Sopenharmony_ci// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 191cb0ef41Sopenharmony_ci// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 201cb0ef41Sopenharmony_ci// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 211cb0ef41Sopenharmony_ci// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 221cb0ef41Sopenharmony_ci// USE OR OTHER DEALINGS IN THE SOFTWARE. 231cb0ef41Sopenharmony_ci 241cb0ef41Sopenharmony_ci'use strict'; 251cb0ef41Sopenharmony_ciconst common = require('../common'); 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ciconst punycodeWarning = 281cb0ef41Sopenharmony_ci 'The `punycode` module is deprecated. Please use a userland alternative ' + 291cb0ef41Sopenharmony_ci 'instead.'; 301cb0ef41Sopenharmony_cicommon.expectWarning('DeprecationWarning', punycodeWarning, 'DEP0040'); 311cb0ef41Sopenharmony_ci 321cb0ef41Sopenharmony_ciconst punycode = require('punycode'); 331cb0ef41Sopenharmony_ciconst assert = require('assert'); 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_ciassert.strictEqual(punycode.encode('ü'), 'tda'); 361cb0ef41Sopenharmony_ciassert.strictEqual(punycode.encode('Goethe'), 'Goethe-'); 371cb0ef41Sopenharmony_ciassert.strictEqual(punycode.encode('Bücher'), 'Bcher-kva'); 381cb0ef41Sopenharmony_ciassert.strictEqual( 391cb0ef41Sopenharmony_ci punycode.encode( 401cb0ef41Sopenharmony_ci 'Willst du die Blüthe des frühen, die Früchte des späteren Jahres' 411cb0ef41Sopenharmony_ci ), 421cb0ef41Sopenharmony_ci 'Willst du die Blthe des frhen, die Frchte des spteren Jahres-x9e96lkal' 431cb0ef41Sopenharmony_ci); 441cb0ef41Sopenharmony_ciassert.strictEqual(punycode.encode('日本語'), 'wgv71a119e'); 451cb0ef41Sopenharmony_ciassert.strictEqual(punycode.encode(''), 'x73l'); 461cb0ef41Sopenharmony_ci 471cb0ef41Sopenharmony_ciassert.strictEqual(punycode.decode('tda'), 'ü'); 481cb0ef41Sopenharmony_ciassert.strictEqual(punycode.decode('Goethe-'), 'Goethe'); 491cb0ef41Sopenharmony_ciassert.strictEqual(punycode.decode('Bcher-kva'), 'Bücher'); 501cb0ef41Sopenharmony_ciassert.strictEqual( 511cb0ef41Sopenharmony_ci punycode.decode( 521cb0ef41Sopenharmony_ci 'Willst du die Blthe des frhen, die Frchte des spteren Jahres-x9e96lkal' 531cb0ef41Sopenharmony_ci ), 541cb0ef41Sopenharmony_ci 'Willst du die Blüthe des frühen, die Früchte des späteren Jahres' 551cb0ef41Sopenharmony_ci); 561cb0ef41Sopenharmony_ciassert.strictEqual(punycode.decode('wgv71a119e'), '日本語'); 571cb0ef41Sopenharmony_ciassert.strictEqual(punycode.decode('x73l'), ''); 581cb0ef41Sopenharmony_ciassert.throws(() => { 591cb0ef41Sopenharmony_ci punycode.decode(' '); 601cb0ef41Sopenharmony_ci}, /^RangeError: Invalid input$/); 611cb0ef41Sopenharmony_ciassert.throws(() => { 621cb0ef41Sopenharmony_ci punycode.decode('α-'); 631cb0ef41Sopenharmony_ci}, /^RangeError: Illegal input >= 0x80 \(not a basic code point\)$/); 641cb0ef41Sopenharmony_ciassert.throws(() => { 651cb0ef41Sopenharmony_ci punycode.decode('あ'); 661cb0ef41Sopenharmony_ci}, /^RangeError: Invalid input$/); 671cb0ef41Sopenharmony_ci 681cb0ef41Sopenharmony_ci// http://tools.ietf.org/html/rfc3492#section-7.1 691cb0ef41Sopenharmony_ciconst tests = [ 701cb0ef41Sopenharmony_ci // (A) Arabic (Egyptian) 711cb0ef41Sopenharmony_ci { 721cb0ef41Sopenharmony_ci encoded: 'egbpdaj6bu4bxfgehfvwxn', 731cb0ef41Sopenharmony_ci decoded: '\u0644\u064A\u0647\u0645\u0627\u0628\u062A\u0643\u0644\u0645' + 741cb0ef41Sopenharmony_ci '\u0648\u0634\u0639\u0631\u0628\u064A\u061F' 751cb0ef41Sopenharmony_ci }, 761cb0ef41Sopenharmony_ci 771cb0ef41Sopenharmony_ci // (B) Chinese (simplified) 781cb0ef41Sopenharmony_ci { 791cb0ef41Sopenharmony_ci encoded: 'ihqwcrb4cv8a8dqg056pqjye', 801cb0ef41Sopenharmony_ci decoded: '\u4ED6\u4EEC\u4E3A\u4EC0\u4E48\u4E0D\u8BF4\u4E2D\u6587' 811cb0ef41Sopenharmony_ci }, 821cb0ef41Sopenharmony_ci 831cb0ef41Sopenharmony_ci // (C) Chinese (traditional) 841cb0ef41Sopenharmony_ci { 851cb0ef41Sopenharmony_ci encoded: 'ihqwctvzc91f659drss3x8bo0yb', 861cb0ef41Sopenharmony_ci decoded: '\u4ED6\u5011\u7232\u4EC0\u9EBD\u4E0D\u8AAA\u4E2D\u6587' 871cb0ef41Sopenharmony_ci }, 881cb0ef41Sopenharmony_ci 891cb0ef41Sopenharmony_ci // (D) Czech: Pro<ccaron>prost<ecaron>nemluv<iacute><ccaron>esky 901cb0ef41Sopenharmony_ci { 911cb0ef41Sopenharmony_ci encoded: 'Proprostnemluvesky-uyb24dma41a', 921cb0ef41Sopenharmony_ci decoded: '\u0050\u0072\u006F\u010D\u0070\u0072\u006F\u0073\u0074\u011B' + 931cb0ef41Sopenharmony_ci '\u006E\u0065\u006D\u006C\u0075\u0076\u00ED\u010D\u0065\u0073\u006B\u0079' 941cb0ef41Sopenharmony_ci }, 951cb0ef41Sopenharmony_ci 961cb0ef41Sopenharmony_ci // (E) Hebrew 971cb0ef41Sopenharmony_ci { 981cb0ef41Sopenharmony_ci encoded: '4dbcagdahymbxekheh6e0a7fei0b', 991cb0ef41Sopenharmony_ci decoded: '\u05DC\u05DE\u05D4\u05D4\u05DD\u05E4\u05E9\u05D5\u05D8\u05DC' + 1001cb0ef41Sopenharmony_ci '\u05D0\u05DE\u05D3\u05D1\u05E8\u05D9\u05DD\u05E2\u05D1\u05E8\u05D9\u05EA' 1011cb0ef41Sopenharmony_ci }, 1021cb0ef41Sopenharmony_ci 1031cb0ef41Sopenharmony_ci // (F) Hindi (Devanagari) 1041cb0ef41Sopenharmony_ci { 1051cb0ef41Sopenharmony_ci encoded: 'i1baa7eci9glrd9b2ae1bj0hfcgg6iyaf8o0a1dig0cd', 1061cb0ef41Sopenharmony_ci decoded: '\u092F\u0939\u0932\u094B\u0917\u0939\u093F\u0928\u094D\u0926' + 1071cb0ef41Sopenharmony_ci '\u0940\u0915\u094D\u092F\u094B\u0902\u0928\u0939\u0940\u0902\u092C' + 1081cb0ef41Sopenharmony_ci '\u094B\u0932\u0938\u0915\u0924\u0947\u0939\u0948\u0902' 1091cb0ef41Sopenharmony_ci }, 1101cb0ef41Sopenharmony_ci 1111cb0ef41Sopenharmony_ci // (G) Japanese (kanji and hiragana) 1121cb0ef41Sopenharmony_ci { 1131cb0ef41Sopenharmony_ci encoded: 'n8jok5ay5dzabd5bym9f0cm5685rrjetr6pdxa', 1141cb0ef41Sopenharmony_ci decoded: '\u306A\u305C\u307F\u3093\u306A\u65E5\u672C\u8A9E\u3092\u8A71' + 1151cb0ef41Sopenharmony_ci '\u3057\u3066\u304F\u308C\u306A\u3044\u306E\u304B' 1161cb0ef41Sopenharmony_ci }, 1171cb0ef41Sopenharmony_ci 1181cb0ef41Sopenharmony_ci // (H) Korean (Hangul syllables) 1191cb0ef41Sopenharmony_ci { 1201cb0ef41Sopenharmony_ci encoded: '989aomsvi5e83db1d2a355cv1e0vak1dwrv93d5xbh15a0dt30a5jpsd879' + 1211cb0ef41Sopenharmony_ci 'ccm6fea98c', 1221cb0ef41Sopenharmony_ci decoded: '\uC138\uACC4\uC758\uBAA8\uB4E0\uC0AC\uB78C\uB4E4\uC774\uD55C' + 1231cb0ef41Sopenharmony_ci '\uAD6D\uC5B4\uB97C\uC774\uD574\uD55C\uB2E4\uBA74\uC5BC\uB9C8\uB098' + 1241cb0ef41Sopenharmony_ci '\uC88B\uC744\uAE4C' 1251cb0ef41Sopenharmony_ci }, 1261cb0ef41Sopenharmony_ci 1271cb0ef41Sopenharmony_ci // (I) Russian (Cyrillic) 1281cb0ef41Sopenharmony_ci { 1291cb0ef41Sopenharmony_ci encoded: 'b1abfaaepdrnnbgefbadotcwatmq2g4l', 1301cb0ef41Sopenharmony_ci decoded: '\u043F\u043E\u0447\u0435\u043C\u0443\u0436\u0435\u043E\u043D' + 1311cb0ef41Sopenharmony_ci '\u0438\u043D\u0435\u0433\u043E\u0432\u043E\u0440\u044F\u0442\u043F' + 1321cb0ef41Sopenharmony_ci '\u043E\u0440\u0443\u0441\u0441\u043A\u0438' 1331cb0ef41Sopenharmony_ci }, 1341cb0ef41Sopenharmony_ci 1351cb0ef41Sopenharmony_ci // (J) Spanish: Porqu<eacute>nopuedensimplementehablarenEspa<ntilde>ol 1361cb0ef41Sopenharmony_ci { 1371cb0ef41Sopenharmony_ci encoded: 'PorqunopuedensimplementehablarenEspaol-fmd56a', 1381cb0ef41Sopenharmony_ci decoded: '\u0050\u006F\u0072\u0071\u0075\u00E9\u006E\u006F\u0070\u0075' + 1391cb0ef41Sopenharmony_ci '\u0065\u0064\u0065\u006E\u0073\u0069\u006D\u0070\u006C\u0065\u006D' + 1401cb0ef41Sopenharmony_ci '\u0065\u006E\u0074\u0065\u0068\u0061\u0062\u006C\u0061\u0072\u0065' + 1411cb0ef41Sopenharmony_ci '\u006E\u0045\u0073\u0070\u0061\u00F1\u006F\u006C' 1421cb0ef41Sopenharmony_ci }, 1431cb0ef41Sopenharmony_ci 1441cb0ef41Sopenharmony_ci // (K) Vietnamese: T<adotbelow>isaoh<odotbelow>kh<ocirc>ngth 1451cb0ef41Sopenharmony_ci // <ecirchookabove>ch<ihookabove>n<oacute>iti<ecircacute>ngVi<ecircdotbelow>t 1461cb0ef41Sopenharmony_ci { 1471cb0ef41Sopenharmony_ci encoded: 'TisaohkhngthchnitingVit-kjcr8268qyxafd2f1b9g', 1481cb0ef41Sopenharmony_ci decoded: '\u0054\u1EA1\u0069\u0073\u0061\u006F\u0068\u1ECD\u006B\u0068' + 1491cb0ef41Sopenharmony_ci '\u00F4\u006E\u0067\u0074\u0068\u1EC3\u0063\u0068\u1EC9\u006E\u00F3' + 1501cb0ef41Sopenharmony_ci '\u0069\u0074\u0069\u1EBF\u006E\u0067\u0056\u0069\u1EC7\u0074' 1511cb0ef41Sopenharmony_ci }, 1521cb0ef41Sopenharmony_ci 1531cb0ef41Sopenharmony_ci // (L) 3<nen>B<gumi><kinpachi><sensei> 1541cb0ef41Sopenharmony_ci { 1551cb0ef41Sopenharmony_ci encoded: '3B-ww4c5e180e575a65lsy2b', 1561cb0ef41Sopenharmony_ci decoded: '\u0033\u5E74\u0042\u7D44\u91D1\u516B\u5148\u751F' 1571cb0ef41Sopenharmony_ci }, 1581cb0ef41Sopenharmony_ci 1591cb0ef41Sopenharmony_ci // (M) <amuro><namie>-with-SUPER-MONKEYS 1601cb0ef41Sopenharmony_ci { 1611cb0ef41Sopenharmony_ci encoded: '-with-SUPER-MONKEYS-pc58ag80a8qai00g7n9n', 1621cb0ef41Sopenharmony_ci decoded: '\u5B89\u5BA4\u5948\u7F8E\u6075\u002D\u0077\u0069\u0074\u0068' + 1631cb0ef41Sopenharmony_ci '\u002D\u0053\u0055\u0050\u0045\u0052\u002D\u004D\u004F\u004E\u004B' + 1641cb0ef41Sopenharmony_ci '\u0045\u0059\u0053' 1651cb0ef41Sopenharmony_ci }, 1661cb0ef41Sopenharmony_ci 1671cb0ef41Sopenharmony_ci // (N) Hello-Another-Way-<sorezore><no><basho> 1681cb0ef41Sopenharmony_ci { 1691cb0ef41Sopenharmony_ci encoded: 'Hello-Another-Way--fc4qua05auwb3674vfr0b', 1701cb0ef41Sopenharmony_ci decoded: '\u0048\u0065\u006C\u006C\u006F\u002D\u0041\u006E\u006F\u0074' + 1711cb0ef41Sopenharmony_ci '\u0068\u0065\u0072\u002D\u0057\u0061\u0079\u002D\u305D\u308C\u305E' + 1721cb0ef41Sopenharmony_ci '\u308C\u306E\u5834\u6240' 1731cb0ef41Sopenharmony_ci }, 1741cb0ef41Sopenharmony_ci 1751cb0ef41Sopenharmony_ci // (O) <hitotsu><yane><no><shita>2 1761cb0ef41Sopenharmony_ci { 1771cb0ef41Sopenharmony_ci encoded: '2-u9tlzr9756bt3uc0v', 1781cb0ef41Sopenharmony_ci decoded: '\u3072\u3068\u3064\u5C4B\u6839\u306E\u4E0B\u0032' 1791cb0ef41Sopenharmony_ci }, 1801cb0ef41Sopenharmony_ci 1811cb0ef41Sopenharmony_ci // (P) Maji<de>Koi<suru>5<byou><mae> 1821cb0ef41Sopenharmony_ci { 1831cb0ef41Sopenharmony_ci encoded: 'MajiKoi5-783gue6qz075azm5e', 1841cb0ef41Sopenharmony_ci decoded: '\u004D\u0061\u006A\u0069\u3067\u004B\u006F\u0069\u3059\u308B' + 1851cb0ef41Sopenharmony_ci '\u0035\u79D2\u524D' 1861cb0ef41Sopenharmony_ci }, 1871cb0ef41Sopenharmony_ci 1881cb0ef41Sopenharmony_ci // (Q) <pafii>de<runba> 1891cb0ef41Sopenharmony_ci { 1901cb0ef41Sopenharmony_ci encoded: 'de-jg4avhby1noc0d', 1911cb0ef41Sopenharmony_ci decoded: '\u30D1\u30D5\u30A3\u30FC\u0064\u0065\u30EB\u30F3\u30D0' 1921cb0ef41Sopenharmony_ci }, 1931cb0ef41Sopenharmony_ci 1941cb0ef41Sopenharmony_ci // (R) <sono><supiido><de> 1951cb0ef41Sopenharmony_ci { 1961cb0ef41Sopenharmony_ci encoded: 'd9juau41awczczp', 1971cb0ef41Sopenharmony_ci decoded: '\u305D\u306E\u30B9\u30D4\u30FC\u30C9\u3067' 1981cb0ef41Sopenharmony_ci }, 1991cb0ef41Sopenharmony_ci 2001cb0ef41Sopenharmony_ci // (S) -> $1.00 <- 2011cb0ef41Sopenharmony_ci { 2021cb0ef41Sopenharmony_ci encoded: '-> $1.00 <--', 2031cb0ef41Sopenharmony_ci decoded: '\u002D\u003E\u0020\u0024\u0031\u002E\u0030\u0030\u0020\u003C' + 2041cb0ef41Sopenharmony_ci '\u002D' 2051cb0ef41Sopenharmony_ci }, 2061cb0ef41Sopenharmony_ci]; 2071cb0ef41Sopenharmony_ci 2081cb0ef41Sopenharmony_cilet errors = 0; 2091cb0ef41Sopenharmony_ciconst handleError = (error, name) => { 2101cb0ef41Sopenharmony_ci console.error( 2111cb0ef41Sopenharmony_ci `FAIL: ${name} expected ${error.expected}, got ${error.actual}` 2121cb0ef41Sopenharmony_ci ); 2131cb0ef41Sopenharmony_ci errors++; 2141cb0ef41Sopenharmony_ci}; 2151cb0ef41Sopenharmony_ci 2161cb0ef41Sopenharmony_ciconst regexNonASCII = /[^\x20-\x7E]/; 2171cb0ef41Sopenharmony_ciconst testBattery = { 2181cb0ef41Sopenharmony_ci encode: (test) => assert.strictEqual( 2191cb0ef41Sopenharmony_ci punycode.encode(test.decoded), 2201cb0ef41Sopenharmony_ci test.encoded 2211cb0ef41Sopenharmony_ci ), 2221cb0ef41Sopenharmony_ci decode: (test) => assert.strictEqual( 2231cb0ef41Sopenharmony_ci punycode.decode(test.encoded), 2241cb0ef41Sopenharmony_ci test.decoded 2251cb0ef41Sopenharmony_ci ), 2261cb0ef41Sopenharmony_ci toASCII: (test) => assert.strictEqual( 2271cb0ef41Sopenharmony_ci punycode.toASCII(test.decoded), 2281cb0ef41Sopenharmony_ci regexNonASCII.test(test.decoded) ? 2291cb0ef41Sopenharmony_ci `xn--${test.encoded}` : 2301cb0ef41Sopenharmony_ci test.decoded 2311cb0ef41Sopenharmony_ci ), 2321cb0ef41Sopenharmony_ci toUnicode: (test) => assert.strictEqual( 2331cb0ef41Sopenharmony_ci punycode.toUnicode( 2341cb0ef41Sopenharmony_ci regexNonASCII.test(test.decoded) ? 2351cb0ef41Sopenharmony_ci `xn--${test.encoded}` : 2361cb0ef41Sopenharmony_ci test.decoded 2371cb0ef41Sopenharmony_ci ), 2381cb0ef41Sopenharmony_ci regexNonASCII.test(test.decoded) ? 2391cb0ef41Sopenharmony_ci test.decoded.toLowerCase() : 2401cb0ef41Sopenharmony_ci test.decoded 2411cb0ef41Sopenharmony_ci ) 2421cb0ef41Sopenharmony_ci}; 2431cb0ef41Sopenharmony_ci 2441cb0ef41Sopenharmony_citests.forEach((testCase) => { 2451cb0ef41Sopenharmony_ci Object.keys(testBattery).forEach((key) => { 2461cb0ef41Sopenharmony_ci try { 2471cb0ef41Sopenharmony_ci testBattery[key](testCase); 2481cb0ef41Sopenharmony_ci } catch (error) { 2491cb0ef41Sopenharmony_ci handleError(error, key); 2501cb0ef41Sopenharmony_ci } 2511cb0ef41Sopenharmony_ci }); 2521cb0ef41Sopenharmony_ci}); 2531cb0ef41Sopenharmony_ci 2541cb0ef41Sopenharmony_ci// BMP code point 2551cb0ef41Sopenharmony_ciassert.strictEqual(punycode.ucs2.encode([0x61]), 'a'); 2561cb0ef41Sopenharmony_ci// Supplementary code point (surrogate pair) 2571cb0ef41Sopenharmony_ciassert.strictEqual(punycode.ucs2.encode([0x1D306]), '\uD834\uDF06'); 2581cb0ef41Sopenharmony_ci// high surrogate 2591cb0ef41Sopenharmony_ciassert.strictEqual(punycode.ucs2.encode([0xD800]), '\uD800'); 2601cb0ef41Sopenharmony_ci// High surrogate followed by non-surrogates 2611cb0ef41Sopenharmony_ciassert.strictEqual(punycode.ucs2.encode([0xD800, 0x61, 0x62]), '\uD800ab'); 2621cb0ef41Sopenharmony_ci// low surrogate 2631cb0ef41Sopenharmony_ciassert.strictEqual(punycode.ucs2.encode([0xDC00]), '\uDC00'); 2641cb0ef41Sopenharmony_ci// Low surrogate followed by non-surrogates 2651cb0ef41Sopenharmony_ciassert.strictEqual(punycode.ucs2.encode([0xDC00, 0x61, 0x62]), '\uDC00ab'); 2661cb0ef41Sopenharmony_ci 2671cb0ef41Sopenharmony_ciassert.strictEqual(errors, 0); 2681cb0ef41Sopenharmony_ci 2691cb0ef41Sopenharmony_ci// test map domain 2701cb0ef41Sopenharmony_ciassert.strictEqual(punycode.toASCII('Bücher@日本語.com'), 2711cb0ef41Sopenharmony_ci 'Bücher@xn--wgv71a119e.com'); 2721cb0ef41Sopenharmony_ciassert.strictEqual(punycode.toUnicode('Bücher@xn--wgv71a119e.com'), 2731cb0ef41Sopenharmony_ci 'Bücher@日本語.com'); 274