import 'package:code_buffer/code_buffer.dart'; import 'package:jael/jael.dart' as jael; import 'package:symbol_table/symbol_table.dart'; import 'package:test/test.dart'; main() { test('attribute binding', () { const template = '''

Hello

'''; var buf = new CodeBuffer(); var document = jael.parseDocument(template, sourceUrl: 'test.jl'); var scope = new SymbolTable(values: { 'profile': { 'avatar': 'thosakwe.png', } }); const jael.Renderer().render(document, buf, scope); print(buf); expect( buf.toString(), '''

Hello

''' .trim()); }); test('interpolation', () { const template = '''

Pokémon

{{ pokemon.name }} - {{ pokemon.type }} '''; var buf = new CodeBuffer(); //jael.scan(template, sourceUrl: 'test.jl').tokens.forEach(print); var document = jael.parseDocument(template, sourceUrl: 'test.jl'); var scope = new SymbolTable(values: { 'pokemon': const _Pokemon('Darkrai', 'Dark'), }); const jael.Renderer().render(document, buf, scope); print(buf); expect( buf.toString(), '''

Pokémon

Darkrai - Dark ''' .trim()); }); test('for loop', () { const template = '''

Pokémon

'''; var buf = new CodeBuffer(); var document = jael.parseDocument(template, sourceUrl: 'test.jl'); var scope = new SymbolTable(values: { 'starters': starters, }); const jael.Renderer().render(document, buf, scope); print(buf); expect( buf.toString(), '''

Pokémon

''' .trim()); }); test('conditional', () { const template = '''

Conditional

Empty Not empty '''; var buf = new CodeBuffer(); var document = jael.parseDocument(template, sourceUrl: 'test.jl'); var scope = new SymbolTable(values: { 'starters': starters, }); const jael.Renderer().render(document, buf, scope); print(buf); expect( buf.toString(), '''

Conditional

Not empty ''' .trim()); }); test('declare', () { const template = '''
'''; var buf = new CodeBuffer(); var document = jael.parseDocument(template, sourceUrl: 'test.jl'); var scope = new SymbolTable(); const jael.Renderer().render(document, buf, scope); print(buf); expect( buf.toString(), '''
''' .trim()); }); test('unescaped attr/interp', () { const template = '''
{{- "" }}
'''; var buf = new CodeBuffer(); var document = jael.parseDocument(template, sourceUrl: 'test.jl'); var scope = new SymbolTable(); const jael.Renderer().render(document, buf, scope); print(buf); expect( buf.toString(), '''
''' .trim()); }); test('quoted attribute name', () { const template = ''' '''; var buf = new CodeBuffer(); var document = jael.parseDocument(template, sourceUrl: 'test.jl'); var scope = new SymbolTable(); const jael.Renderer().render(document, buf, scope); print(buf); expect( buf.toString(), ''' ''' .trim()); }); } const List<_Pokemon> starters = const [ const _Pokemon('Bulbasaur', 'Grass'), const _Pokemon('Charmander', 'Fire'), const _Pokemon('Squirtle', 'Water'), ]; class _Pokemon { final String name, type; const _Pokemon(this.name, this.type); }