platform/packages/code_buffer/test/write_test.dart

88 lines
1.9 KiB
Dart
Raw Normal View History

2021-03-16 00:14:28 +00:00
import 'package:charcode/charcode.dart';
import 'package:test/test.dart';
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
main() {
2021-05-14 03:06:32 +00:00
var buf = CodeBuffer();
2021-03-16 00:14:28 +00:00
tearDown(buf.clear);
test('writeCharCode', () {
buf.writeCharCode($x);
expect(buf.toString(), 'x');
});
test('write', () {
buf.write('hello world');
expect(buf.toString(), 'hello world');
});
test('custom space', () {
2021-05-14 03:06:32 +00:00
var b = CodeBuffer(space: '+')
2021-03-16 00:14:28 +00:00
..writeln('foo')
..indent()
..writeln('baz');
expect(b.toString(), 'foo\n+baz');
});
test('custom newline', () {
2021-05-14 03:06:32 +00:00
var b = CodeBuffer(newline: 'N')
2021-03-16 00:14:28 +00:00
..writeln('foo')
..indent()
..writeln('baz');
expect(b.toString(), 'fooN baz');
});
test('trailing newline', () {
2021-05-14 03:06:32 +00:00
var b = CodeBuffer(trailingNewline: true)..writeln('foo');
2021-03-16 00:14:28 +00:00
expect(b.toString(), 'foo\n');
});
group('multiple lines', () {
setUp(() {
buf..writeln('foo')..writeln('bar')..writeln('baz');
expect(buf.lines, hasLength(3));
expect(buf.lines[0].text, 'foo');
expect(buf.lines[1].text, 'bar');
expect(buf.lines[2].text, 'baz');
});
});
test('indent', () {
buf
..writeln('foo')
..indent()
..writeln('bar')
..indent()
..writeln('baz')
..outdent()
..writeln('quux')
..outdent()
..writeln('end');
expect(buf.toString(), 'foo\n bar\n baz\n quux\nend');
});
group('sets lastLine text', () {
test('writeCharCode', () {
buf.writeCharCode($x);
expect(buf.lastLine!.text, 'x');
});
test('write', () {
buf.write('hello world');
expect(buf.lastLine!.text, 'hello world');
});
});
group('sets lastLine lastSpan', () {
test('writeCharCode', () {
buf.writeCharCode($x);
expect(buf.lastLine!.lastSpan!.text, 'x');
});
test('write', () {
buf.write('hello world');
expect(buf.lastLine!.lastSpan!.text, 'hello world');
});
});
}