2017-02-02 14:13:16 +08:00
|
|
|
'use strict';
|
|
|
|
|
2018-08-22 03:27:56 +08:00
|
|
|
// Tests below are not from WPT.
|
|
|
|
|
2017-02-02 14:13:16 +08:00
|
|
|
const common = require('../common');
|
|
|
|
if (!common.hasIntl) {
|
|
|
|
// A handful of the tests fail when ICU is not included.
|
|
|
|
common.skip('missing Intl');
|
|
|
|
}
|
|
|
|
|
2017-07-01 02:29:09 +03:00
|
|
|
const util = require('util');
|
|
|
|
const assert = require('assert');
|
|
|
|
|
2017-04-04 21:03:14 -07:00
|
|
|
const url = new URL('https://username:password@host.name:8080/path/name/?que=ry#hash');
|
2017-02-02 14:13:16 +08:00
|
|
|
|
2017-04-04 21:03:14 -07:00
|
|
|
assert.strictEqual(
|
|
|
|
util.inspect(url),
|
|
|
|
`URL {
|
2019-04-05 22:18:16 +02:00
|
|
|
href: 'https://username:password@host.name:8080/path/name/?que=ry#hash',
|
2017-04-04 21:03:14 -07:00
|
|
|
origin: 'https://host.name:8080',
|
|
|
|
protocol: 'https:',
|
|
|
|
username: 'username',
|
2017-04-15 00:42:25 -04:00
|
|
|
password: 'password',
|
2017-04-04 21:03:14 -07:00
|
|
|
host: 'host.name:8080',
|
|
|
|
hostname: 'host.name',
|
|
|
|
port: '8080',
|
|
|
|
pathname: '/path/name/',
|
|
|
|
search: '?que=ry',
|
|
|
|
searchParams: URLSearchParams { 'que' => 'ry' },
|
2019-04-05 22:18:16 +02:00
|
|
|
hash: '#hash'
|
|
|
|
}`);
|
2017-02-02 14:13:16 +08:00
|
|
|
|
2017-04-04 21:03:14 -07:00
|
|
|
assert.strictEqual(
|
|
|
|
util.inspect(url, { showHidden: true }),
|
|
|
|
`URL {
|
2019-04-05 22:18:16 +02:00
|
|
|
href: 'https://username:password@host.name:8080/path/name/?que=ry#hash',
|
2017-04-04 21:03:14 -07:00
|
|
|
origin: 'https://host.name:8080',
|
|
|
|
protocol: 'https:',
|
|
|
|
username: 'username',
|
|
|
|
password: 'password',
|
|
|
|
host: 'host.name:8080',
|
|
|
|
hostname: 'host.name',
|
|
|
|
port: '8080',
|
|
|
|
pathname: '/path/name/',
|
|
|
|
search: '?que=ry',
|
|
|
|
searchParams: URLSearchParams { 'que' => 'ry' },
|
|
|
|
hash: '#hash',
|
2024-11-08 12:18:04 +00:00
|
|
|
Symbol(context): URLContext {
|
2023-02-06 08:30:55 -05:00
|
|
|
href: 'https://username:password@host.name:8080/path/name/?que=ry#hash',
|
2023-03-31 09:03:06 -04:00
|
|
|
protocol_end: 6,
|
|
|
|
username_end: 16,
|
|
|
|
host_start: 25,
|
|
|
|
host_end: 35,
|
|
|
|
pathname_start: 40,
|
|
|
|
search_start: 51,
|
|
|
|
hash_start: 58,
|
|
|
|
port: 8080,
|
|
|
|
scheme_type: 2,
|
|
|
|
[hasPort]: [Getter],
|
|
|
|
[hasSearch]: [Getter],
|
|
|
|
[hasHash]: [Getter]
|
2019-04-05 22:18:16 +02:00
|
|
|
}
|
|
|
|
}`);
|
2017-02-02 14:13:16 +08:00
|
|
|
|
2017-04-04 21:03:14 -07:00
|
|
|
assert.strictEqual(
|
|
|
|
util.inspect({ a: url }, { depth: 0 }),
|
2023-03-03 16:34:56 -05:00
|
|
|
'{ a: URL {} }');
|
2017-02-02 14:13:16 +08:00
|
|
|
|
2017-04-04 21:03:14 -07:00
|
|
|
class MyURL extends URL {}
|
|
|
|
assert(util.inspect(new MyURL(url.href)).startsWith('MyURL {'));
|