|
| 1 | +import { convertToMentionPath } from "../path-mentions" |
| 2 | + |
| 3 | +describe("path-mentions", () => { |
| 4 | + describe("convertToMentionPath", () => { |
| 5 | + it("should convert an absolute path to a mention path when it starts with cwd", () => { |
| 6 | + // Windows-style paths |
| 7 | + expect(convertToMentionPath("C:\\Users\\user\\project\\file.txt", "C:\\Users\\user\\project")).toBe( |
| 8 | + "@/file.txt", |
| 9 | + ) |
| 10 | + |
| 11 | + // Unix-style paths |
| 12 | + expect(convertToMentionPath("/Users/user/project/file.txt", "/Users/user/project")).toBe("@/file.txt") |
| 13 | + }) |
| 14 | + |
| 15 | + it("should handle paths with trailing slashes in cwd", () => { |
| 16 | + expect(convertToMentionPath("/Users/user/project/file.txt", "/Users/user/project/")).toBe("@/file.txt") |
| 17 | + }) |
| 18 | + |
| 19 | + it("should be case-insensitive when matching paths", () => { |
| 20 | + expect(convertToMentionPath("/Users/User/Project/file.txt", "/users/user/project")).toBe("@/file.txt") |
| 21 | + }) |
| 22 | + |
| 23 | + it("should return the original path when cwd is not provided", () => { |
| 24 | + expect(convertToMentionPath("/Users/user/project/file.txt")).toBe("/Users/user/project/file.txt") |
| 25 | + }) |
| 26 | + |
| 27 | + it("should return the original path when it does not start with cwd", () => { |
| 28 | + expect(convertToMentionPath("/Users/other/project/file.txt", "/Users/user/project")).toBe( |
| 29 | + "/Users/other/project/file.txt", |
| 30 | + ) |
| 31 | + }) |
| 32 | + |
| 33 | + it("should normalize backslashes to forward slashes", () => { |
| 34 | + expect(convertToMentionPath("C:\\Users\\user\\project\\subdir\\file.txt", "C:\\Users\\user\\project")).toBe( |
| 35 | + "@/subdir/file.txt", |
| 36 | + ) |
| 37 | + }) |
| 38 | + |
| 39 | + it("should handle nested paths correctly", () => { |
| 40 | + expect(convertToMentionPath("/Users/user/project/nested/deeply/file.txt", "/Users/user/project")).toBe( |
| 41 | + "@/nested/deeply/file.txt", |
| 42 | + ) |
| 43 | + }) |
| 44 | + }) |
| 45 | +}) |
0 commit comments