|
| 1 | +import { describe, it, expect } from '@jest/globals'; |
| 2 | +import { quotePath, normalizePath, expandHome, convertToWindowsPath } from '../path-utils.js'; |
| 3 | + |
| 4 | +describe('Path Utilities', () => { |
| 5 | + describe('quotePath', () => { |
| 6 | + it('adds quotes to paths with spaces', () => { |
| 7 | + expect(quotePath('C:\\NS\\My Kindle Content')).toBe('"C:\\NS\\My Kindle Content"'); |
| 8 | + expect(quotePath('C:/NS/My Kindle Content')).toBe('"C:/NS/My Kindle Content"'); |
| 9 | + }); |
| 10 | + |
| 11 | + it('leaves paths without spaces unquoted', () => { |
| 12 | + expect(quotePath('C:\\Windows')).toBe('C:\\Windows'); |
| 13 | + expect(quotePath('C:/Windows')).toBe('C:/Windows'); |
| 14 | + }); |
| 15 | + }); |
| 16 | + |
| 17 | + describe('convertToWindowsPath', () => { |
| 18 | + it('converts WSL paths to Windows format', () => { |
| 19 | + expect(convertToWindowsPath('/mnt/c/NS/MyKindleContent')) |
| 20 | + .toBe('C:\\NS\\MyKindleContent'); |
| 21 | + }); |
| 22 | + |
| 23 | + it('converts Unix-style Windows paths to Windows format', () => { |
| 24 | + expect(convertToWindowsPath('/c/NS/MyKindleContent')) |
| 25 | + .toBe('C:\\NS\\MyKindleContent'); |
| 26 | + }); |
| 27 | + |
| 28 | + it('leaves Windows paths unchanged', () => { |
| 29 | + expect(convertToWindowsPath('C:\\NS\\MyKindleContent')) |
| 30 | + .toBe('C:\\NS\\MyKindleContent'); |
| 31 | + }); |
| 32 | + |
| 33 | + it('handles uppercase and lowercase drive letters', () => { |
| 34 | + expect(convertToWindowsPath('/mnt/d/some/path')) |
| 35 | + .toBe('D:\\some\\path'); |
| 36 | + expect(convertToWindowsPath('/d/some/path')) |
| 37 | + .toBe('D:\\some\\path'); |
| 38 | + }); |
| 39 | + }); |
| 40 | + |
| 41 | + describe('normalizePath', () => { |
| 42 | + it('removes surrounding quotes', () => { |
| 43 | + expect(normalizePath('"C:\\NS\\My Kindle Content"')) |
| 44 | + .toBe('C:\\NS\\My Kindle Content'); |
| 45 | + }); |
| 46 | + |
| 47 | + it('normalizes backslashes', () => { |
| 48 | + expect(normalizePath('C:\\\\NS\\\\MyKindleContent')) |
| 49 | + .toBe('C:\\NS\\MyKindleContent'); |
| 50 | + }); |
| 51 | + |
| 52 | + it('converts forward slashes to backslashes on Windows', () => { |
| 53 | + expect(normalizePath('C:/NS/MyKindleContent')) |
| 54 | + .toBe('C:\\NS\\MyKindleContent'); |
| 55 | + }); |
| 56 | + |
| 57 | + it('handles WSL paths', () => { |
| 58 | + expect(normalizePath('/mnt/c/NS/MyKindleContent')) |
| 59 | + .toBe('C:\\NS\\MyKindleContent'); |
| 60 | + }); |
| 61 | + |
| 62 | + it('handles Unix-style Windows paths', () => { |
| 63 | + expect(normalizePath('/c/NS/MyKindleContent')) |
| 64 | + .toBe('C:\\NS\\MyKindleContent'); |
| 65 | + }); |
| 66 | + |
| 67 | + it('handles paths with spaces and mixed slashes', () => { |
| 68 | + expect(normalizePath('C:/NS/My Kindle Content')) |
| 69 | + .toBe('C:\\NS\\My Kindle Content'); |
| 70 | + expect(normalizePath('/mnt/c/NS/My Kindle Content')) |
| 71 | + .toBe('C:\\NS\\My Kindle Content'); |
| 72 | + }); |
| 73 | + }); |
| 74 | + |
| 75 | + describe('expandHome', () => { |
| 76 | + it('expands ~ to home directory', () => { |
| 77 | + const result = expandHome('~/test'); |
| 78 | + expect(result).toContain('test'); |
| 79 | + expect(result).not.toContain('~'); |
| 80 | + }); |
| 81 | + |
| 82 | + it('leaves other paths unchanged', () => { |
| 83 | + expect(expandHome('C:/test')).toBe('C:/test'); |
| 84 | + }); |
| 85 | + }); |
| 86 | +}); |
0 commit comments