parse.test.ts 1023 B

123456789101112131415161718192021222324
  1. import { expect, test } from "bun:test"
  2. import { parseFileLineRange, parseSlashHead } from "../../src/prompt/parse"
  3. test("preserves file line-range parsing semantics", () => {
  4. expect([
  5. parseFileLineRange("src/app.ts#12-20"),
  6. parseFileLineRange("src/app.ts#12-"),
  7. parseFileLineRange("src/app.ts#12-12"),
  8. parseFileLineRange("src/app.ts#bad"),
  9. parseFileLineRange("src/app.ts"),
  10. ]).toEqual([
  11. { base: "src/app.ts", lineRange: { startLine: 12, endLine: 20 } },
  12. { base: "src/app.ts", lineRange: { startLine: 12, endLine: undefined } },
  13. { base: "src/app.ts", lineRange: { startLine: 12, endLine: undefined } },
  14. { base: "src/app.ts" },
  15. { base: "src/app.ts" },
  16. ])
  17. })
  18. test("keeps frontend-specific slash separators", () => {
  19. expect(parseSlashHead("/editor\rfirst")).toEqual({ name: "editor\rfirst", arguments: "", end: 13 })
  20. expect(parseSlashHead("/editor\rfirst", /\s/)).toEqual({ name: "editor", arguments: "first", end: 7 })
  21. expect(parseSlashHead("editor")).toBeUndefined()
  22. })