platform/packages/jael/jael_preprocessor/test/include_test.dart

50 lines
1.3 KiB
Dart
Raw Normal View History

2021-09-25 06:32:32 +00:00
import 'package:belatuk_code_buffer/belatuk_code_buffer.dart';
2017-09-30 05:27:31 +00:00
import 'package:file/file.dart';
import 'package:file/memory.dart';
2021-05-15 10:28:09 +00:00
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';
2017-09-30 05:27:31 +00:00
import 'package:test/test.dart';
2021-05-15 10:28:09 +00:00
void main() {
2021-04-30 07:08:54 +00:00
late FileSystem fileSystem;
2017-09-30 05:27:31 +00:00
setUp(() {
2021-04-30 07:08:54 +00:00
fileSystem = MemoryFileSystem();
2017-09-30 05:27:31 +00:00
// 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(),
2021-04-30 07:08:54 +00:00
sourceUrl: file.uri, onError: (e) => throw e)!;
2017-09-30 05:27:31 +00:00
var processed = await jael.resolveIncludes(original,
fileSystem.directory(fileSystem.currentDirectory), (e) => throw e);
2021-04-30 07:08:54 +00:00
var buf = CodeBuffer();
var scope = SymbolTable();
const jael.Renderer().render(processed!, buf, scope);
2017-09-30 05:27:31 +00:00
print(buf);
expect(
buf.toString(),
'''
<u>
<i>
<b>
a.jl
</b>
</i>
</u>
'''
.trim());
});
}