Expand test with harder tests.

This commit is contained in:
saul 2023-03-29 10:37:10 +13:00
parent 194ecafb0a
commit ed28fb4136

View File

@ -1,10 +1,12 @@
import { equal } from 'assert' import { equal } from 'assert'
import Path from 'path' import Path from 'path'
import { join, posixJoin, win32Join } from '../src/utils/path-join.js' import { posixJoin, win32Join } from '../src/utils/path-join.js'
const platform = process.platform const platform = process.platform
const createTestData = s => [ const createTestData = s => [
[],
[''],
[s], [s],
[s, 'test'], [s, 'test'],
['test'], ['test'],
@ -14,7 +16,11 @@ const createTestData = s => [
[`test${s}`, s, `${s}${s}`, `${s}a`], [`test${s}`, s, `${s}${s}`, `${s}a`],
[`test${s}`, '.', `${s}a`], [`test${s}`, '.', `${s}a`],
[`test${s}.${s}a`], [`test${s}.${s}a`],
['test', s, '.', s] ['test', s, '.', s],
['/test', '\\', 'mixed'],
['\\test', '/', 'mixed'],
['test', '/', 'mixed', '\\', 'data'],
['test', '\\', 'mixed', '/', 'data']
] ]
const posixTestData = createTestData('/') const posixTestData = createTestData('/')
@ -62,13 +68,13 @@ describe('Path join on win32', () => {
it('gives the same results as Path using posix paths', () => { it('gives the same results as Path using posix paths', () => {
for (const data of posixTestData) { for (const data of posixTestData) {
equal(Path.win32.join(...data), join(...data)) equal(Path.join(...data), join(...data))
} }
}) })
it('gives the same results as Path using win32 paths', () => { it('gives the same results as Path using win32 paths', () => {
for (const data of win32TestData) { for (const data of win32TestData) {
equal(Path.win32.join(...data), join(...data)) equal(Path.join(...data), join(...data))
} }
}) })
}) })
@ -87,13 +93,13 @@ describe('Path join on posix', () => {
it('gives the same results as Path using posix paths', () => { it('gives the same results as Path using posix paths', () => {
for (const data of posixTestData) { for (const data of posixTestData) {
equal(Path.posix.join(...data), join(...data)) equal(Path.join(...data), join(...data))
} }
}) })
it('gives the same results as Path using win32 paths', () => { it('gives the same results as Path using win32 paths', () => {
for (const data of win32TestData) { for (const data of win32TestData) {
equal(Path.posix.join(...data), join(...data)) equal(Path.join(...data), join(...data))
} }
}) })
}) })