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;
|
2021-09-13 00:30:02 +00:00
|
|
|
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(
|
2018-11-10 21:37:00 +00:00
|
|
|
'<i><include src="a.jl" /><block name="greeting"><p>Hello</p></block></i>');
|
2017-09-30 05:27:31 +00:00
|
|
|
|
|
|
|
// c.jl
|
2018-11-10 21:37:00 +00:00
|
|
|
// NOTE: This SHOULD NOT produce "yes", because the only children expanded within an <extend>
|
|
|
|
// are <block>s.
|
2017-09-30 05:27:31 +00:00
|
|
|
fileSystem.file('c.jl').writeAsStringSync(
|
2018-11-10 17:43:39 +00:00
|
|
|
'<extend src="b.jl"><block name="greeting">Goodbye</block>Yes</extend>');
|
2017-09-30 05:27:31 +00:00
|
|
|
|
|
|
|
// d.jl
|
2018-11-10 21:37:00 +00:00
|
|
|
// This should not output "Yes", either.
|
|
|
|
// It should actually produce the same as c.jl, since it doesn't define any unique blocks.
|
2017-09-30 05:27:31 +00:00
|
|
|
fileSystem.file('d.jl').writeAsStringSync(
|
2018-11-10 17:43:39 +00:00
|
|
|
'<extend src="c.jl"><block name="greeting">Saluton!</block>Yes</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(
|
2018-11-10 21:37:00 +00:00
|
|
|
'<div><block name="dance">The name is <block name="name">default-name</block></block></div>');
|
2018-11-03 00:16:03 +00:00
|
|
|
|
|
|
|
// 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(),
|
2021-04-30 07:08:54 +00:00
|
|
|
sourceUrl: file.uri, onError: (e) => throw e)!;
|
|
|
|
var processed = await (jael.resolve(
|
2017-09-30 05:27:31 +00:00
|
|
|
original, fileSystem.directory(fileSystem.currentDirectory),
|
2021-04-30 07:08:54 +00:00
|
|
|
onError: (e) => throw e));
|
|
|
|
var buf = CodeBuffer();
|
|
|
|
var scope = SymbolTable();
|
|
|
|
const jael.Renderer().render(processed!, buf, scope);
|
2017-09-30 05:27:31 +00:00
|
|
|
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>
|
2018-11-10 21:37:00 +00:00
|
|
|
Goodbye
|
2017-09-30 05:27:31 +00:00
|
|
|
</i>
|
2018-07-15 20:41:43 +00:00
|
|
|
'''
|
|
|
|
.trim());
|
2017-09-30 05:27:31 +00:00
|
|
|
});
|
|
|
|
|
2018-11-10 21:37:00 +00:00
|
|
|
test('block defaults are emitted', () async {
|
|
|
|
var file = fileSystem.file('b.jl');
|
2017-09-30 05:27:31 +00:00
|
|
|
var original = jael.parseDocument(await file.readAsString(),
|
2021-04-30 07:08:54 +00:00
|
|
|
sourceUrl: file.uri, onError: (e) => throw e)!;
|
|
|
|
var processed = await (jael.resolve(
|
2017-09-30 05:27:31 +00:00
|
|
|
original, fileSystem.directory(fileSystem.currentDirectory),
|
2021-04-30 07:08:54 +00:00
|
|
|
onError: (e) => throw e));
|
|
|
|
var buf = CodeBuffer();
|
|
|
|
var scope = SymbolTable();
|
|
|
|
const jael.Renderer().render(processed!, buf, scope);
|
2017-09-30 05:27:31 +00:00
|
|
|
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>
|
2018-11-10 21:37:00 +00:00
|
|
|
<p>
|
|
|
|
Hello
|
|
|
|
</p>
|
2017-09-30 05:27:31 +00:00
|
|
|
</i>
|
2018-07-15 20:41:43 +00:00
|
|
|
'''
|
|
|
|
.trim());
|
|
|
|
});
|
|
|
|
|
2018-11-10 21:37:00 +00:00
|
|
|
test('block resolution only redefines blocks at one level at a time',
|
|
|
|
() async {
|
|
|
|
var file = fileSystem.file('d.jl');
|
2018-07-15 20:41:43 +00:00
|
|
|
var original = jael.parseDocument(await file.readAsString(),
|
2021-04-30 07:08:54 +00:00
|
|
|
sourceUrl: file.uri, onError: (e) => throw e)!;
|
|
|
|
var processed = await (jael.resolve(
|
2018-07-15 20:41:43 +00:00
|
|
|
original, fileSystem.directory(fileSystem.currentDirectory),
|
2021-04-30 07:08:54 +00:00
|
|
|
onError: (e) => throw e));
|
|
|
|
var buf = CodeBuffer();
|
|
|
|
var scope = SymbolTable();
|
|
|
|
const jael.Renderer().render(processed!, buf, scope);
|
2018-07-15 20:41:43 +00:00
|
|
|
print(buf);
|
|
|
|
|
|
|
|
expect(
|
|
|
|
buf.toString(),
|
|
|
|
'''
|
|
|
|
<i>
|
|
|
|
<b>
|
|
|
|
a.jl
|
|
|
|
</b>
|
2018-11-10 21:37:00 +00:00
|
|
|
Goodbye
|
2018-07-15 20:41:43 +00:00
|
|
|
</i>
|
|
|
|
'''
|
|
|
|
.trim());
|
2017-09-30 05:27:31 +00:00
|
|
|
});
|
2018-11-10 21:37:00 +00:00
|
|
|
|
|
|
|
test('blocks within blocks', () async {
|
|
|
|
var file = fileSystem.file('foxtrot.jl');
|
|
|
|
var original = jael.parseDocument(await file.readAsString(),
|
2021-04-30 07:08:54 +00:00
|
|
|
sourceUrl: file.uri, onError: (e) => throw e)!;
|
|
|
|
var processed = await (jael.resolve(
|
2018-11-10 21:37:00 +00:00
|
|
|
original, fileSystem.directory(fileSystem.currentDirectory),
|
2021-04-30 07:08:54 +00:00
|
|
|
onError: (e) => throw e));
|
|
|
|
var buf = CodeBuffer();
|
|
|
|
var scope = SymbolTable();
|
|
|
|
const jael.Renderer().render(processed!, buf, scope);
|
2018-11-10 21:37:00 +00:00
|
|
|
print(buf);
|
|
|
|
|
|
|
|
expect(
|
|
|
|
buf.toString(),
|
|
|
|
'''
|
|
|
|
<div>
|
|
|
|
The name is CONGA
|
|
|
|
<i>
|
|
|
|
framework
|
|
|
|
</i>
|
|
|
|
</div>
|
|
|
|
'''
|
|
|
|
.trim());
|
|
|
|
});
|
2017-09-30 05:27:31 +00:00
|
|
|
}
|