markdown-code-state.test.ts 747 B

1234567891011121314151617181920212223242526272829303132
  1. import { expect, test } from "bun:test"
  2. import { shouldResetCodeTokens } from "./markdown-code-state"
  3. const previous = {
  4. language: "ts",
  5. generation: 1,
  6. stableCount: 3,
  7. unstable: [],
  8. raw: "```ts\nconst x = 1\n```",
  9. }
  10. test("resets tokens for a non-prefix replacement with the same generation and token count", () => {
  11. expect(
  12. shouldResetCodeTokens(previous, {
  13. language: "ts",
  14. generation: 1,
  15. stableCount: 3,
  16. raw: "```ts\nlet y = 2\n```",
  17. }),
  18. ).toBe(true)
  19. })
  20. test("retains tokens for an append-only streaming update", () => {
  21. expect(
  22. shouldResetCodeTokens(previous, {
  23. language: "ts",
  24. generation: 1,
  25. stableCount: 4,
  26. raw: `${previous.raw}\nmore`,
  27. }),
  28. ).toBe(false)
  29. })