display.test.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233
  1. import { describe, expect, test } from "bun:test"
  2. import { displayCharAt, displaySlice, mentionTriggerIndex } from "../../src/prompt/display"
  3. describe("prompt display", () => {
  4. test("uses display-width offsets for mentions", () => {
  5. expect(mentionTriggerIndex("@")).toBe(0)
  6. expect(mentionTriggerIndex("test @")).toBe(5)
  7. expect(mentionTriggerIndex("中文 @")).toBe(5)
  8. expect(mentionTriggerIndex("こんにちは @")).toBe(11)
  9. expect(mentionTriggerIndex("한국어 @")).toBe(7)
  10. expect(mentionTriggerIndex("🙂 @")).toBe(3)
  11. expect(mentionTriggerIndex("中文 @src file", Bun.stringWidth("中文 @src"))).toBe(5)
  12. expect(displayCharAt("中文 @src", Bun.stringWidth("中文 @"))).toBe("s")
  13. expect(displaySlice("中文 @src", 5, Bun.stringWidth("中文 @src"))).toBe("@src")
  14. expect(displaySlice("中文 @src", 6, Bun.stringWidth("中文 @src"))).toBe("src")
  15. expect(mentionTriggerIndex("👨‍👩‍👧‍👦 @src", Bun.stringWidth("👨‍👩‍👧‍👦 @src"))).toBe(3)
  16. expect(displayCharAt("👨‍👩‍👧‍👦 @src", Bun.stringWidth("👨‍👩‍👧‍👦 @"))).toBe("s")
  17. expect(displaySlice("👨‍👩‍👧‍👦 @src", 3, Bun.stringWidth("👨‍👩‍👧‍👦 @src"))).toBe("@src")
  18. expect(mentionTriggerIndex("@file1\n@file2", 13)).toBe(7)
  19. expect(displayCharAt("@file1\n@file2", 6)).toBe("\n")
  20. expect(displaySlice("@file1\n@file2", 8, 13)).toBe("file2")
  21. expect(mentionTriggerIndex("@file1\nfoo @file2", 17)).toBe(11)
  22. expect(mentionTriggerIndex("中文 @one\n@two", 14)).toBe(10)
  23. expect(displaySlice("中文 @one\n@two", 11, 14)).toBe("two")
  24. expect(mentionTriggerIndex("中文@")).toBeUndefined()
  25. expect(mentionTriggerIndex("こんにちは@")).toBeUndefined()
  26. expect(mentionTriggerIndex("한국어@")).toBeUndefined()
  27. expect(mentionTriggerIndex("🙂@")).toBeUndefined()
  28. expect(mentionTriggerIndex("hello@")).toBeUndefined()
  29. expect(mentionTriggerIndex("foo@bar.com")).toBeUndefined()
  30. expect(mentionTriggerIndex("中文 @src file")).toBeUndefined()
  31. })
  32. })