platform/packages/jael/jael2/test/render/dsx_test.dart

44 lines
1.1 KiB
Dart
Raw Normal View History

2018-06-26 15:29:03 +00:00
import 'package:jael/jael.dart';
import 'package:symbol_table/symbol_table.dart';
import 'package:test/test.dart';
void main() {
test('attributes', () {
var doc = parseDSX('''
<foo bar="baz" yes={no} />
2021-04-28 00:37:33 +00:00
''')!;
2018-06-26 15:29:03 +00:00
var foo = doc.root as SelfClosingElement;
expect(foo.tagName.name, 'foo');
expect(foo.attributes, hasLength(2));
expect(foo.getAttribute('bar'), isNotNull);
expect(foo.getAttribute('yes'), isNotNull);
2021-04-28 00:37:33 +00:00
expect(foo.getAttribute('bar')?.value?.compute(null), 'baz');
2018-06-26 15:29:03 +00:00
expect(
foo
2021-04-29 07:21:31 +00:00
.getAttribute('yes')
?.value
?.compute(SymbolTable(values: {'no': 'maybe'})),
2018-06-26 15:29:03 +00:00
'maybe');
});
test('children', () {
var doc = parseDSX('''
<foo bar="baz" yes={no}>
<bar>{24 * 3}</bar>
</foo>
2021-04-28 00:37:33 +00:00
''')!;
2018-06-26 15:29:03 +00:00
var bar = doc.root.children.first as RegularElement;
expect(bar.tagName.name, 'bar');
var interpolation = bar.children.first as Interpolation;
expect(interpolation.expression.compute(null), 24 * 3);
});
}
2021-04-28 00:37:33 +00:00
Document? parseDSX(String text) {
2018-06-26 15:29:03 +00:00
return parseDocument(text,
sourceUrl: 'test.dsx', asDSX: true, onError: (e) => throw e);
}