import { describe, test, expect, beforeAll } from "vitest" import { Herb } from "@herb-tools/node-wasm" import { IdentityPrinter } from "../src/index.js" describe("IdentityPrinter", () => { beforeAll(async () => { await Herb.load() }) function expectPrintRoundTrip(input: string, description: string) { test(description, () => { const parseResult = Herb.parse(input, { track_whitespace: true }) expect(parseResult.value).toBeTruthy() const printer = new IdentityPrinter() const output = printer.print(parseResult.value!) expect(output).toBe(input) }) } describe("Basic functionality", () => { test("is defined", () => { expect(IdentityPrinter).toBeDefined() }) test("can be instantiated", () => { const printer = new IdentityPrinter() expect(printer).toBeInstanceOf(IdentityPrinter) }) test("static print method works", () => { const input = '
Test paragraph
' const parseResult = Herb.parse(input, { track_whitespace: true }) expect(parseResult.value).toBeTruthy() const printer = new IdentityPrinter() const instanceOutput = printer.print(parseResult.value!) const staticOutput = IdentityPrinter.print(parseResult.value!) expect(staticOutput).toBe(instanceOutput) expect(staticOutput).toBe(input) }) test("static print method respects options", () => { const input = 'Simple paragraph
', 'simple paragraph') expectPrintRoundTrip('Inline text', 'simple span') expectPrintRoundTrip('Nested content
Deep nesting
', 'img tag with attributes')
expectPrintRoundTrip('Preformatted\n Text', 'preformatted whitespace') expectPrintRoundTrip('
const x = 5; ', 'code with spaces')
expectPrintRoundTrip('