|
| 1 | +import * as path from 'path' |
| 2 | + |
| 3 | +import {toPlatformPath, toPosixPath, toWin32Path} from '../src/path-utils' |
| 4 | + |
| 5 | +describe('#toPosixPath', () => { |
| 6 | + const cases: { |
| 7 | + only?: boolean |
| 8 | + name: string |
| 9 | + input: string |
| 10 | + expected: string |
| 11 | + }[] = [ |
| 12 | + { |
| 13 | + name: 'empty string', |
| 14 | + input: '', |
| 15 | + expected: '' |
| 16 | + }, |
| 17 | + { |
| 18 | + name: 'single value', |
| 19 | + input: 'foo', |
| 20 | + expected: 'foo' |
| 21 | + }, |
| 22 | + { |
| 23 | + name: 'with posix relative', |
| 24 | + input: 'foo/bar/baz', |
| 25 | + expected: 'foo/bar/baz' |
| 26 | + }, |
| 27 | + { |
| 28 | + name: 'with posix absolute', |
| 29 | + input: '/foo/bar/baz', |
| 30 | + expected: '/foo/bar/baz' |
| 31 | + }, |
| 32 | + { |
| 33 | + name: 'with win32 relative', |
| 34 | + input: 'foo\\bar\\baz', |
| 35 | + expected: 'foo/bar/baz' |
| 36 | + }, |
| 37 | + { |
| 38 | + name: 'with win32 absolute', |
| 39 | + input: '\\foo\\bar\\baz', |
| 40 | + expected: '/foo/bar/baz' |
| 41 | + }, |
| 42 | + { |
| 43 | + name: 'with a mix', |
| 44 | + input: '\\foo/bar/baz', |
| 45 | + expected: '/foo/bar/baz' |
| 46 | + } |
| 47 | + ] |
| 48 | + |
| 49 | + for (const tc of cases) { |
| 50 | + const fn = tc.only ? it.only : it |
| 51 | + fn(tc.name, () => { |
| 52 | + const result = toPosixPath(tc.input) |
| 53 | + expect(result).toEqual(tc.expected) |
| 54 | + }) |
| 55 | + } |
| 56 | +}) |
| 57 | + |
| 58 | +describe('#toWin32Path', () => { |
| 59 | + const cases: { |
| 60 | + only?: boolean |
| 61 | + name: string |
| 62 | + input: string |
| 63 | + expected: string |
| 64 | + }[] = [ |
| 65 | + { |
| 66 | + name: 'empty string', |
| 67 | + input: '', |
| 68 | + expected: '' |
| 69 | + }, |
| 70 | + { |
| 71 | + name: 'single value', |
| 72 | + input: 'foo', |
| 73 | + expected: 'foo' |
| 74 | + }, |
| 75 | + { |
| 76 | + name: 'with posix relative', |
| 77 | + input: 'foo/bar/baz', |
| 78 | + expected: 'foo\\bar\\baz' |
| 79 | + }, |
| 80 | + { |
| 81 | + name: 'with posix absolute', |
| 82 | + input: '/foo/bar/baz', |
| 83 | + expected: '\\foo\\bar\\baz' |
| 84 | + }, |
| 85 | + { |
| 86 | + name: 'with win32 relative', |
| 87 | + input: 'foo\\bar\\baz', |
| 88 | + expected: 'foo\\bar\\baz' |
| 89 | + }, |
| 90 | + { |
| 91 | + name: 'with win32 absolute', |
| 92 | + input: '\\foo\\bar\\baz', |
| 93 | + expected: '\\foo\\bar\\baz' |
| 94 | + }, |
| 95 | + { |
| 96 | + name: 'with a mix', |
| 97 | + input: '\\foo/bar\\baz', |
| 98 | + expected: '\\foo\\bar\\baz' |
| 99 | + } |
| 100 | + ] |
| 101 | + |
| 102 | + for (const tc of cases) { |
| 103 | + const fn = tc.only ? it.only : it |
| 104 | + fn(tc.name, () => { |
| 105 | + const result = toWin32Path(tc.input) |
| 106 | + expect(result).toEqual(tc.expected) |
| 107 | + }) |
| 108 | + } |
| 109 | +}) |
| 110 | + |
| 111 | +describe('#toPlatformPath', () => { |
| 112 | + const cases: { |
| 113 | + only?: boolean |
| 114 | + name: string |
| 115 | + input: string |
| 116 | + expected: string |
| 117 | + }[] = [ |
| 118 | + { |
| 119 | + name: 'empty string', |
| 120 | + input: '', |
| 121 | + expected: '' |
| 122 | + }, |
| 123 | + { |
| 124 | + name: 'single value', |
| 125 | + input: 'foo', |
| 126 | + expected: 'foo' |
| 127 | + }, |
| 128 | + { |
| 129 | + name: 'with posix relative', |
| 130 | + input: 'foo/bar/baz', |
| 131 | + expected: path.join('foo', 'bar', 'baz') |
| 132 | + }, |
| 133 | + { |
| 134 | + name: 'with posix absolute', |
| 135 | + input: '/foo/bar/baz', |
| 136 | + expected: path.join(path.sep, 'foo', 'bar', 'baz') |
| 137 | + }, |
| 138 | + { |
| 139 | + name: 'with win32 relative', |
| 140 | + input: 'foo\\bar\\baz', |
| 141 | + expected: path.join('foo', 'bar', 'baz') |
| 142 | + }, |
| 143 | + { |
| 144 | + name: 'with win32 absolute', |
| 145 | + input: '\\foo\\bar\\baz', |
| 146 | + expected: path.join(path.sep, 'foo', 'bar', 'baz') |
| 147 | + }, |
| 148 | + { |
| 149 | + name: 'with a mix', |
| 150 | + input: '\\foo/bar\\baz', |
| 151 | + expected: path.join(path.sep, 'foo', 'bar', 'baz') |
| 152 | + } |
| 153 | + ] |
| 154 | + |
| 155 | + for (const tc of cases) { |
| 156 | + const fn = tc.only ? it.only : it |
| 157 | + fn(tc.name, () => { |
| 158 | + const result = toPlatformPath(tc.input) |
| 159 | + expect(result).toEqual(tc.expected) |
| 160 | + }) |
| 161 | + } |
| 162 | +}) |
0 commit comments