import { describe, it, expect } from 'bun:test'; import { parseTemplate } from '../src/engine/parser'; describe('Template Parser', () => { it('should parse simple text template', () => { const yaml = ` name: "Test Template" id: "test" width: 80mm blocks: - type: text content: "Hello World" align: center `; const template = parseTemplate(yaml); expect(template.name).toBe('Test Template'); expect(template.blocks).toHaveLength(1); expect(template.blocks[0].type).toBe('text'); expect((template.blocks[0] as any).content).toBe('Hello World'); }); it('should parse row with columns', () => { const yaml = ` name: "Row Test" id: "row-test" width: 80mm blocks: - type: row columns: - content: "Left" align: left width: 50% - content: "Right" align: right width: 50% `; const template = parseTemplate(yaml); const row = template.blocks[0] as any; expect(row.type).toBe('row'); expect(row.columns).toHaveLength(2); expect(row.columns[0].align).toBe('left'); }); it('should parse list with item template', () => { const yaml = ` name: "List Test" id: "list-test" width: 80mm blocks: - type: list data: "{{items}}" itemTemplate: - type: text content: "{{name}}" `; const template = parseTemplate(yaml); const list = template.blocks[0] as any; expect(list.type).toBe('list'); expect(list.data).toBe('{{items}}'); expect(list.itemTemplate).toHaveLength(1); }); it('should throw on invalid YAML', () => { const yaml = 'invalid: [unclosed'; expect(() => parseTemplate(yaml)).toThrow(); }); });