part.test.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. import { describe, expect, test } from "bun:test"
  2. import { expandTrackedPastedText } from "../../src/prompt/part"
  3. describe("prompt part", () => {
  4. test("preserves wide characters around pasted text", () => {
  5. const marker = "[Pasted ~3 lines]"
  6. const prefix = "你好你好\n"
  7. expect(
  8. expandTrackedPastedText(prefix + marker + "\n阿斯顿法国红酒看来", [
  9. {
  10. start: Bun.stringWidth("你好你好") + 1,
  11. end: Bun.stringWidth("你好你好") + 1 + Bun.stringWidth(marker),
  12. text: "public:\n\tvoid ExecuteTask();\nprivate:",
  13. },
  14. ]),
  15. ).toBe("你好你好\npublic:\n\tvoid ExecuteTask();\nprivate:\n阿斯顿法国红酒看来")
  16. })
  17. test("only expands the tracked placeholder occurrence", () => {
  18. const marker = "[Pasted ~3 lines]"
  19. const prefix = `keep ${marker} then `
  20. expect(
  21. expandTrackedPastedText(prefix + marker + " tail", [
  22. {
  23. start: Bun.stringWidth(prefix),
  24. end: Bun.stringWidth(prefix + marker),
  25. text: "alpha\nbeta\ngamma",
  26. },
  27. ]),
  28. ).toBe(`keep ${marker} then alpha\nbeta\ngamma tail`)
  29. })
  30. })