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();
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
- {{ starter.name }} - {{ starter.type }}
''';
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
-
Bulbasaur - Grass
-
Charmander - Fire
-
Squirtle - Water
'''
.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());
});
}
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);
}