| 1 | import { extractPathsFromCodeBlocks } from "./extractPathsFromCodeBlocks"; |
| 2 | |
| 3 | describe("extractPathsFromCodeBlocks", () => { |
| 4 | it("should extract paths from code blocks with language and filepath", () => { |
| 5 | const content = "```typescript src/main.ts\nconst x = 1;\n```"; |
| 6 | expect(extractPathsFromCodeBlocks(content)).toEqual(["src/main.ts"]); |
| 7 | }); |
| 8 | |
| 9 | it("should extract paths from code blocks with filepath only (no language)", () => { |
| 10 | const content = "```test.js\nclass Calculator { }\n```"; |
| 11 | expect(extractPathsFromCodeBlocks(content)).toEqual(["test.js"]); |
| 12 | }); |
| 13 | |
| 14 | it("should extract paths from code blocks with line ranges", () => { |
| 15 | const content = "```js test.js (19-25)\nfunction test() {}\n```"; |
| 16 | expect(extractPathsFromCodeBlocks(content)).toEqual(["test.js"]); |
| 17 | }); |
| 18 | |
| 19 | it("should handle multiple code blocks with different formats", () => { |
| 20 | const content = |
| 21 | "```typescript src/main.ts\nconst x = 1;\n```\n" + |
| 22 | "```test.js\nclass Calculator { }\n```\n" + |
| 23 | "```js utils.js (19-25)\nfunction test() {}\n```"; |
| 24 | const result = extractPathsFromCodeBlocks(content); |
| 25 | expect(result).toContain("src/main.ts"); |
| 26 | expect(result).toContain("test.js"); |
| 27 | expect(result).toContain("utils.js"); |
| 28 | expect(result.length).toBe(3); |
| 29 | }); |
| 30 | |
| 31 | it("should not extract paths from code blocks without file paths", () => { |
| 32 | const content = "```typescript\nconst x = 1;\n```"; |
| 33 | expect(extractPathsFromCodeBlocks(content)).toEqual([]); |
| 34 | }); |
| 35 | }); |