import { describe, it, expect } from "vitest"; import { Tokenizer } from "./index.js"; import type { Callbacks } from "./Tokenizer.js"; function tokenize(data: string, options = {}) { const log: unknown[][] = []; const tokenizer = new Tokenizer( options, new Proxy( {}, { get(_, property) { return (...values: unknown[]) => log.push([property, ...values]); }, }, ) as Callbacks, ); tokenizer.write(data); tokenizer.end(); return log; } describe("Tokenizer", () => { describe("should support self-closing special tags", () => { it("for self-closing script tag", () => { expect(tokenize("
")).toMatchSnapshot(); }); it("for normal style tag", () => { expect(tokenize("
")).toMatchSnapshot(); }); it("for normal sitle tag", () => { expect(tokenize("
")).toMatchSnapshot(); }); it("for normal textarea tag", () => { expect( tokenize("
"), ).toMatchSnapshot(); }); it("for normal xmp tag", () => { expect(tokenize("
")).toMatchSnapshot(); }); }); describe("should treat html inside special tags as text", () => { it("for div inside script tag", () => { expect(tokenize("")).toMatchSnapshot(); }); it("for div inside style tag", () => { expect(tokenize("")).toMatchSnapshot(); }); it("for div inside title tag", () => { expect(tokenize("<div></div>")).toMatchSnapshot(); }); it("for div inside textarea tag", () => { expect( tokenize(""), ).toMatchSnapshot(); }); it("for div inside xmp tag", () => { expect(tokenize("<div></div>")).toMatchSnapshot(); }); }); describe("should correctly mark attributes", () => { it("for no value attribute", () => { expect(tokenize("
")).toMatchSnapshot(); }); it("for no quotes attribute", () => { expect(tokenize("
")).toMatchSnapshot(); }); it("for single quotes attribute", () => { expect(tokenize("
")).toMatchSnapshot(); }); it("for double quotes attribute", () => { expect(tokenize('
')).toMatchSnapshot(); }); }); describe("should not break after special tag followed by an entity", () => { it("for normal special tag", () => { expect(tokenize("'
")).toMatchSnapshot(); }); it("for self-closing special tag", () => { expect(tokenize("