import { GFM, parser } from "@lezer/markdown"
import { describe, it } from "vitest"
import { createMarkdownExtensions } from "@/lib/markdown-extensions"

const markdownParser = parser.configure([GFM, ...createMarkdownExtensions()])

const tests = [
  "# Hello",
  "> quotes",
  "> [!NOTE] test",
  "  # Title",
  "TODO buy milk",
  "plain\n# heading on second line",
]

describe("Lezer AST structure", () => {
  for (const text of tests) {
    it(`parses: ${JSON.stringify(text).slice(0, 40)}`, () => {
      console.log(`\n=== ${JSON.stringify(text)} ===`)
      const tree = markdownParser.parse(text)
      tree.iterate({
        enter(node) {
          console.log("  ", node.type.name, "from:", node.from, "to:", node.to)
        },
      })
    })
  }
})
