session-diff.test.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import { describe, expect, test } from "bun:test"
  2. import { normalize, text } from "./session-diff"
  3. describe("session diff", () => {
  4. test("keeps unified patch content", () => {
  5. const diff = {
  6. file: "a.ts",
  7. patch:
  8. "Index: a.ts\n===================================================================\n--- a.ts\t\n+++ a.ts\t\n@@ -1,2 +1,2 @@\n one\n-two\n+three\n",
  9. additions: 1,
  10. deletions: 1,
  11. status: "modified" as const,
  12. }
  13. const view = normalize(diff)
  14. expect(view.patch).toBe(diff.patch)
  15. expect(view.fileDiff.name).toBe("a.ts")
  16. expect(text(view, "deletions")).toBe("one\ntwo\n")
  17. expect(text(view, "additions")).toBe("one\nthree\n")
  18. })
  19. test("converts legacy content into a patch", () => {
  20. const diff = {
  21. file: "a.ts",
  22. before: "one\n",
  23. after: "two\n",
  24. additions: 1,
  25. deletions: 1,
  26. status: "modified" as const,
  27. }
  28. const view = normalize(diff)
  29. expect(view.patch).toContain("@@ -1,1 +1,1 @@")
  30. expect(text(view, "deletions")).toBe("one\n")
  31. expect(text(view, "additions")).toBe("two\n")
  32. })
  33. })