platform/packages/jael/jael_preprocessor/test/include_test.dart
2021-09-13 08:30:02 +08:00

49 lines
1.3 KiB
Dart

import 'package:angel3_code_buffer/angel3_code_buffer.dart';
import 'package:file/file.dart';
import 'package:file/memory.dart';
import 'package:jael3/jael3.dart' as jael;
import 'package:jael3_preprocessor/jael3_preprocessor.dart' as jael;
import 'package:belatuk_symbol_table/belatuk_symbol_table.dart';
import 'package:test/test.dart';
void main() {
late FileSystem fileSystem;
setUp(() {
fileSystem = MemoryFileSystem();
// a.jl
fileSystem.file('a.jl').writeAsStringSync('<b>a.jl</b>');
// b.jl
fileSystem.file('b.jl').writeAsStringSync('<i><include src="a.jl"></i>');
// c.jl
fileSystem.file('c.jl').writeAsStringSync('<u><include src="b.jl"></u>');
});
test('includes are expanded', () 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.resolveIncludes(original,
fileSystem.directory(fileSystem.currentDirectory), (e) => throw e);
var buf = CodeBuffer();
var scope = SymbolTable();
const jael.Renderer().render(processed!, buf, scope);
print(buf);
expect(
buf.toString(),
'''
<u>
<i>
<b>
a.jl
</b>
</i>
</u>
'''
.trim());
});
}