|
| 1 | +import { normalizePath } from "../../../src/pathUtils"; |
| 2 | + |
| 3 | +describe("normalizePath", () => { |
| 4 | + const testCases = [ |
| 5 | + // Basic cases |
| 6 | + { |
| 7 | + input: "path/to/file.prompt", |
| 8 | + expectedWithExtension: "path/to/file.prompt", |
| 9 | + expectedWithoutExtension: "path/to/file", |
| 10 | + }, |
| 11 | + { |
| 12 | + input: "path\\to\\file.agent", |
| 13 | + expectedWithExtension: "path/to/file.agent", |
| 14 | + expectedWithoutExtension: "path/to/file", |
| 15 | + }, |
| 16 | + { |
| 17 | + input: "/leading/slashes/file.prompt", |
| 18 | + expectedWithExtension: "leading/slashes/file.prompt", |
| 19 | + expectedWithoutExtension: "leading/slashes/file", |
| 20 | + }, |
| 21 | + { |
| 22 | + input: "trailing/slashes/file.agent/", |
| 23 | + expectedWithExtension: "trailing/slashes/file.agent", |
| 24 | + expectedWithoutExtension: "trailing/slashes/file", |
| 25 | + }, |
| 26 | + { |
| 27 | + input: "multiple//slashes//file.prompt", |
| 28 | + expectedWithExtension: "multiple/slashes/file.prompt", |
| 29 | + expectedWithoutExtension: "multiple/slashes/file", |
| 30 | + }, |
| 31 | + // Edge cases |
| 32 | + { |
| 33 | + input: "path/to/file with spaces.prompt", |
| 34 | + expectedWithExtension: "path/to/file with spaces.prompt", |
| 35 | + expectedWithoutExtension: "path/to/file with spaces", |
| 36 | + }, |
| 37 | + { |
| 38 | + input: "path/to/file\\with\\backslashes.prompt", |
| 39 | + expectedWithExtension: "path/to/file/with/backslashes.prompt", |
| 40 | + expectedWithoutExtension: "path/to/file/with/backslashes", |
| 41 | + }, |
| 42 | + { |
| 43 | + input: "path/to/unicode/文件.prompt", |
| 44 | + expectedWithExtension: "path/to/unicode/文件.prompt", |
| 45 | + expectedWithoutExtension: "path/to/unicode/文件", |
| 46 | + }, |
| 47 | + { |
| 48 | + input: "path/to/special/chars/!@#$%^&*().prompt", |
| 49 | + expectedWithExtension: "path/to/special/chars/!@#$%^&*().prompt", |
| 50 | + expectedWithoutExtension: "path/to/special/chars/!@#$%^&*()", |
| 51 | + }, |
| 52 | + ]; |
| 53 | + |
| 54 | + test.each(testCases)( |
| 55 | + "normalizes path '$input' correctly", |
| 56 | + ({ input, expectedWithExtension, expectedWithoutExtension }) => { |
| 57 | + // Test without stripping extension |
| 58 | + const resultWithExtension = normalizePath(input, false); |
| 59 | + expect(resultWithExtension).toBe(expectedWithExtension); |
| 60 | + |
| 61 | + // Test with extension stripping |
| 62 | + const resultWithoutExtension = normalizePath(input, true); |
| 63 | + expect(resultWithoutExtension).toBe(expectedWithoutExtension); |
| 64 | + |
| 65 | + // Add custom failure messages if needed |
| 66 | + if (resultWithExtension !== expectedWithExtension) { |
| 67 | + throw new Error( |
| 68 | + `Failed with stripExtension=false for '${input}'. Expected '${expectedWithExtension}', got '${resultWithExtension}'`, |
| 69 | + ); |
| 70 | + } |
| 71 | + if (resultWithoutExtension !== expectedWithoutExtension) { |
| 72 | + throw new Error( |
| 73 | + `Failed with stripExtension=true for '${input}'. Expected '${expectedWithoutExtension}', got '${resultWithoutExtension}'`, |
| 74 | + ); |
| 75 | + } |
| 76 | + }, |
| 77 | + ); |
| 78 | +}); |
0 commit comments