import { AreHTMLTokenizer } from '@adaas/are-html/tokenizer'; import { AreStaticAttribute } from '@adaas/are-html/attributes/AreStatic.attribute'; import { AreBindingAttribute } from '@adaas/are-html/attributes/AreBinding.attribute'; import { AreEventAttribute } from '@adaas/are-html/attributes/AreEvent.attribute'; import { AreDirectiveAttribute } from '@adaas/are-html/attributes/AreDirective.attribute'; import { AreHTMLEngine } from '@adaas/are-html/engine'; import { AreSyntaxTokenMatch } from '@adaas/are'; jest.retryTimes(0); // ───────────────────────────────────────────────────────────────────────────── // ── Helpers ─────────────────────────────────────────────────────────────────── // ───────────────────────────────────────────────────────────────────────────── /** * Returns a bare AreHTMLTokenizer instance without registering it in any scope, * sufficient for testing pure attribute-extraction logic. */ function makeTokenizer(): AreHTMLTokenizer { // Object.create skips the constructor, so instance properties aren't set. // Manually initialise ATTR_PATTERN (the only property extractAttributes needs). const t = Object.create(AreHTMLTokenizer.prototype) as AreHTMLTokenizer; t.ATTR_PATTERN = /([$:@]?[\w-]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>/"'=]+)))?/g; return t; } /** * Returns an AreHTMLEngine instance so we can call its protected matchers * directly without spinning up a full container. */ function makeEngine(): AreHTMLEngine { return Object.create(AreHTMLEngine.prototype) as AreHTMLEngine; } /** Minimal stub for the `build` callback required by the matcher methods. */ function buildStub( raw: string, content: string, position: number, closing: string, ): AreSyntaxTokenMatch { return { raw, content, position, closing, opening: '<', payload: {} } as unknown as AreSyntaxTokenMatch; } // ───────────────────────────────────────────────────────────────────────────── // ── AreHTMLTokenizer — extractAttributes ───────────────────────────────────── // ───────────────────────────────────────────────────────────────────────────── describe('AreHTMLTokenizer — extractAttributes', () => { it('parses plain static attributes', () => { const tokenizer = makeTokenizer(); const attrs = tokenizer.extractAttributes('
'); expect(attrs).toHaveLength(2); expect(attrs[0]).toBeInstanceOf(AreStaticAttribute); expect(attrs[0].name).toBe('class'); expect(attrs[0].content).toBe('dashboard'); expect(attrs[1]).toBeInstanceOf(AreStaticAttribute); expect(attrs[1].name).toBe('id'); expect(attrs[1].content).toBe('main'); }); it('parses a binding attribute prefixed with ":"', () => { const tokenizer = makeTokenizer(); const attrs = tokenizer.extractAttributes(''); expect(attrs).toHaveLength(1); expect(attrs[0]).toBeInstanceOf(AreBindingAttribute); expect(attrs[0].name).toBe('class'); expect(attrs[0].content).toBe('dynamicClass'); }); it('parses an event attribute prefixed with "@"', () => { const tokenizer = makeTokenizer(); const attrs = tokenizer.extractAttributes('