|
| 1 | +import { test } from 'uvu' |
| 2 | +import * as assert from 'uvu/assert' |
| 3 | +import { |
| 4 | + withPrefix, |
| 5 | + withoutPrefix, |
| 6 | + withSuffix, |
| 7 | + withoutSuffix, |
| 8 | + createUrl, |
| 9 | + getFullPath, |
| 10 | +} from '../../../src/utils/route' |
| 11 | + |
| 12 | +test('withPrefix', () => { |
| 13 | + assert.is(withPrefix('/my/path', '/'), '/my/path') |
| 14 | + assert.is(withPrefix('my/path', '/'), '/my/path') |
| 15 | + assert.is(withPrefix('/my/path', '/my'), '/my/path') |
| 16 | + assert.is(withPrefix('/path', '/my'), '/my/path') |
| 17 | +}) |
| 18 | + |
| 19 | +test('withoutPrefix', () => { |
| 20 | + assert.is(withoutPrefix('/my/path', '/'), 'my/path') |
| 21 | + assert.is(withoutPrefix('my/path', '/'), 'my/path') |
| 22 | + assert.is(withoutPrefix('/my/path', '/my'), '/path') |
| 23 | + assert.is(withoutPrefix('/path', '/my'), '/path') |
| 24 | +}) |
| 25 | + |
| 26 | +test('withSuffix', () => { |
| 27 | + assert.is(withSuffix('/my/path', '/'), '/my/path/') |
| 28 | + assert.is(withSuffix('/my/path/', '/'), '/my/path/') |
| 29 | + assert.is(withSuffix('/my', '/path'), '/my/path') |
| 30 | + assert.is(withSuffix('/my/path', '/path'), '/my/path') |
| 31 | +}) |
| 32 | + |
| 33 | +test('withoutSuffix', () => { |
| 34 | + assert.is(withoutSuffix('/my/path', '/'), '/my/path') |
| 35 | + assert.is(withoutSuffix('/my/path/', '/'), '/my/path') |
| 36 | + assert.is(withoutSuffix('/my/path', '/path'), '/my') |
| 37 | + assert.is(withoutSuffix('/my', '/path'), '/my') |
| 38 | +}) |
| 39 | + |
| 40 | +test('createUrl', () => { |
| 41 | + assert.is( |
| 42 | + createUrl(new URL('http://e.g/my/path')).toString(), |
| 43 | + 'http://e.g/my/path' |
| 44 | + ) |
| 45 | + |
| 46 | + assert.is(createUrl('http://e.g/my/path').toString(), 'http://e.g/my/path') |
| 47 | + assert.is(createUrl('/my/path').toString(), 'http://e.g/my/path') |
| 48 | + assert.is(createUrl('/my/path?query').toString(), 'http://e.g/my/path?query') |
| 49 | +}) |
| 50 | + |
| 51 | +test('getFullPath', () => { |
| 52 | + assert.is(getFullPath(new URL('http://e.g/my/path')), '/my/path/') |
| 53 | + assert.is(getFullPath('/my/path'), '/my/path/') |
| 54 | + assert.is(getFullPath('/my/path?query'), '/my/path/?query') |
| 55 | + |
| 56 | + assert.is(getFullPath('/my/path', '/my'), '/path/') |
| 57 | + assert.is(getFullPath('/my/path/', '/my'), '/path/') |
| 58 | + assert.is(getFullPath('/my/path?query', '/my'), '/path/?query') |
| 59 | + |
| 60 | + assert.is(getFullPath('/my/', '/my'), '/') |
| 61 | + assert.is(getFullPath('/my', '/my'), '/') |
| 62 | + assert.is(getFullPath('/my/?query', '/my'), '/?query') |
| 63 | + assert.is(getFullPath('/my?query', '/my'), '/?query') |
| 64 | + |
| 65 | + assert.is(getFullPath('/my/deep/path', '/my/deep'), '/path/') |
| 66 | + assert.is(getFullPath('/my/deepest/path', '/my/deep'), '/my/deepest/path/') |
| 67 | +}) |
| 68 | + |
| 69 | +test.run() |
0 commit comments