platform/packages/code_buffer/test/copy_test.dart

46 lines
1 KiB
Dart
Raw Normal View History

2021-05-14 03:06:32 +00:00
import 'package:angel3_code_buffer/angel3_code_buffer.dart';
2021-03-16 00:14:28 +00:00
import 'package:test/test.dart';
2021-05-14 03:06:32 +00:00
void main() {
var a = CodeBuffer(), b = CodeBuffer();
2021-03-16 00:14:28 +00:00
setUp(() {
a.writeln('outer block 1');
b..writeln('inner block 1')..writeln('inner block 2');
b.copyInto(a..indent());
a
..outdent()
..writeln('outer block 2');
});
tearDown(() {
a.clear();
b.clear();
});
test('sets correct text', () {
expect(
a.toString(),
[
'outer block 1',
' inner block 1',
' inner block 2',
'outer block 2',
].join('\n'));
});
test('sets lastLine+lastSpan', () {
2021-05-14 03:06:32 +00:00
var c = CodeBuffer()
2021-03-16 00:14:28 +00:00
..indent()
..write('>')
..writeln('innermost');
c.copyInto(a);
expect(a.lastLine!.text, '>innermost');
expect(a.lastLine!.span.start.column, 2);
expect(a.lastLine!.lastSpan!.start.line, 4);
expect(a.lastLine!.lastSpan!.start.column, 3);
expect(a.lastLine!.lastSpan!.end.line, 4);
expect(a.lastLine!.lastSpan!.end.column, 12);
});
}