|
| 1 | +import {escapeExecutablePath} from "../src/utils/escapePath" |
| 2 | + |
| 3 | +describe("test path escape", () => { |
| 4 | + it("should escape Windows path with space", () => { |
| 5 | + const originalPath = "C:\\Program Files\\processing\\processing-java" |
| 6 | + |
| 7 | + expect(escapeExecutablePath(originalPath)).toBe( |
| 8 | + "C:\\Program` Files\\processing\\processing-java", |
| 9 | + ) |
| 10 | + }) |
| 11 | + |
| 12 | + it("should escape Unix path with space", () => { |
| 13 | + const originalPath = "/usr/bin/something else/processing-java" |
| 14 | + |
| 15 | + expect(escapeExecutablePath(originalPath)).toBe( |
| 16 | + "/usr/bin/something\\ else/processing-java", |
| 17 | + ) |
| 18 | + }) |
| 19 | + |
| 20 | + it("should leave Windows path without spaces as is", () => { |
| 21 | + const originalPath = ".\\processing\\processing-java" |
| 22 | + |
| 23 | + expect(escapeExecutablePath(originalPath)).toBe(".\\processing\\processing-java") |
| 24 | + }) |
| 25 | + |
| 26 | + it("should leave Unix path without spaces as is", () => { |
| 27 | + const originalPath = "/usr/bin/processing-java" |
| 28 | + |
| 29 | + expect(escapeExecutablePath(originalPath)).toBe("/usr/bin/processing-java") |
| 30 | + }) |
| 31 | + |
| 32 | + it("should not escape already escaped spaces on Windows", () => { |
| 33 | + const originalPath = "C:\\Program` Files\\processing\\processing java" |
| 34 | + |
| 35 | + expect(escapeExecutablePath(originalPath)).toBe( |
| 36 | + "C:\\Program` Files\\processing\\processing` java", |
| 37 | + ) |
| 38 | + }) |
| 39 | + |
| 40 | + it("should not escape already escaped spaces on Unix", () => { |
| 41 | + const originalPath = "/usr/bin/something else/processing\\ java" |
| 42 | + |
| 43 | + expect(escapeExecutablePath(originalPath)).toBe( |
| 44 | + "/usr/bin/something\\ else/processing\\ java", |
| 45 | + ) |
| 46 | + }) |
| 47 | + |
| 48 | + it("should detect platform if no path seperators available", () => { |
| 49 | + const originalPath = "processing java" |
| 50 | + |
| 51 | + if (process.platform === "win32") { |
| 52 | + expect(escapeExecutablePath(originalPath)).toBe("processing` java") |
| 53 | + } else { |
| 54 | + expect(escapeExecutablePath(originalPath)).toBe("processing\\ java") |
| 55 | + } |
| 56 | + }) |
| 57 | + |
| 58 | + it("should leave single path as is", () => { |
| 59 | + const originalPath = "processing-java" |
| 60 | + |
| 61 | + expect(escapeExecutablePath(originalPath)).toBe("processing-java") |
| 62 | + }) |
| 63 | +}) |
0 commit comments