|
| 1 | +/*--------------------------------------------------------- |
| 2 | + * Copyright (C) Microsoft Corporation. All rights reserved. |
| 3 | + * Licensed under the MIT License. See LICENSE in the project root for license information. |
| 4 | + *--------------------------------------------------------*/ |
| 5 | + |
| 6 | +import * as assert from 'assert'; |
| 7 | +import { normalizeSeparators } from '../../src/debugAdapter/goDebug'; |
| 8 | + |
| 9 | +suite('NormalizeSeparators Tests', () => { |
| 10 | + test('fix separator', () => { |
| 11 | + const tt = [ |
| 12 | + { |
| 13 | + input: 'path/to/file', |
| 14 | + want: 'path/to/file', |
| 15 | + }, |
| 16 | + { |
| 17 | + input: '\\path\\to\\file', |
| 18 | + want: '/path/to/file', |
| 19 | + }, |
| 20 | + { |
| 21 | + input: '/path/to\\file', |
| 22 | + want: '/path/to/file', |
| 23 | + }, |
| 24 | + ]; |
| 25 | + |
| 26 | + for (const tc of tt) { |
| 27 | + const got = normalizeSeparators(tc.input); |
| 28 | + assert.strictEqual(got, tc.want); |
| 29 | + } |
| 30 | + }); |
| 31 | + test('fix drive casing', () => { |
| 32 | + const tt = [ |
| 33 | + { |
| 34 | + input: 'C:/path/to/file', |
| 35 | + want: 'C:/path/to/file', |
| 36 | + }, |
| 37 | + { |
| 38 | + input: 'c:/path/to/file', |
| 39 | + want: 'C:/path/to/file', |
| 40 | + }, |
| 41 | + { |
| 42 | + input: 'C:/path/to/file', |
| 43 | + want: 'C:/path/to/file', |
| 44 | + }, |
| 45 | + { |
| 46 | + input: 'C:\\path\\to\\file', |
| 47 | + want: 'C:/path/to/file', |
| 48 | + }, |
| 49 | + { |
| 50 | + input: 'c:\\path\\to\\file', |
| 51 | + want: 'C:/path/to/file', |
| 52 | + }, |
| 53 | + { |
| 54 | + input: 'c:\\path\\to\\file', |
| 55 | + want: 'C:/path/to/file', |
| 56 | + } |
| 57 | + ]; |
| 58 | + |
| 59 | + for (const tc of tt) { |
| 60 | + const got = normalizeSeparators(tc.input); |
| 61 | + assert.strictEqual(got, tc.want); |
| 62 | + } |
| 63 | + }); |
| 64 | + test('relative paths', () => { |
| 65 | + const tt = [ |
| 66 | + { |
| 67 | + input: '../path/to/file', |
| 68 | + want: '../path/to/file', |
| 69 | + }, |
| 70 | + { |
| 71 | + input: './path/to/file', |
| 72 | + want: './path/to/file', |
| 73 | + }, |
| 74 | + { |
| 75 | + input: '..\\path\\to\\file', |
| 76 | + want: '../path/to/file', |
| 77 | + }, |
| 78 | + { |
| 79 | + input: '.\\path\\to\\file', |
| 80 | + want: './path/to/file', |
| 81 | + }, |
| 82 | + { |
| 83 | + input: '/path/to/../file', |
| 84 | + want: '/path/to/../file', |
| 85 | + }, |
| 86 | + { |
| 87 | + input: 'c:\\path\\to\\..\\file', |
| 88 | + want: 'C:/path/to/../file', |
| 89 | + } |
| 90 | + ]; |
| 91 | + |
| 92 | + for (const tc of tt) { |
| 93 | + const got = normalizeSeparators(tc.input); |
| 94 | + assert.strictEqual(got, tc.want); |
| 95 | + } |
| 96 | + }); |
| 97 | + |
| 98 | +}); |
0 commit comments