import dedent from "dedent" import { describe, test, beforeAll } from "vitest" import { Herb } from "@herb-tools/node-wasm" import { HTMLElementNode, HTMLOpenTagNode, HTMLCloseTagNode } from "@herb-tools/core" import { expectNodeToPrint, expectPrintRoundTrip, location, createToken, createTextNode } from "../helpers/printer-test-helpers.js" describe("HTMLElementNode Printing", () => { beforeAll(async () => { await Herb.load() }) test("prints simple HTML element", () => { expectPrintRoundTrip(`
`) }) test("prints HTML element with content", () => { expectPrintRoundTrip(`

Hello World

`) }) test("prints HTML element with attributes", () => { expectPrintRoundTrip(`
`) }) test("prints nested HTML elements", () => { expectPrintRoundTrip(dedent`

Title

Paragraph

`) }) test("prints HTML element with ERB content", () => { expectPrintRoundTrip(`

<%= @title %>

`) }) test("prints HTML element with ERB in attributes", () => { expectPrintRoundTrip(`
Content
`) }) test("can print from node", () => { const open_tag = HTMLOpenTagNode.build({ location, tag_opening: createToken("TOKEN_HTML_TAG_START", "<"), tag_name: createToken("TOKEN_IDENTIFIER", "a"), tag_closing: createToken("TOKEN_HTML_TAG_END", ">"), children: [], is_void: true }) const close_tag = HTMLCloseTagNode.build({ location, tag_opening: createToken("TOKEN_HTML_TAG_START_CLOSE", "") }) const node = HTMLElementNode.build({ location, open_tag, tag_name: createToken("TOKEN_IDENTIFIER", "a"), body: [ createTextNode("Click me") ], close_tag, is_void: false }) expectNodeToPrint(node, "Click me") }) test("can print from source", () => { expectPrintRoundTrip(`

Element

`) }) })