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

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

describe("Lezer AST debug", () => {
  const testCases = [
    "# Hello",
    "  # Title",
    "> Quote text",
    "> [!NOTE] test",
    "TODO buy milk",
    "first line\nTODO buy milk",
    "some text\n\n#tag more text",
    "**bold**",
  ]

  for (const text of testCases) {
    it(`logs AST for: ${JSON.stringify(text).slice(0, 40)}`, () => {
      console.log(`\n--- Parsing: ${JSON.stringify(text)} ---`)
      const tree = markdownParser.parse(text)
      tree.iterate({
        enter(node) {
          console.log(
            `${"  ".repeat(node.type.isTop ? 0 : 1)}${node.name} [${node.from}-${node.to}] "${text.slice(node.from, node.to)}"`,
          )
        },
      })
    })
  }
})
