import { describe, expect, it } from "vitest"
import { getMathContent } from "@/lib/katex"

describe("getMathContent", () => {
  it("extracts content between $$ fences", () => {
    expect(getMathContent("$$\nE = mc^2\n$$")).toBe("E = mc^2")
  })

  it("returns empty string for unclosed opening fence", () => {
    expect(getMathContent("$$\nE = mc^2")).toBe("")
  })

  it("returns empty string for text without any fences", () => {
    expect(getMathContent("just math")).toBe("")
  })

  it("handles empty block ($$\\n$$) - exactly 2 lines", () => {
    expect(getMathContent("$$\n$$")).toBe("")
  })

  it("returns empty string for closing fence without opening", () => {
    expect(getMathContent("E = mc^2\n$$")).toBe("")
  })

  it("extracts multi-line content", () => {
    expect(getMathContent("$$\na\nb\nc\n$$")).toBe("a\nb\nc")
  })
})
