| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,14 +1,10 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | ||
| 3 | - const common = require('../common'); | ||
| 4 | - if (!common.hasIntl) | ||
| 5 | - common.skip('missing Intl'); | ||
| 3 | + const { hasIntl } = require('../common'); | ||
| 6 | 4 | ||
| 7 | - const strictEqual = require('assert').strictEqual; | ||
| 8 | - const url = require('url'); | ||
| 9 | - | ||
| 10 | - const domainToASCII = url.domainToASCII; | ||
| 11 | - const domainToUnicode = url.domainToUnicode; | ||
| 5 | + const { strictEqual } = require('node:assert'); | ||
| 6 | + const { domainToASCII, domainToUnicode } = require('node:url'); | ||
| 7 | + const { test } = require('node:test'); | ||
| 12 | 8 | ||
| 13 | 9 | const domainWithASCII = [ | |
| 14 | 10 | ['ıíd', 'xn--d-iga7r'], | |
@@ -21,11 +17,11 @@ const domainWithASCII = [ | |||
| 21 | 17 | ['भारत.org', 'xn--h2brj9c.org'], | |
| 22 | 18 | ]; | |
| 23 | 19 | ||
| 24 | - domainWithASCII.forEach((pair) => { | ||
| 25 | - const domain = pair[0]; | ||
| 26 | - const ascii = pair[1]; | ||
| 27 | - const domainConvertedToASCII = domainToASCII(domain); | ||
| 28 | - strictEqual(domainConvertedToASCII, ascii); | ||
| 29 | - const asciiConvertedToUnicode = domainToUnicode(ascii); | ||
| 30 | - strictEqual(asciiConvertedToUnicode, domain); | ||
| 20 | + test('domainToASCII and domainToUnicode', { skip: !hasIntl }, () => { | ||
| 21 | + for (const [domain, ascii] of domainWithASCII) { | ||
| 22 | + const domainConvertedToASCII = domainToASCII(domain); | ||
| 23 | + strictEqual(domainConvertedToASCII, ascii); | ||
| 24 | + const asciiConvertedToUnicode = domainToUnicode(ascii); | ||
| 25 | + strictEqual(asciiConvertedToUnicode, domain); | ||
| 26 | + } | ||
| 31 | 27 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,25 +1,25 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | const { isWindows } = require('../common'); | |
| 3 | - const assert = require('assert'); | ||
| 4 | - const url = require('url'); | ||
| 5 | 3 | ||
| 6 | - function testInvalidArgs(...args) { | ||
| 7 | - for (const arg of args) { | ||
| 4 | + const { test } = require('node:test'); | ||
| 5 | + const assert = require('node:assert'); | ||
| 6 | + const url = require('node:url'); | ||
| 7 | + | ||
| 8 | + test('invalid arguments', () => { | ||
| 9 | + for (const arg of [null, undefined, 1, {}, true]) { | ||
| 8 | 10 | assert.throws(() => url.fileURLToPath(arg), { | |
| 9 | 11 | code: 'ERR_INVALID_ARG_TYPE' | |
| 10 | 12 | }); | |
| 11 | 13 | } | |
| 12 | - } | ||
| 13 | - | ||
| 14 | - // Input must be string or URL | ||
| 15 | - testInvalidArgs(null, undefined, 1, {}, true); | ||
| 14 | + }); | ||
| 16 | 15 | ||
| 17 | - // Input must be a file URL | ||
| 18 | - assert.throws(() => url.fileURLToPath('https://a/b/c'), { | ||
| 19 | - code: 'ERR_INVALID_URL_SCHEME' | ||
| 16 | + test('input must be a file URL', () => { | ||
| 17 | + assert.throws(() => url.fileURLToPath('https://a/b/c'), { | ||
| 18 | + code: 'ERR_INVALID_URL_SCHEME' | ||
| 19 | + }); | ||
| 20 | 20 | }); | |
| 21 | 21 | ||
| 22 | - { | ||
| 22 | + test('fileURLToPath with host', () => { | ||
| 23 | 23 | const withHost = new URL('file://host/a'); | |
| 24 | 24 | ||
| 25 | 25 | if (isWindows) { | |
@@ -29,9 +29,9 @@ assert.throws(() => url.fileURLToPath('https://a/b/c'), { | |||
| 29 | 29 | code: 'ERR_INVALID_FILE_URL_HOST' | |
| 30 | 30 | }); | |
| 31 | 31 | } | |
| 32 | - } | ||
| 32 | + }); | ||
| 33 | 33 | ||
| 34 | - { | ||
| 34 | + test('fileURLToPath with invalid path', () => { | ||
| 35 | 35 | if (isWindows) { | |
| 36 | 36 | assert.throws(() => url.fileURLToPath('file:///C:/a%2F/'), { | |
| 37 | 37 | code: 'ERR_INVALID_FILE_URL_PATH' | |
@@ -47,7 +47,7 @@ assert.throws(() => url.fileURLToPath('https://a/b/c'), { | |||
| 47 | 47 | code: 'ERR_INVALID_FILE_URL_PATH' | |
| 48 | 48 | }); | |
| 49 | 49 | } | |
| 50 | - } | ||
| 50 | + }); | ||
| 51 | 51 | ||
| 52 | 52 | const windowsTestCases = [ | |
| 53 | 53 | // Lowercase ascii alpha | |
@@ -95,6 +95,7 @@ const windowsTestCases = [ | |||
| 95 | 95 | // UNC path (see https://docs.microsoft.com/en-us/archive/blogs/ie/file-uris-in-windows) | |
| 96 | 96 | { path: '\\\\nas\\My Docs\\File.doc', fileURL: 'file://nas/My%20Docs/File.doc' }, | |
| 97 | 97 | ]; | |
| 98 | + | ||
| 98 | 99 | const posixTestCases = [ | |
| 99 | 100 | // Lowercase ascii alpha | |
| 100 | 101 | { path: '/foo', fileURL: 'file:///foo' }, | |
@@ -140,29 +141,37 @@ const posixTestCases = [ | |||
| 140 | 141 | { path: '/🚀', fileURL: 'file:///%F0%9F%9A%80' }, | |
| 141 | 142 | ]; | |
| 142 | 143 | ||
| 143 | - for (const { path, fileURL } of windowsTestCases) { | ||
| 144 | - const fromString = url.fileURLToPath(fileURL, { windows: true }); | ||
| 145 | - assert.strictEqual(fromString, path); | ||
| 146 | - const fromURL = url.fileURLToPath(new URL(fileURL), { windows: true }); | ||
| 147 | - assert.strictEqual(fromURL, path); | ||
| 148 | - } | ||
| 144 | + test('fileURLToPath with windows path', { skip: !isWindows }, () => { | ||
| 145 | + | ||
| 146 | + for (const { path, fileURL } of windowsTestCases) { | ||
| 147 | + const fromString = url.fileURLToPath(fileURL, { windows: true }); | ||
| 148 | + assert.strictEqual(fromString, path); | ||
| 149 | + const fromURL = url.fileURLToPath(new URL(fileURL), { windows: true }); | ||
| 150 | + assert.strictEqual(fromURL, path); | ||
| 151 | + } | ||
| 152 | + }); | ||
| 149 | 153 | ||
| 150 | - for (const { path, fileURL } of posixTestCases) { | ||
| 151 | - const fromString = url.fileURLToPath(fileURL, { windows: false }); | ||
| 152 | - assert.strictEqual(fromString, path); | ||
| 153 | - const fromURL = url.fileURLToPath(new URL(fileURL), { windows: false }); | ||
| 154 | - assert.strictEqual(fromURL, path); | ||
| 155 | - } | ||
| 154 | + test('fileURLToPath with posix path', { skip: isWindows }, () => { | ||
| 155 | + for (const { path, fileURL } of posixTestCases) { | ||
| 156 | + const fromString = url.fileURLToPath(fileURL, { windows: false }); | ||
| 157 | + assert.strictEqual(fromString, path); | ||
| 158 | + const fromURL = url.fileURLToPath(new URL(fileURL), { windows: false }); | ||
| 159 | + assert.strictEqual(fromURL, path); | ||
| 160 | + } | ||
| 161 | + }); | ||
| 156 | 162 | ||
| 157 | 163 | const defaultTestCases = isWindows ? windowsTestCases : posixTestCases; | |
| 158 | 164 | ||
| 159 | - // Test when `options` is null | ||
| 160 | - const whenNullActual = url.fileURLToPath(new URL(defaultTestCases[0].fileURL), null); | ||
| 161 | - assert.strictEqual(whenNullActual, defaultTestCases[0].path); | ||
| 165 | + test('options is null', () => { | ||
| 166 | + const whenNullActual = url.fileURLToPath(new URL(defaultTestCases[0].fileURL), null); | ||
| 167 | + assert.strictEqual(whenNullActual, defaultTestCases[0].path); | ||
| 168 | + }); | ||
| 162 | 169 | ||
| 163 | - for (const { path, fileURL } of defaultTestCases) { | ||
| 164 | - const fromString = url.fileURLToPath(fileURL); | ||
| 165 | - assert.strictEqual(fromString, path); | ||
| 166 | - const fromURL = url.fileURLToPath(new URL(fileURL)); | ||
| 167 | - assert.strictEqual(fromURL, path); | ||
| 168 | - } | ||
| 170 | + test('defaultTestCases', () => { | ||
| 171 | + for (const { path, fileURL } of defaultTestCases) { | ||
| 172 | + const fromString = url.fileURLToPath(fileURL); | ||
| 173 | + assert.strictEqual(fromString, path); | ||
| 174 | + const fromURL = url.fileURLToPath(new URL(fileURL)); | ||
| 175 | + assert.strictEqual(fromURL, path); | ||
| 176 | + } | ||
| 177 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,27 +1,30 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | - const common = require('../common'); | ||
| 3 | - const assert = require('assert'); | ||
| 4 | - const url = require('url'); | ||
| 5 | 2 | ||
| 6 | - const throwsObjsAndReportTypes = [ | ||
| 7 | - undefined, | ||
| 8 | - null, | ||
| 9 | - true, | ||
| 10 | - false, | ||
| 11 | - 0, | ||
| 12 | - function() {}, | ||
| 13 | - Symbol('foo'), | ||
| 14 | - ]; | ||
| 3 | + require('../common'); | ||
| 15 | 4 | ||
| 16 | - for (const urlObject of throwsObjsAndReportTypes) { | ||
| 17 | - assert.throws(() => { | ||
| 18 | - url.format(urlObject); | ||
| 19 | - }, { | ||
| 20 | - code: 'ERR_INVALID_ARG_TYPE', | ||
| 21 | - name: 'TypeError', | ||
| 22 | - message: 'The "urlObject" argument must be one of type object or string.' + | ||
| 23 | - common.invalidArgTypeHelper(urlObject) | ||
| 24 | - }); | ||
| 25 | - } | ||
| 26 | - assert.strictEqual(url.format(''), ''); | ||
| 27 | - assert.strictEqual(url.format({}), ''); | ||
| 5 | + const assert = require('node:assert'); | ||
| 6 | + const url = require('node:url'); | ||
| 7 | + const { test } = require('node:test'); | ||
| 8 | + | ||
| 9 | + test('format invalid input', () => { | ||
| 10 | + const throwsObjsAndReportTypes = [ | ||
| 11 | + undefined, | ||
| 12 | + null, | ||
| 13 | + true, | ||
| 14 | + false, | ||
| 15 | + 0, | ||
| 16 | + function() {}, | ||
| 17 | + Symbol('foo'), | ||
| 18 | + ]; | ||
| 19 | + | ||
| 20 | + for (const urlObject of throwsObjsAndReportTypes) { | ||
| 21 | + assert.throws(() => { | ||
| 22 | + url.format(urlObject); | ||
| 23 | + }, { | ||
| 24 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 25 | + name: 'TypeError', | ||
| 26 | + }); | ||
| 27 | + } | ||
| 28 | + assert.strictEqual(url.format(''), ''); | ||
| 29 | + assert.strictEqual(url.format({}), ''); | ||
| 30 | + }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments