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(); jael.Document document; SymbolTable scope; try { document = jael.parseDocument(template, sourceUrl: 'test.jl'); scope = new SymbolTable(values: { 'csrf_token': 'foo', 'profile': { 'avatar': 'thosakwe.png', } }); } on jael.JaelError catch (e) { print(e); print(e.stackTrace); } expect(document, isNotNull); 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().replaceAll('\n', '').replaceAll(' ', '').trim(), '''

Pokémon

Darkrai - Dark ''' .replaceAll('\n', '') .replaceAll(' ', '') .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().replaceAll('\n', '').replaceAll(' ', '').trim(), '''
''' .replaceAll('\n', '') .replaceAll(' ', '') .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()); }); test('switch', () { const template = ''' BAN HAMMER LOLOL You are in good standing. Weird... '''; var buf = new CodeBuffer(); var document = jael.parseDocument(template, sourceUrl: 'test.jl'); var scope = new SymbolTable(values: { 'account': new _Account(isDisabled: true), }); const jael.Renderer().render(document, buf, scope); print(buf); expect(buf.toString().trim(), 'BAN HAMMER LOLOL'); }); test('default', () { const template = ''' BAN HAMMER LOLOL You are in good standing. Weird... '''; var buf = new CodeBuffer(); var document = jael.parseDocument(template, sourceUrl: 'test.jl'); var scope = new SymbolTable(values: { 'account': new _Account(isDisabled: null), }); const jael.Renderer().render(document, buf, scope); print(buf); expect(buf.toString().trim(), 'Weird...'); }); } 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); } class _Account { final bool isDisabled; _Account({this.isDisabled}); }