import dedent from "dedent"
import { describe, it, expect, beforeAll } from "vitest"
import { Herb, getTagName } from "@herb-tools/node-wasm"
import { RootElementCollector } from "../src/root_element_collector"
import { ParserService } from "../src/parser_service"
describe("RootElementCollector", () => {
let parserService: ParserService
beforeAll(async () => {
await Herb.load()
parserService = new ParserService(Herb)
})
function collect(source: string): RootElementCollector {
const result = parserService.parseContent(source)
const collector = new RootElementCollector()
collector.visit(result.value)
return collector
}
function tagName(source: string): string | null {
return getTagName(collect(source).element)
}
it("collects the only element", () => {
expect(tagName(`
`)).toBe("img")
})
it("is null without any element", () => {
expect(collect(`<%= @user.name %>`).element).toBeNull()
})
it("is null for an empty document", () => {
expect(collect(``).element).toBeNull()
})
})