11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst common = require('../common');
41cb0ef41Sopenharmony_ciif (!common.hasIntl)
51cb0ef41Sopenharmony_ci  common.skip('missing Intl');
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ciconst assert = require('assert');
81cb0ef41Sopenharmony_ciconst url = require('url');
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ciconst myURL = new URL('http://user:pass@xn--lck1c3crb1723bpq4a.com/a?a=b#c');
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_ciassert.strictEqual(
131cb0ef41Sopenharmony_ci  url.format(myURL),
141cb0ef41Sopenharmony_ci  'http://user:pass@xn--lck1c3crb1723bpq4a.com/a?a=b#c'
151cb0ef41Sopenharmony_ci);
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ciassert.strictEqual(
181cb0ef41Sopenharmony_ci  url.format(myURL, {}),
191cb0ef41Sopenharmony_ci  'http://user:pass@xn--lck1c3crb1723bpq4a.com/a?a=b#c'
201cb0ef41Sopenharmony_ci);
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_ci{
231cb0ef41Sopenharmony_ci  [true, 1, 'test', Infinity].forEach((value) => {
241cb0ef41Sopenharmony_ci    assert.throws(
251cb0ef41Sopenharmony_ci      () => url.format(myURL, value),
261cb0ef41Sopenharmony_ci      {
271cb0ef41Sopenharmony_ci        code: 'ERR_INVALID_ARG_TYPE',
281cb0ef41Sopenharmony_ci        name: 'TypeError',
291cb0ef41Sopenharmony_ci        message: 'The "options" argument must be of type object.' +
301cb0ef41Sopenharmony_ci                 common.invalidArgTypeHelper(value)
311cb0ef41Sopenharmony_ci      }
321cb0ef41Sopenharmony_ci    );
331cb0ef41Sopenharmony_ci  });
341cb0ef41Sopenharmony_ci}
351cb0ef41Sopenharmony_ci
361cb0ef41Sopenharmony_ci// Any falsy value other than undefined will be treated as false.
371cb0ef41Sopenharmony_ci// Any truthy value will be treated as true.
381cb0ef41Sopenharmony_ci
391cb0ef41Sopenharmony_ciassert.strictEqual(
401cb0ef41Sopenharmony_ci  url.format(myURL, { auth: false }),
411cb0ef41Sopenharmony_ci  'http://xn--lck1c3crb1723bpq4a.com/a?a=b#c'
421cb0ef41Sopenharmony_ci);
431cb0ef41Sopenharmony_ci
441cb0ef41Sopenharmony_ciassert.strictEqual(
451cb0ef41Sopenharmony_ci  url.format(myURL, { auth: '' }),
461cb0ef41Sopenharmony_ci  'http://xn--lck1c3crb1723bpq4a.com/a?a=b#c'
471cb0ef41Sopenharmony_ci);
481cb0ef41Sopenharmony_ci
491cb0ef41Sopenharmony_ciassert.strictEqual(
501cb0ef41Sopenharmony_ci  url.format(myURL, { auth: 0 }),
511cb0ef41Sopenharmony_ci  'http://xn--lck1c3crb1723bpq4a.com/a?a=b#c'
521cb0ef41Sopenharmony_ci);
531cb0ef41Sopenharmony_ci
541cb0ef41Sopenharmony_ciassert.strictEqual(
551cb0ef41Sopenharmony_ci  url.format(myURL, { auth: 1 }),
561cb0ef41Sopenharmony_ci  'http://user:pass@xn--lck1c3crb1723bpq4a.com/a?a=b#c'
571cb0ef41Sopenharmony_ci);
581cb0ef41Sopenharmony_ci
591cb0ef41Sopenharmony_ciassert.strictEqual(
601cb0ef41Sopenharmony_ci  url.format(myURL, { auth: {} }),
611cb0ef41Sopenharmony_ci  'http://user:pass@xn--lck1c3crb1723bpq4a.com/a?a=b#c'
621cb0ef41Sopenharmony_ci);
631cb0ef41Sopenharmony_ci
641cb0ef41Sopenharmony_ciassert.strictEqual(
651cb0ef41Sopenharmony_ci  url.format(myURL, { fragment: false }),
661cb0ef41Sopenharmony_ci  'http://user:pass@xn--lck1c3crb1723bpq4a.com/a?a=b'
671cb0ef41Sopenharmony_ci);
681cb0ef41Sopenharmony_ci
691cb0ef41Sopenharmony_ciassert.strictEqual(
701cb0ef41Sopenharmony_ci  url.format(myURL, { fragment: '' }),
711cb0ef41Sopenharmony_ci  'http://user:pass@xn--lck1c3crb1723bpq4a.com/a?a=b'
721cb0ef41Sopenharmony_ci);
731cb0ef41Sopenharmony_ci
741cb0ef41Sopenharmony_ciassert.strictEqual(
751cb0ef41Sopenharmony_ci  url.format(myURL, { fragment: 0 }),
761cb0ef41Sopenharmony_ci  'http://user:pass@xn--lck1c3crb1723bpq4a.com/a?a=b'
771cb0ef41Sopenharmony_ci);
781cb0ef41Sopenharmony_ci
791cb0ef41Sopenharmony_ciassert.strictEqual(
801cb0ef41Sopenharmony_ci  url.format(myURL, { fragment: 1 }),
811cb0ef41Sopenharmony_ci  'http://user:pass@xn--lck1c3crb1723bpq4a.com/a?a=b#c'
821cb0ef41Sopenharmony_ci);
831cb0ef41Sopenharmony_ci
841cb0ef41Sopenharmony_ciassert.strictEqual(
851cb0ef41Sopenharmony_ci  url.format(myURL, { fragment: {} }),
861cb0ef41Sopenharmony_ci  'http://user:pass@xn--lck1c3crb1723bpq4a.com/a?a=b#c'
871cb0ef41Sopenharmony_ci);
881cb0ef41Sopenharmony_ci
891cb0ef41Sopenharmony_ciassert.strictEqual(
901cb0ef41Sopenharmony_ci  url.format(myURL, { search: false }),
911cb0ef41Sopenharmony_ci  'http://user:pass@xn--lck1c3crb1723bpq4a.com/a#c'
921cb0ef41Sopenharmony_ci);
931cb0ef41Sopenharmony_ci
941cb0ef41Sopenharmony_ciassert.strictEqual(
951cb0ef41Sopenharmony_ci  url.format(myURL, { search: '' }),
961cb0ef41Sopenharmony_ci  'http://user:pass@xn--lck1c3crb1723bpq4a.com/a#c'
971cb0ef41Sopenharmony_ci);
981cb0ef41Sopenharmony_ci
991cb0ef41Sopenharmony_ciassert.strictEqual(
1001cb0ef41Sopenharmony_ci  url.format(myURL, { search: 0 }),
1011cb0ef41Sopenharmony_ci  'http://user:pass@xn--lck1c3crb1723bpq4a.com/a#c'
1021cb0ef41Sopenharmony_ci);
1031cb0ef41Sopenharmony_ci
1041cb0ef41Sopenharmony_ciassert.strictEqual(
1051cb0ef41Sopenharmony_ci  url.format(myURL, { search: 1 }),
1061cb0ef41Sopenharmony_ci  'http://user:pass@xn--lck1c3crb1723bpq4a.com/a?a=b#c'
1071cb0ef41Sopenharmony_ci);
1081cb0ef41Sopenharmony_ci
1091cb0ef41Sopenharmony_ciassert.strictEqual(
1101cb0ef41Sopenharmony_ci  url.format(myURL, { search: {} }),
1111cb0ef41Sopenharmony_ci  'http://user:pass@xn--lck1c3crb1723bpq4a.com/a?a=b#c'
1121cb0ef41Sopenharmony_ci);
1131cb0ef41Sopenharmony_ci
1141cb0ef41Sopenharmony_ciassert.strictEqual(
1151cb0ef41Sopenharmony_ci  url.format(myURL, { unicode: true }),
1161cb0ef41Sopenharmony_ci  'http://user:pass@理容ナカムラ.com/a?a=b#c'
1171cb0ef41Sopenharmony_ci);
1181cb0ef41Sopenharmony_ci
1191cb0ef41Sopenharmony_ciassert.strictEqual(
1201cb0ef41Sopenharmony_ci  url.format(myURL, { unicode: 1 }),
1211cb0ef41Sopenharmony_ci  'http://user:pass@理容ナカムラ.com/a?a=b#c'
1221cb0ef41Sopenharmony_ci);
1231cb0ef41Sopenharmony_ci
1241cb0ef41Sopenharmony_ciassert.strictEqual(
1251cb0ef41Sopenharmony_ci  url.format(myURL, { unicode: {} }),
1261cb0ef41Sopenharmony_ci  'http://user:pass@理容ナカムラ.com/a?a=b#c'
1271cb0ef41Sopenharmony_ci);
1281cb0ef41Sopenharmony_ci
1291cb0ef41Sopenharmony_ciassert.strictEqual(
1301cb0ef41Sopenharmony_ci  url.format(myURL, { unicode: false }),
1311cb0ef41Sopenharmony_ci  'http://user:pass@xn--lck1c3crb1723bpq4a.com/a?a=b#c'
1321cb0ef41Sopenharmony_ci);
1331cb0ef41Sopenharmony_ci
1341cb0ef41Sopenharmony_ciassert.strictEqual(
1351cb0ef41Sopenharmony_ci  url.format(myURL, { unicode: 0 }),
1361cb0ef41Sopenharmony_ci  'http://user:pass@xn--lck1c3crb1723bpq4a.com/a?a=b#c'
1371cb0ef41Sopenharmony_ci);
1381cb0ef41Sopenharmony_ci
1391cb0ef41Sopenharmony_ciassert.strictEqual(
1401cb0ef41Sopenharmony_ci  url.format(new URL('http://user:pass@xn--0zwm56d.com:8080/path'), { unicode: true }),
1411cb0ef41Sopenharmony_ci  'http://user:pass@测试.com:8080/path'
1421cb0ef41Sopenharmony_ci);
1431cb0ef41Sopenharmony_ci
1441cb0ef41Sopenharmony_ciassert.strictEqual(
1451cb0ef41Sopenharmony_ci  url.format(new URL('tel:123')),
1461cb0ef41Sopenharmony_ci  url.format(new URL('tel:123'), { unicode: true })
1471cb0ef41Sopenharmony_ci);
148