platform/jael_preprocessor/test/block_test.dart

122 lines
3.4 KiB
Dart
Raw Normal View History

2017-09-30 05:27:31 +00:00
import 'package:code_buffer/code_buffer.dart';
import 'package:file/file.dart';
import 'package:file/memory.dart';
import 'package:jael/jael.dart' as jael;
import 'package:jael_preprocessor/jael_preprocessor.dart' as jael;
import 'package:symbol_table/symbol_table.dart';
import 'package:test/test.dart';
main() {
FileSystem fileSystem;
setUp(() {
fileSystem = new MemoryFileSystem();
// a.jl
fileSystem.file('a.jl').writeAsStringSync('<b>a.jl</b>');
// b.jl
fileSystem.file('b.jl').writeAsStringSync(
'<i><include src="a.jl"><block name="greeting"><p>Hello</p></block></i>');
// c.jl
fileSystem.file('c.jl').writeAsStringSync(
2017-10-01 03:14:44 +00:00
'<extend src="b.jl"><block name="greeting"><block name="greeting"></block>Goodbye</block></extend>');
2017-09-30 05:27:31 +00:00
// d.jl
fileSystem.file('d.jl').writeAsStringSync(
'<extend src="c.jl"><block name="greeting">Saluton!</block></extend>');
2018-07-15 20:41:43 +00:00
// e.jl
fileSystem.file('e.jl').writeAsStringSync(
2018-11-03 00:16:03 +00:00
'<extend src="c.jl"><block name="greeting">Angel <b><block name="name">default</block></b></block></extend>');
2018-07-15 20:41:43 +00:00
2018-11-03 00:16:03 +00:00
// fox.jl
fileSystem.file('fox.jl').writeAsStringSync(
'<block name="dance">The name is <block name="name"></block></block>');
// trot.jl
fileSystem.file('trot.jl').writeAsStringSync(
'<extend src="fox.jl"><block name="name">CONGA <i><block name="exclaim">YEAH</block></i></block></extend>');
// foxtrot.jl
fileSystem.file('foxtrot.jl').writeAsStringSync(
'<extend src="trot.jl"><block name="exclaim">framework</block></extend>');
2017-09-30 05:27:31 +00:00
});
test('blocks are replaced or kept', () async {
var file = fileSystem.file('c.jl');
var original = jael.parseDocument(await file.readAsString(),
sourceUrl: file.uri, onError: (e) => throw e);
var processed = await jael.resolve(
original, fileSystem.directory(fileSystem.currentDirectory),
onError: (e) => throw e);
var buf = new CodeBuffer();
var scope = new SymbolTable();
const jael.Renderer().render(processed, buf, scope);
print(buf);
2018-07-15 20:41:43 +00:00
expect(
buf.toString(),
'''
2017-09-30 05:27:31 +00:00
<i>
<b>
a.jl
</b>
Goodbye
</i>
2018-07-15 20:41:43 +00:00
'''
.trim());
2017-09-30 05:27:31 +00:00
});
2017-10-01 03:14:44 +00:00
test('block resolution is recursive', () async {
2017-09-30 05:27:31 +00:00
var file = fileSystem.file('d.jl');
var original = jael.parseDocument(await file.readAsString(),
sourceUrl: file.uri, onError: (e) => throw e);
var processed = await jael.resolve(
original, fileSystem.directory(fileSystem.currentDirectory),
onError: (e) => throw e);
var buf = new CodeBuffer();
var scope = new SymbolTable();
const jael.Renderer().render(processed, buf, scope);
print(buf);
2018-07-15 20:41:43 +00:00
expect(
buf.toString(),
'''
2017-09-30 05:27:31 +00:00
<i>
<b>
a.jl
</b>
2017-10-01 03:14:44 +00:00
Saluton!Goodbye
2017-09-30 05:27:31 +00:00
</i>
2018-07-15 20:41:43 +00:00
'''
.trim());
});
test('blocks within blocks', () async {
2018-11-03 00:16:03 +00:00
var file = fileSystem.file('foxtrot.jl');
2018-07-15 20:41:43 +00:00
var original = jael.parseDocument(await file.readAsString(),
sourceUrl: file.uri, onError: (e) => throw e);
var processed = await jael.resolve(
original, fileSystem.directory(fileSystem.currentDirectory),
onError: (e) => throw e);
var buf = new CodeBuffer();
var scope = new SymbolTable();
const jael.Renderer().render(processed, buf, scope);
print(buf);
expect(
buf.toString(),
'''
<i>
<b>
a.jl
</b>
Angel frameworkGoodbye
</i>
'''
.trim());
2017-09-30 05:27:31 +00:00
});
}