2
This commit is contained in:
1 parent
9fbb414ee6
commit
4554f22c87
233 files changed
+147430
-605
No files matched your search
@@ -0,0 +1,609 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:path/path.dart';
|
||||
import 'package:re_editor/re_editor.dart';
|
||||
|
||||
void main() {
|
||||
const DefaultCodeChunkAnalyzer analyzer = DefaultCodeChunkAnalyzer();
|
||||
group('DefaultCodeChunkAnalyzer.parse()', () {
|
||||
test('A single code line with empty content', () {
|
||||
{
|
||||
final CodeLines codeLines = CodeLines.of([
|
||||
CodeLine.empty
|
||||
]);
|
||||
expect(analyzer.parse(codeLines), const []);
|
||||
}
|
||||
});
|
||||
test('A single code line without quota', () {
|
||||
{
|
||||
final CodeLines codeLines = CodeLines.of(const [
|
||||
CodeLine('abc')
|
||||
]);
|
||||
expect(analyzer.parse(codeLines), const []);
|
||||
}
|
||||
{
|
||||
final CodeLines codeLines = CodeLines.of(const [
|
||||
CodeLine('(')
|
||||
]);
|
||||
expect(analyzer.parse(codeLines), const [
|
||||
CodeChunkSymbol('(', 0)
|
||||
]);
|
||||
}
|
||||
{
|
||||
final CodeLines codeLines = CodeLines.of(const [
|
||||
CodeLine(')')
|
||||
]);
|
||||
expect(analyzer.parse(codeLines), const [
|
||||
CodeChunkSymbol(')', 0)
|
||||
]);
|
||||
}
|
||||
{
|
||||
final CodeLines codeLines = CodeLines.of(const [
|
||||
CodeLine('[')
|
||||
]);
|
||||
expect(analyzer.parse(codeLines), const [
|
||||
CodeChunkSymbol('[', 0)
|
||||
]);
|
||||
}
|
||||
{
|
||||
final CodeLines codeLines = CodeLines.of(const [
|
||||
CodeLine(']')
|
||||
]);
|
||||
expect(analyzer.parse(codeLines), const [
|
||||
CodeChunkSymbol(']', 0)
|
||||
]);
|
||||
}
|
||||
{
|
||||
final CodeLines codeLines = CodeLines.of(const [
|
||||
CodeLine('{')
|
||||
]);
|
||||
expect(analyzer.parse(codeLines), const [
|
||||
CodeChunkSymbol('{', 0)
|
||||
]);
|
||||
}
|
||||
{
|
||||
final CodeLines codeLines = CodeLines.of(const [
|
||||
CodeLine('}')
|
||||
]);
|
||||
expect(analyzer.parse(codeLines), const [
|
||||
CodeChunkSymbol('}', 0)
|
||||
]);
|
||||
}
|
||||
{
|
||||
final CodeLines codeLines = CodeLines.of(const [
|
||||
CodeLine('()')
|
||||
]);
|
||||
expect(analyzer.parse(codeLines), const [
|
||||
CodeChunkSymbol('(', 0),
|
||||
CodeChunkSymbol(')', 0)
|
||||
]);
|
||||
}
|
||||
{
|
||||
final CodeLines codeLines = CodeLines.of(const [
|
||||
CodeLine('[]')
|
||||
]);
|
||||
expect(analyzer.parse(codeLines), const [
|
||||
CodeChunkSymbol('[', 0),
|
||||
CodeChunkSymbol(']', 0)
|
||||
]);
|
||||
}
|
||||
{
|
||||
final CodeLines codeLines = CodeLines.of(const [
|
||||
CodeLine('{}')
|
||||
]);
|
||||
expect(analyzer.parse(codeLines), const [
|
||||
CodeChunkSymbol('{', 0),
|
||||
CodeChunkSymbol('}', 0)
|
||||
]);
|
||||
}
|
||||
{
|
||||
final CodeLines codeLines = CodeLines.of(const [
|
||||
CodeLine('()[]{}')
|
||||
]);
|
||||
expect(analyzer.parse(codeLines), const [
|
||||
CodeChunkSymbol('(', 0),
|
||||
CodeChunkSymbol(')', 0),
|
||||
CodeChunkSymbol('[', 0),
|
||||
CodeChunkSymbol(']', 0),
|
||||
CodeChunkSymbol('{', 0),
|
||||
CodeChunkSymbol('}', 0)
|
||||
]);
|
||||
}
|
||||
{
|
||||
final CodeLines codeLines = CodeLines.of(const [
|
||||
CodeLine('123{[foo]((abc))[[]]{{bar}}()}')
|
||||
]);
|
||||
expect(analyzer.parse(codeLines), const [
|
||||
CodeChunkSymbol('{', 0),
|
||||
CodeChunkSymbol('[', 0),
|
||||
CodeChunkSymbol(']', 0),
|
||||
CodeChunkSymbol('(', 0),
|
||||
CodeChunkSymbol('(', 0),
|
||||
CodeChunkSymbol(')', 0),
|
||||
CodeChunkSymbol(')', 0),
|
||||
CodeChunkSymbol('[', 0),
|
||||
CodeChunkSymbol('[', 0),
|
||||
CodeChunkSymbol(']', 0),
|
||||
CodeChunkSymbol(']', 0),
|
||||
CodeChunkSymbol('{', 0),
|
||||
CodeChunkSymbol('{', 0),
|
||||
CodeChunkSymbol('}', 0),
|
||||
CodeChunkSymbol('}', 0),
|
||||
CodeChunkSymbol('(', 0),
|
||||
CodeChunkSymbol(')', 0),
|
||||
CodeChunkSymbol('}', 0),
|
||||
]);
|
||||
}
|
||||
});
|
||||
|
||||
test('A single code line with quotas', () {
|
||||
{
|
||||
final CodeLines codeLines = CodeLines.of(const [
|
||||
CodeLine('"')
|
||||
]);
|
||||
expect(analyzer.parse(codeLines), const []);
|
||||
}
|
||||
{
|
||||
final CodeLines codeLines = CodeLines.of(const [
|
||||
CodeLine('\'')
|
||||
]);
|
||||
expect(analyzer.parse(codeLines), const []);
|
||||
}
|
||||
{
|
||||
final CodeLines codeLines = CodeLines.of(const [
|
||||
CodeLine('\\"\\"')
|
||||
]);
|
||||
expect(analyzer.parse(codeLines), const []);
|
||||
}
|
||||
{
|
||||
final CodeLines codeLines = CodeLines.of(const [
|
||||
CodeLine('\\\'\\\'')
|
||||
]);
|
||||
expect(analyzer.parse(codeLines), const []);
|
||||
}
|
||||
{
|
||||
final CodeLines codeLines = CodeLines.of(const [
|
||||
CodeLine('"abc"')
|
||||
]);
|
||||
expect(analyzer.parse(codeLines), const []);
|
||||
}
|
||||
{
|
||||
final CodeLines codeLines = CodeLines.of(const [
|
||||
CodeLine('\'abc\'')
|
||||
]);
|
||||
expect(analyzer.parse(codeLines), const []);
|
||||
}
|
||||
{
|
||||
final CodeLines codeLines = CodeLines.of(const [
|
||||
CodeLine('"\'abc\'"')
|
||||
]);
|
||||
expect(analyzer.parse(codeLines), const []);
|
||||
}
|
||||
{
|
||||
final CodeLines codeLines = CodeLines.of(const [
|
||||
CodeLine('"("')
|
||||
]);
|
||||
expect(analyzer.parse(codeLines), const []);
|
||||
}
|
||||
{
|
||||
final CodeLines codeLines = CodeLines.of(const [
|
||||
CodeLine('\'(\'')
|
||||
]);
|
||||
expect(analyzer.parse(codeLines), const []);
|
||||
}
|
||||
{
|
||||
final CodeLines codeLines = CodeLines.of(const [
|
||||
CodeLine('"()[]{}"')
|
||||
]);
|
||||
expect(analyzer.parse(codeLines), const []);
|
||||
}
|
||||
{
|
||||
final CodeLines codeLines = CodeLines.of(const [
|
||||
CodeLine('\'()[]{}\'')
|
||||
]);
|
||||
expect(analyzer.parse(codeLines), const []);
|
||||
}
|
||||
{
|
||||
final CodeLines codeLines = CodeLines.of(const [
|
||||
CodeLine('"\'()[]{}\'"')
|
||||
]);
|
||||
expect(analyzer.parse(codeLines), const []);
|
||||
}
|
||||
{
|
||||
final CodeLines codeLines = CodeLines.of(const [
|
||||
CodeLine('\\"\'()[]{}\'\\"')
|
||||
]);
|
||||
expect(analyzer.parse(codeLines), const []);
|
||||
}
|
||||
{
|
||||
final CodeLines codeLines = CodeLines.of(const [
|
||||
CodeLine('""(')
|
||||
]);
|
||||
expect(analyzer.parse(codeLines), const [
|
||||
CodeChunkSymbol('(', 0),
|
||||
]);
|
||||
}
|
||||
{
|
||||
final CodeLines codeLines = CodeLines.of(const [
|
||||
CodeLine('""(""')
|
||||
]);
|
||||
expect(analyzer.parse(codeLines), const [
|
||||
CodeChunkSymbol('(', 0),
|
||||
]);
|
||||
}
|
||||
{
|
||||
final CodeLines codeLines = CodeLines.of(const [
|
||||
CodeLine('""("")')
|
||||
]);
|
||||
expect(analyzer.parse(codeLines), const [
|
||||
CodeChunkSymbol('(', 0),
|
||||
CodeChunkSymbol(')', 0),
|
||||
]);
|
||||
}
|
||||
{
|
||||
final CodeLines codeLines = CodeLines.of(const [
|
||||
CodeLine('\'\'(')
|
||||
]);
|
||||
expect(analyzer.parse(codeLines), const [
|
||||
CodeChunkSymbol('(', 0),
|
||||
]);
|
||||
}
|
||||
{
|
||||
final CodeLines codeLines = CodeLines.of(const [
|
||||
CodeLine('\'\'(\'\'')
|
||||
]);
|
||||
expect(analyzer.parse(codeLines), const [
|
||||
CodeChunkSymbol('(', 0),
|
||||
]);
|
||||
}
|
||||
{
|
||||
final CodeLines codeLines = CodeLines.of(const [
|
||||
CodeLine('\'\'(\'\')')
|
||||
]);
|
||||
expect(analyzer.parse(codeLines), const [
|
||||
CodeChunkSymbol('(', 0),
|
||||
CodeChunkSymbol(')', 0),
|
||||
]);
|
||||
}
|
||||
});
|
||||
|
||||
test('A single code line with unbalanced quotas', () {
|
||||
{
|
||||
final CodeLines codeLines = CodeLines.of(const [
|
||||
CodeLine('\'(')
|
||||
]);
|
||||
expect(analyzer.parse(codeLines), const []);
|
||||
}
|
||||
{
|
||||
final CodeLines codeLines = CodeLines.of(const [
|
||||
CodeLine('"(')
|
||||
]);
|
||||
expect(analyzer.parse(codeLines), const []);
|
||||
}
|
||||
{
|
||||
final CodeLines codeLines = CodeLines.of(const [
|
||||
CodeLine('\'(\'\')')
|
||||
]);
|
||||
expect(analyzer.parse(codeLines), const []);
|
||||
}
|
||||
{
|
||||
final CodeLines codeLines = CodeLines.of(const [
|
||||
CodeLine('"\'()[]{}')
|
||||
]);
|
||||
expect(analyzer.parse(codeLines), const []);
|
||||
}
|
||||
{
|
||||
final CodeLines codeLines = CodeLines.of(const [
|
||||
CodeLine('"\'()"[]')
|
||||
]);
|
||||
expect(analyzer.parse(codeLines), const [
|
||||
CodeChunkSymbol('[', 0),
|
||||
CodeChunkSymbol(']', 0),
|
||||
]);
|
||||
}
|
||||
{
|
||||
final CodeLines codeLines = CodeLines.of(const [
|
||||
CodeLine('"\\"()"[]')
|
||||
]);
|
||||
expect(analyzer.parse(codeLines), const [
|
||||
CodeChunkSymbol('[', 0),
|
||||
CodeChunkSymbol(']', 0),
|
||||
]);
|
||||
}
|
||||
{
|
||||
final CodeLines codeLines = CodeLines.of(const [
|
||||
CodeLine('\\"()"[]')
|
||||
]);
|
||||
expect(analyzer.parse(codeLines), const []);
|
||||
}
|
||||
});
|
||||
|
||||
test('Multi code lines', () {
|
||||
{
|
||||
final CodeLines codeLines = CodeLines.of(const [
|
||||
CodeLine('()'),
|
||||
CodeLine('[]'),
|
||||
CodeLine('{}'),
|
||||
]);
|
||||
expect(analyzer.parse(codeLines), const [
|
||||
CodeChunkSymbol('(', 0),
|
||||
CodeChunkSymbol(')', 0),
|
||||
CodeChunkSymbol('[', 1),
|
||||
CodeChunkSymbol(']', 1),
|
||||
CodeChunkSymbol('{', 2),
|
||||
CodeChunkSymbol('}', 2),
|
||||
]);
|
||||
}
|
||||
{
|
||||
final CodeLines codeLines = CodeLines.of(const [
|
||||
CodeLine('('),
|
||||
CodeLine('{'),
|
||||
CodeLine('['),
|
||||
CodeLine('inner1'),
|
||||
CodeLine('inner2'),
|
||||
CodeLine('inner3'),
|
||||
CodeLine(']'),
|
||||
CodeLine('{'),
|
||||
CodeLine('inner'),
|
||||
CodeLine('inner4'),
|
||||
CodeLine('inner5'),
|
||||
CodeLine('inner6'),
|
||||
CodeLine('inner7'),
|
||||
CodeLine('}'),
|
||||
CodeLine('}'),
|
||||
CodeLine(')'),
|
||||
]);
|
||||
expect(analyzer.parse(codeLines), const [
|
||||
CodeChunkSymbol('(', 0),
|
||||
CodeChunkSymbol('{', 1),
|
||||
CodeChunkSymbol('[', 2),
|
||||
CodeChunkSymbol(']', 6),
|
||||
CodeChunkSymbol('{', 7),
|
||||
CodeChunkSymbol('}', 13),
|
||||
CodeChunkSymbol('}', 14),
|
||||
CodeChunkSymbol(')', 15),
|
||||
]);
|
||||
}
|
||||
// Half collapsed code lines
|
||||
{
|
||||
final CodeLines codeLines = CodeLines.of(const [
|
||||
CodeLine('('),
|
||||
CodeLine('[', [
|
||||
CodeLine('inner1'),
|
||||
CodeLine('inner2'),
|
||||
CodeLine('inner3'),
|
||||
]),
|
||||
CodeLine(']'),
|
||||
CodeLine(')'),
|
||||
]);
|
||||
expect(analyzer.parse(codeLines), const [
|
||||
CodeChunkSymbol('(', 0),
|
||||
CodeChunkSymbol('[', 1),
|
||||
CodeChunkSymbol(']', 2),
|
||||
CodeChunkSymbol(')', 3),
|
||||
]);
|
||||
}
|
||||
// All collapsed code lines
|
||||
{
|
||||
final CodeLines codeLines = CodeLines.of(const [
|
||||
CodeLine('(', [
|
||||
CodeLine('{', [
|
||||
CodeLine('[', [
|
||||
CodeLine('inner1'),
|
||||
CodeLine('inner2'),
|
||||
CodeLine('inner3'),
|
||||
])
|
||||
]),
|
||||
CodeLine(']'),
|
||||
CodeLine('{', [
|
||||
CodeLine('inner', [
|
||||
CodeLine('inner4'),
|
||||
CodeLine('inner5'),
|
||||
CodeLine('inner6'),
|
||||
CodeLine('inner7'),
|
||||
])
|
||||
]),
|
||||
CodeLine('}'),
|
||||
CodeLine('}'),
|
||||
]),
|
||||
CodeLine(')'),
|
||||
]);
|
||||
expect(analyzer.parse(codeLines), const [
|
||||
CodeChunkSymbol('(', 0),
|
||||
CodeChunkSymbol(')', 1),
|
||||
]);
|
||||
}
|
||||
});
|
||||
|
||||
test('Parse a json string', () {
|
||||
{
|
||||
final CodeLines codeLines = File(join('test', 'data', 'json_pretty.json')).readAsStringSync().codeLines;
|
||||
expect(analyzer.parse(codeLines), const [
|
||||
CodeChunkSymbol('{', 0),
|
||||
CodeChunkSymbol('{', 1),
|
||||
CodeChunkSymbol('[', 2),
|
||||
CodeChunkSymbol(']', 4),
|
||||
CodeChunkSymbol('}', 5),
|
||||
CodeChunkSymbol('[', 6),
|
||||
CodeChunkSymbol('{', 7),
|
||||
CodeChunkSymbol('}', 10),
|
||||
CodeChunkSymbol('{', 11),
|
||||
CodeChunkSymbol('}', 14),
|
||||
CodeChunkSymbol(']', 15),
|
||||
CodeChunkSymbol('}', 17),
|
||||
]);
|
||||
}
|
||||
{
|
||||
final CodeLines codeLines = File(join('test', 'data', 'json_flatted.json')).readAsStringSync().codeLines;
|
||||
expect(analyzer.parse(codeLines), const [
|
||||
CodeChunkSymbol('{', 0),
|
||||
CodeChunkSymbol('{', 0),
|
||||
CodeChunkSymbol('[', 0),
|
||||
CodeChunkSymbol(']', 0),
|
||||
CodeChunkSymbol('}', 0),
|
||||
CodeChunkSymbol('[', 0),
|
||||
CodeChunkSymbol('{', 0),
|
||||
CodeChunkSymbol('}', 0),
|
||||
CodeChunkSymbol('{', 0),
|
||||
CodeChunkSymbol('}', 0),
|
||||
CodeChunkSymbol(']', 0),
|
||||
CodeChunkSymbol('}', 0),
|
||||
]);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
group('DefaultCodeChunkAnalyzer.run()', () {
|
||||
test('A single code line', () {
|
||||
{
|
||||
final CodeLines codeLines = CodeLines.of(const [
|
||||
CodeLine.empty
|
||||
]);
|
||||
expect(analyzer.run(codeLines), const []);
|
||||
}
|
||||
{
|
||||
final CodeLines codeLines = CodeLines.of(const [
|
||||
CodeLine('abc')
|
||||
]);
|
||||
expect(analyzer.run(codeLines), const []);
|
||||
}
|
||||
{
|
||||
final CodeLines codeLines = CodeLines.of(const [
|
||||
CodeLine('abc(){}[]')
|
||||
]);
|
||||
expect(analyzer.run(codeLines), const []);
|
||||
}
|
||||
});
|
||||
test('Multi code lines', () {
|
||||
{
|
||||
final CodeLines codeLines = CodeLines.of(const [
|
||||
CodeLine.empty,
|
||||
CodeLine.empty,
|
||||
CodeLine.empty,
|
||||
CodeLine.empty,
|
||||
CodeLine.empty,
|
||||
]);
|
||||
expect(analyzer.run(codeLines), const []);
|
||||
}
|
||||
{
|
||||
final CodeLines codeLines = CodeLines.of(const [
|
||||
CodeLine('abc'),
|
||||
CodeLine('abc'),
|
||||
CodeLine('abc'),
|
||||
CodeLine('abc'),
|
||||
CodeLine('abc'),
|
||||
]);
|
||||
expect(analyzer.run(codeLines), const []);
|
||||
}
|
||||
{
|
||||
final CodeLines codeLines = CodeLines.of(const [
|
||||
CodeLine('abc(){}[]'),
|
||||
CodeLine('abc(){}[]'),
|
||||
CodeLine('abc(){}[]'),
|
||||
CodeLine('abc(){}[]'),
|
||||
CodeLine('abc(){}[]'),
|
||||
]);
|
||||
expect(analyzer.run(codeLines), const []);
|
||||
}
|
||||
{
|
||||
final CodeLines codeLines = CodeLines.of(const [
|
||||
CodeLine('abc('),
|
||||
CodeLine('abc'),
|
||||
CodeLine('abc'),
|
||||
CodeLine('abc'),
|
||||
CodeLine('abc)'),
|
||||
]);
|
||||
expect(analyzer.run(codeLines), const [
|
||||
CodeChunk(0, 4)
|
||||
]);
|
||||
}
|
||||
{
|
||||
final CodeLines codeLines = CodeLines.of(const [
|
||||
CodeLine('abc('),
|
||||
CodeLine('abc['),
|
||||
CodeLine('abc{}'),
|
||||
CodeLine('abc]'),
|
||||
CodeLine('abc)'),
|
||||
]);
|
||||
expect(analyzer.run(codeLines), const [
|
||||
CodeChunk(0, 4),
|
||||
CodeChunk(1, 3)
|
||||
]);
|
||||
}
|
||||
{
|
||||
final CodeLines codeLines = CodeLines.of(const [
|
||||
CodeLine('{'),
|
||||
CodeLine('}'),
|
||||
CodeLine('{'),
|
||||
CodeLine('}'),
|
||||
CodeLine('{'),
|
||||
CodeLine('}'),
|
||||
]);
|
||||
expect(analyzer.run(codeLines), const [
|
||||
CodeChunk(0, 1),
|
||||
CodeChunk(2, 3),
|
||||
CodeChunk(4, 5)
|
||||
]);
|
||||
}
|
||||
{
|
||||
final CodeLines codeLines = CodeLines.of(const [
|
||||
CodeLine('abc('),
|
||||
CodeLine('abc[[[['),
|
||||
CodeLine('abc'),
|
||||
CodeLine('abc]]]]'),
|
||||
CodeLine('abc)'),
|
||||
]);
|
||||
expect(analyzer.run(codeLines), const [
|
||||
CodeChunk(0, 4),
|
||||
CodeChunk(1, 3)
|
||||
]);
|
||||
}
|
||||
{
|
||||
final CodeLines codeLines = CodeLines.of(const [
|
||||
CodeLine('abc('),
|
||||
CodeLine('[[[['),
|
||||
CodeLine('abc'),
|
||||
CodeLine(']'),
|
||||
CodeLine(']'),
|
||||
CodeLine(']'),
|
||||
CodeLine(']'),
|
||||
CodeLine('abc)'),
|
||||
]);
|
||||
expect(analyzer.run(codeLines), const [
|
||||
CodeChunk(0, 7),
|
||||
CodeChunk(1, 3)
|
||||
]);
|
||||
}
|
||||
{
|
||||
final CodeLines codeLines = CodeLines.of(const [
|
||||
CodeLine('abc('),
|
||||
CodeLine('abc['),
|
||||
CodeLine('abc'),
|
||||
CodeLine('abc['),
|
||||
CodeLine('abc)'),
|
||||
]);
|
||||
expect(analyzer.run(codeLines), const [
|
||||
CodeChunk(0, 4),
|
||||
]);
|
||||
}
|
||||
});
|
||||
test('Parse a json string', () {
|
||||
{
|
||||
final CodeLines codeLines = File(join('test', 'data', 'json_pretty.json')).readAsStringSync().codeLines;
|
||||
expect(analyzer.run(codeLines), const [
|
||||
CodeChunk(0, 17),
|
||||
CodeChunk(1, 5),
|
||||
CodeChunk(2, 4),
|
||||
CodeChunk(6, 15),
|
||||
CodeChunk(7, 10),
|
||||
CodeChunk(11, 14)
|
||||
]);
|
||||
}
|
||||
{
|
||||
final CodeLines codeLines = File(join('test', 'data', 'json_flatted.json')).readAsStringSync().codeLines;
|
||||
expect(analyzer.run(codeLines), const []);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,936 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:re_editor/re_editor.dart';
|
||||
|
||||
void main() {
|
||||
group('CodeChunkController constructor', () {
|
||||
test('CodeChunkController()', () async {
|
||||
{
|
||||
final CodeChunkController controller = CodeChunkController(CodeLineEditingController(),
|
||||
const DefaultCodeChunkAnalyzer());
|
||||
await Future.delayed(const Duration(milliseconds: 200), () {
|
||||
expect(controller.value, const []);
|
||||
controller.dispose();
|
||||
});
|
||||
}
|
||||
{
|
||||
final CodeChunkController controller = CodeChunkController(CodeLineEditingController.fromText('{\n\n}'),
|
||||
const DefaultCodeChunkAnalyzer());
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
expect(controller.value, const [
|
||||
CodeChunk(0, 2)
|
||||
]);
|
||||
controller.dispose();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
group('CodeChunkController method', () {
|
||||
|
||||
test('collapse()', () async {
|
||||
// Empty content, and no chunk
|
||||
{
|
||||
final CodeChunkController controller = CodeChunkController(CodeLineEditingController(),
|
||||
const DefaultCodeChunkAnalyzer());
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
controller.collapse(0);
|
||||
expect(controller.value, const []);
|
||||
controller.dispose();
|
||||
}
|
||||
// Non-Empty content, but no chunk
|
||||
{
|
||||
final CodeChunkController controller = CodeChunkController(CodeLineEditingController.fromText('abc'),
|
||||
const DefaultCodeChunkAnalyzer());
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
controller.collapse(0);
|
||||
expect(controller.value, const []);
|
||||
controller.dispose();
|
||||
}
|
||||
// Have a chunk, but nothing to collapse
|
||||
{
|
||||
final CodeChunkController controller = CodeChunkController(CodeLineEditingController.fromText('{\n}'),
|
||||
const DefaultCodeChunkAnalyzer());
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
expect(controller.value, const [
|
||||
CodeChunk(0, 1)
|
||||
]);
|
||||
controller.collapse(0);
|
||||
expect(controller.value, const [
|
||||
CodeChunk(0, 1)
|
||||
]);
|
||||
controller.dispose();
|
||||
}
|
||||
// Have only a chunk
|
||||
{
|
||||
final CodeLineEditingController editingController = CodeLineEditingController.fromText('{\nabc\n}');
|
||||
final CodeChunkController controller = CodeChunkController(editingController,
|
||||
const DefaultCodeChunkAnalyzer());
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
expect(controller.value, const [
|
||||
CodeChunk(0, 2)
|
||||
]);
|
||||
controller.collapse(0);
|
||||
expect(controller.value, const [
|
||||
CodeChunk(0, 1)
|
||||
]);
|
||||
expect(editingController.codeLines, CodeLines.of(const [
|
||||
CodeLine('{', [
|
||||
CodeLine('abc')
|
||||
]),
|
||||
CodeLine('}')
|
||||
]));
|
||||
controller.dispose();
|
||||
}
|
||||
// Have multi chunks, collapse from inside one by one
|
||||
{
|
||||
final CodeLineEditingController editingController = CodeLineEditingController.fromText('{\n\n{\n[\nabc\n(foo)\nbar\n]\n}\n\n}');
|
||||
final CodeChunkController controller = CodeChunkController(editingController,
|
||||
const DefaultCodeChunkAnalyzer());
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
expect(controller.value, const [
|
||||
CodeChunk(0, 10),
|
||||
CodeChunk(2, 8),
|
||||
CodeChunk(3, 7),
|
||||
]);
|
||||
controller.collapse(3);
|
||||
expect(controller.value, const [
|
||||
CodeChunk(0, 7),
|
||||
CodeChunk(2, 5),
|
||||
CodeChunk(3, 4),
|
||||
]);
|
||||
expect(editingController.codeLines, CodeLines.of(const [
|
||||
CodeLine('{'),
|
||||
CodeLine(''),
|
||||
CodeLine('{'),
|
||||
CodeLine('[', [
|
||||
CodeLine('abc'),
|
||||
CodeLine('(foo)'),
|
||||
CodeLine('bar'),
|
||||
]),
|
||||
CodeLine(']'),
|
||||
CodeLine('}'),
|
||||
CodeLine(''),
|
||||
CodeLine('}')
|
||||
]));
|
||||
controller.collapse(2);
|
||||
expect(controller.value, const [
|
||||
CodeChunk(0, 5),
|
||||
CodeChunk(2, 3)
|
||||
]);
|
||||
expect(editingController.codeLines, CodeLines.of(const [
|
||||
CodeLine('{'),
|
||||
CodeLine(''),
|
||||
CodeLine('{', [
|
||||
CodeLine('[', [
|
||||
CodeLine('abc'),
|
||||
CodeLine('(foo)'),
|
||||
CodeLine('bar'),
|
||||
]),
|
||||
CodeLine(']')
|
||||
]),
|
||||
CodeLine('}'),
|
||||
CodeLine(''),
|
||||
CodeLine('}')
|
||||
]));
|
||||
controller.collapse(0);
|
||||
expect(editingController.codeLines, CodeLines.of(const [
|
||||
CodeLine('{', [
|
||||
CodeLine(''),
|
||||
CodeLine('{', [
|
||||
CodeLine('[', [
|
||||
CodeLine('abc'),
|
||||
CodeLine('(foo)'),
|
||||
CodeLine('bar'),
|
||||
]),
|
||||
CodeLine(']')
|
||||
]),
|
||||
CodeLine('}'),
|
||||
CodeLine(''),
|
||||
]),
|
||||
CodeLine('}')
|
||||
]));
|
||||
controller.collapse(0);
|
||||
expect(controller.value, const [
|
||||
CodeChunk(0, 1)
|
||||
]);
|
||||
controller.dispose();
|
||||
}
|
||||
// Have multi chunks, collapse from top one by one
|
||||
{
|
||||
final CodeLineEditingController editingController = CodeLineEditingController.fromText('{\n\n}{\n\n}{\n\n}{\n\n}');
|
||||
final CodeChunkController controller = CodeChunkController(editingController,
|
||||
const DefaultCodeChunkAnalyzer());
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
expect(controller.value, const [
|
||||
CodeChunk(0, 2),
|
||||
CodeChunk(2, 4),
|
||||
CodeChunk(4, 6),
|
||||
CodeChunk(6, 8),
|
||||
]);
|
||||
controller.collapse(0);
|
||||
expect(controller.value, const [
|
||||
CodeChunk(0, 1),
|
||||
CodeChunk(1, 3),
|
||||
CodeChunk(3, 5),
|
||||
CodeChunk(5, 7),
|
||||
]);
|
||||
expect(editingController.codeLines, CodeLines.of(const [
|
||||
CodeLine('{', [
|
||||
CodeLine('')
|
||||
]),
|
||||
CodeLine('}{'),
|
||||
CodeLine(''),
|
||||
CodeLine('}{'),
|
||||
CodeLine(''),
|
||||
CodeLine('}{'),
|
||||
CodeLine(''),
|
||||
CodeLine('}'),
|
||||
]));
|
||||
controller.collapse(1);
|
||||
expect(controller.value, const [
|
||||
CodeChunk(0, 1),
|
||||
CodeChunk(1, 2),
|
||||
CodeChunk(2, 4),
|
||||
CodeChunk(4, 6),
|
||||
]);
|
||||
expect(editingController.codeLines, CodeLines.of(const [
|
||||
CodeLine('{', [
|
||||
CodeLine('')
|
||||
]),
|
||||
CodeLine('}{', [
|
||||
CodeLine('')
|
||||
]),
|
||||
CodeLine('}{'),
|
||||
CodeLine(''),
|
||||
CodeLine('}{'),
|
||||
CodeLine(''),
|
||||
CodeLine('}'),
|
||||
]));
|
||||
controller.collapse(2);
|
||||
expect(controller.value, const [
|
||||
CodeChunk(0, 1),
|
||||
CodeChunk(1, 2),
|
||||
CodeChunk(2, 3),
|
||||
CodeChunk(3, 5),
|
||||
]);
|
||||
expect(editingController.codeLines, CodeLines.of(const [
|
||||
CodeLine('{', [
|
||||
CodeLine('')
|
||||
]),
|
||||
CodeLine('}{', [
|
||||
CodeLine('')
|
||||
]),
|
||||
CodeLine('}{', [
|
||||
CodeLine('')
|
||||
]),
|
||||
CodeLine('}{'),
|
||||
CodeLine(''),
|
||||
CodeLine('}'),
|
||||
]));
|
||||
controller.collapse(3);
|
||||
expect(controller.value, const [
|
||||
CodeChunk(0, 1),
|
||||
CodeChunk(1, 2),
|
||||
CodeChunk(2, 3),
|
||||
CodeChunk(3, 4),
|
||||
]);
|
||||
expect(editingController.codeLines, CodeLines.of(const [
|
||||
CodeLine('{', [
|
||||
CodeLine('')
|
||||
]),
|
||||
CodeLine('}{', [
|
||||
CodeLine('')
|
||||
]),
|
||||
CodeLine('}{', [
|
||||
CodeLine('')
|
||||
]),
|
||||
CodeLine('}{', [
|
||||
CodeLine('')
|
||||
]),
|
||||
CodeLine('}'),
|
||||
]));
|
||||
}
|
||||
// Have multi chunks, collapse from bottom one by one
|
||||
{
|
||||
final CodeLineEditingController editingController = CodeLineEditingController.fromText('{\n\n}{\n\n}{\n\n}{\n\n}');
|
||||
final CodeChunkController controller = CodeChunkController(editingController,
|
||||
const DefaultCodeChunkAnalyzer());
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
expect(controller.value, const [
|
||||
CodeChunk(0, 2),
|
||||
CodeChunk(2, 4),
|
||||
CodeChunk(4, 6),
|
||||
CodeChunk(6, 8),
|
||||
]);
|
||||
controller.collapse(6);
|
||||
expect(controller.value, const [
|
||||
CodeChunk(0, 2),
|
||||
CodeChunk(2, 4),
|
||||
CodeChunk(4, 6),
|
||||
CodeChunk(6, 7),
|
||||
]);
|
||||
expect(editingController.codeLines, CodeLines.of(const [
|
||||
CodeLine('{'),
|
||||
CodeLine(''),
|
||||
CodeLine('}{'),
|
||||
CodeLine(''),
|
||||
CodeLine('}{'),
|
||||
CodeLine(''),
|
||||
CodeLine('}{', [
|
||||
CodeLine(''),
|
||||
]),
|
||||
CodeLine('}'),
|
||||
]));
|
||||
controller.collapse(4);
|
||||
expect(controller.value, const [
|
||||
CodeChunk(0, 2),
|
||||
CodeChunk(2, 4),
|
||||
CodeChunk(4, 5),
|
||||
CodeChunk(5, 6),
|
||||
]);
|
||||
expect(editingController.codeLines, CodeLines.of(const [
|
||||
CodeLine('{'),
|
||||
CodeLine(''),
|
||||
CodeLine('}{'),
|
||||
CodeLine(''),
|
||||
CodeLine('}{', [
|
||||
CodeLine(''),
|
||||
]),
|
||||
CodeLine('}{', [
|
||||
CodeLine(''),
|
||||
]),
|
||||
CodeLine('}'),
|
||||
]));
|
||||
controller.collapse(2);
|
||||
expect(controller.value, const [
|
||||
CodeChunk(0, 2),
|
||||
CodeChunk(2, 3),
|
||||
CodeChunk(3, 4),
|
||||
CodeChunk(4, 5),
|
||||
]);
|
||||
expect(editingController.codeLines, CodeLines.of(const [
|
||||
CodeLine('{'),
|
||||
CodeLine(''),
|
||||
CodeLine('}{', [
|
||||
CodeLine(''),
|
||||
]),
|
||||
CodeLine('}{', [
|
||||
CodeLine(''),
|
||||
]),
|
||||
CodeLine('}{', [
|
||||
CodeLine(''),
|
||||
]),
|
||||
CodeLine('}'),
|
||||
]));
|
||||
controller.collapse(0);
|
||||
expect(controller.value, const [
|
||||
CodeChunk(0, 1),
|
||||
CodeChunk(1, 2),
|
||||
CodeChunk(2, 3),
|
||||
CodeChunk(3, 4),
|
||||
]);
|
||||
expect(editingController.codeLines, CodeLines.of(const [
|
||||
CodeLine('{', [
|
||||
CodeLine('')
|
||||
]),
|
||||
CodeLine('}{', [
|
||||
CodeLine('')
|
||||
]),
|
||||
CodeLine('}{', [
|
||||
CodeLine('')
|
||||
]),
|
||||
CodeLine('}{', [
|
||||
CodeLine('')
|
||||
]),
|
||||
CodeLine('}'),
|
||||
]));
|
||||
}
|
||||
});
|
||||
|
||||
test('expand()', () async {
|
||||
// Empty content, and no chunk
|
||||
{
|
||||
final CodeChunkController controller = CodeChunkController(CodeLineEditingController(),
|
||||
const DefaultCodeChunkAnalyzer());
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
controller.expand(0);
|
||||
expect(controller.value, const []);
|
||||
controller.dispose();
|
||||
}
|
||||
// Non-Empty content, but no chunk
|
||||
{
|
||||
final CodeChunkController controller = CodeChunkController(CodeLineEditingController.fromText('abc'),
|
||||
const DefaultCodeChunkAnalyzer());
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
controller.expand(0);
|
||||
expect(controller.value, const []);
|
||||
controller.dispose();
|
||||
}
|
||||
// Have a chunk, but nothing to expand
|
||||
{
|
||||
final CodeChunkController controller = CodeChunkController(CodeLineEditingController.fromText('{\n}'),
|
||||
const DefaultCodeChunkAnalyzer());
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
expect(controller.value, const [
|
||||
CodeChunk(0, 1)
|
||||
]);
|
||||
controller.expand(0);
|
||||
expect(controller.value, const [
|
||||
CodeChunk(0, 1)
|
||||
]);
|
||||
controller.dispose();
|
||||
}
|
||||
// Have only a collapsed chunk
|
||||
{
|
||||
final CodeLineEditingController editingController = CodeLineEditingController(
|
||||
codeLines: CodeLines.of(const [
|
||||
CodeLine('{', [
|
||||
CodeLine('abc'),
|
||||
]),
|
||||
CodeLine('}'),
|
||||
]
|
||||
));
|
||||
final CodeChunkController controller = CodeChunkController(editingController, const DefaultCodeChunkAnalyzer());
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
expect(controller.value, const [
|
||||
CodeChunk(0, 1),
|
||||
]);
|
||||
controller.expand(0);
|
||||
expect(controller.value, const [
|
||||
CodeChunk(0, 2)
|
||||
]);
|
||||
expect(editingController.codeLines, CodeLines.of(const [
|
||||
CodeLine('{'),
|
||||
CodeLine('abc'),
|
||||
CodeLine('}'),
|
||||
]));
|
||||
controller.dispose();
|
||||
}
|
||||
// Have multi collapsed chunks, expand from outside one by one
|
||||
{
|
||||
final CodeLineEditingController editingController = CodeLineEditingController(
|
||||
codeLines: CodeLines.of(const [
|
||||
CodeLine('{', [
|
||||
CodeLine(''),
|
||||
CodeLine('{', [
|
||||
CodeLine('[', [
|
||||
CodeLine('abc'),
|
||||
CodeLine('(foo)'),
|
||||
CodeLine('bar'),
|
||||
]),
|
||||
CodeLine(']')
|
||||
]),
|
||||
CodeLine('}'),
|
||||
CodeLine(''),
|
||||
]),
|
||||
CodeLine('}')
|
||||
]
|
||||
));
|
||||
final CodeChunkController controller = CodeChunkController(editingController,
|
||||
const DefaultCodeChunkAnalyzer());
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
expect(controller.value, const [
|
||||
CodeChunk(0, 1),
|
||||
]);
|
||||
controller.expand(0);
|
||||
expect(controller.value, const [
|
||||
CodeChunk(0, 5),
|
||||
]);
|
||||
expect(editingController.codeLines, CodeLines.of(const [
|
||||
CodeLine('{'),
|
||||
CodeLine(''),
|
||||
CodeLine('{', [
|
||||
CodeLine('[', [
|
||||
CodeLine('abc'),
|
||||
CodeLine('(foo)'),
|
||||
CodeLine('bar'),
|
||||
]),
|
||||
CodeLine(']')
|
||||
]),
|
||||
CodeLine('}'),
|
||||
CodeLine(''),
|
||||
CodeLine('}')
|
||||
]));
|
||||
controller.expand(2);
|
||||
expect(controller.value, const [
|
||||
CodeChunk(0, 7),
|
||||
CodeChunk(2, 5),
|
||||
]);
|
||||
expect(editingController.codeLines, CodeLines.of(const [
|
||||
CodeLine('{'),
|
||||
CodeLine(''),
|
||||
CodeLine('{'),
|
||||
CodeLine('[', [
|
||||
CodeLine('abc'),
|
||||
CodeLine('(foo)'),
|
||||
CodeLine('bar'),
|
||||
]),
|
||||
CodeLine(']'),
|
||||
CodeLine('}'),
|
||||
CodeLine(''),
|
||||
CodeLine('}')
|
||||
]));
|
||||
controller.expand(3);
|
||||
expect(controller.value, const [
|
||||
CodeChunk(0, 10),
|
||||
CodeChunk(2, 8),
|
||||
CodeChunk(3, 7),
|
||||
]);
|
||||
expect(editingController.codeLines, CodeLines.of(const [
|
||||
CodeLine('{'),
|
||||
CodeLine(''),
|
||||
CodeLine('{'),
|
||||
CodeLine('['),
|
||||
CodeLine('abc'),
|
||||
CodeLine('(foo)'),
|
||||
CodeLine('bar'),
|
||||
CodeLine(']'),
|
||||
CodeLine('}'),
|
||||
CodeLine(''),
|
||||
CodeLine('}')
|
||||
]));
|
||||
controller.dispose();
|
||||
}
|
||||
// Have multi collapsed chunks, expand from top one by one
|
||||
{
|
||||
final CodeLineEditingController editingController = CodeLineEditingController(
|
||||
codeLines: CodeLines.of(const [
|
||||
CodeLine('{', [
|
||||
CodeLine('')
|
||||
]),
|
||||
CodeLine('}{', [
|
||||
CodeLine('')
|
||||
]),
|
||||
CodeLine('}{', [
|
||||
CodeLine('')
|
||||
]),
|
||||
CodeLine('}{', [
|
||||
CodeLine('')
|
||||
]),
|
||||
CodeLine('}'),
|
||||
]
|
||||
));
|
||||
final CodeChunkController controller = CodeChunkController(editingController,
|
||||
const DefaultCodeChunkAnalyzer());
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
expect(controller.value, const [
|
||||
CodeChunk(0, 1),
|
||||
CodeChunk(1, 2),
|
||||
CodeChunk(2, 3),
|
||||
CodeChunk(3, 4),
|
||||
]);
|
||||
controller.expand(0);
|
||||
expect(controller.value, const [
|
||||
CodeChunk(0, 2),
|
||||
CodeChunk(2, 3),
|
||||
CodeChunk(3, 4),
|
||||
CodeChunk(4, 5),
|
||||
]);
|
||||
expect(editingController.codeLines, CodeLines.of(const [
|
||||
CodeLine('{'),
|
||||
CodeLine(''),
|
||||
CodeLine('}{', [
|
||||
CodeLine('')
|
||||
]),
|
||||
CodeLine('}{', [
|
||||
CodeLine('')
|
||||
]),
|
||||
CodeLine('}{', [
|
||||
CodeLine('')
|
||||
]),
|
||||
CodeLine('}'),
|
||||
]));
|
||||
controller.expand(2);
|
||||
expect(controller.value, const [
|
||||
CodeChunk(0, 2),
|
||||
CodeChunk(2, 4),
|
||||
CodeChunk(4, 5),
|
||||
CodeChunk(5, 6),
|
||||
]);
|
||||
expect(editingController.codeLines, CodeLines.of(const [
|
||||
CodeLine('{'),
|
||||
CodeLine(''),
|
||||
CodeLine('}{'),
|
||||
CodeLine(''),
|
||||
CodeLine('}{', [
|
||||
CodeLine('')
|
||||
]),
|
||||
CodeLine('}{', [
|
||||
CodeLine('')
|
||||
]),
|
||||
CodeLine('}'),
|
||||
]));
|
||||
controller.expand(4);
|
||||
expect(controller.value, const [
|
||||
CodeChunk(0, 2),
|
||||
CodeChunk(2, 4),
|
||||
CodeChunk(4, 6),
|
||||
CodeChunk(6, 7),
|
||||
]);
|
||||
expect(editingController.codeLines, CodeLines.of(const [
|
||||
CodeLine('{'),
|
||||
CodeLine(''),
|
||||
CodeLine('}{'),
|
||||
CodeLine(''),
|
||||
CodeLine('}{'),
|
||||
CodeLine(''),
|
||||
CodeLine('}{', [
|
||||
CodeLine('')
|
||||
]),
|
||||
CodeLine('}'),
|
||||
]));
|
||||
controller.expand(6);
|
||||
expect(controller.value, const [
|
||||
CodeChunk(0, 2),
|
||||
CodeChunk(2, 4),
|
||||
CodeChunk(4, 6),
|
||||
CodeChunk(6, 8),
|
||||
]);
|
||||
expect(editingController.codeLines, CodeLines.of(const [
|
||||
CodeLine('{'),
|
||||
CodeLine(''),
|
||||
CodeLine('}{'),
|
||||
CodeLine(''),
|
||||
CodeLine('}{'),
|
||||
CodeLine(''),
|
||||
CodeLine('}{'),
|
||||
CodeLine(''),
|
||||
CodeLine('}'),
|
||||
]));
|
||||
controller.dispose();
|
||||
}
|
||||
// Have multi collapsed chunks, expand from bottom one by one
|
||||
{
|
||||
final CodeLineEditingController editingController = CodeLineEditingController(
|
||||
codeLines: CodeLines.of(const [
|
||||
CodeLine('{', [
|
||||
CodeLine('')
|
||||
]),
|
||||
CodeLine('}{', [
|
||||
CodeLine('')
|
||||
]),
|
||||
CodeLine('}{', [
|
||||
CodeLine('')
|
||||
]),
|
||||
CodeLine('}{', [
|
||||
CodeLine('')
|
||||
]),
|
||||
CodeLine('}'),
|
||||
]
|
||||
));
|
||||
final CodeChunkController controller = CodeChunkController(editingController,
|
||||
const DefaultCodeChunkAnalyzer());
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
expect(controller.value, const [
|
||||
CodeChunk(0, 1),
|
||||
CodeChunk(1, 2),
|
||||
CodeChunk(2, 3),
|
||||
CodeChunk(3, 4),
|
||||
]);
|
||||
controller.expand(3);
|
||||
expect(controller.value, const [
|
||||
CodeChunk(0, 1),
|
||||
CodeChunk(1, 2),
|
||||
CodeChunk(2, 3),
|
||||
CodeChunk(3, 5),
|
||||
]);
|
||||
expect(editingController.codeLines, CodeLines.of(const [
|
||||
CodeLine('{', [
|
||||
CodeLine('')
|
||||
]),
|
||||
CodeLine('}{', [
|
||||
CodeLine('')
|
||||
]),
|
||||
CodeLine('}{', [
|
||||
CodeLine('')
|
||||
]),
|
||||
CodeLine('}{',),
|
||||
CodeLine(''),
|
||||
CodeLine('}'),
|
||||
]));
|
||||
controller.expand(2);
|
||||
expect(controller.value, const [
|
||||
CodeChunk(0, 1),
|
||||
CodeChunk(1, 2),
|
||||
CodeChunk(2, 4),
|
||||
CodeChunk(4, 6),
|
||||
]);
|
||||
expect(editingController.codeLines, CodeLines.of(const [
|
||||
CodeLine('{', [
|
||||
CodeLine('')
|
||||
]),
|
||||
CodeLine('}{', [
|
||||
CodeLine('')
|
||||
]),
|
||||
CodeLine('}{'),
|
||||
CodeLine(''),
|
||||
CodeLine('}{',),
|
||||
CodeLine(''),
|
||||
CodeLine('}'),
|
||||
]));
|
||||
controller.expand(1);
|
||||
expect(controller.value, const [
|
||||
CodeChunk(0, 1),
|
||||
CodeChunk(1, 3),
|
||||
CodeChunk(3, 5),
|
||||
CodeChunk(5, 7),
|
||||
]);
|
||||
expect(editingController.codeLines, CodeLines.of(const [
|
||||
CodeLine('{', [
|
||||
CodeLine('')
|
||||
]),
|
||||
CodeLine('}{'),
|
||||
CodeLine(''),
|
||||
CodeLine('}{'),
|
||||
CodeLine(''),
|
||||
CodeLine('}{',),
|
||||
CodeLine(''),
|
||||
CodeLine('}'),
|
||||
]));
|
||||
controller.expand(0);
|
||||
expect(controller.value, const [
|
||||
CodeChunk(0, 2),
|
||||
CodeChunk(2, 4),
|
||||
CodeChunk(4, 6),
|
||||
CodeChunk(6, 8),
|
||||
]);
|
||||
expect(editingController.codeLines, CodeLines.of(const [
|
||||
CodeLine('{'),
|
||||
CodeLine(''),
|
||||
CodeLine('}{'),
|
||||
CodeLine(''),
|
||||
CodeLine('}{'),
|
||||
CodeLine(''),
|
||||
CodeLine('}{'),
|
||||
CodeLine(''),
|
||||
CodeLine('}'),
|
||||
]));
|
||||
controller.dispose();
|
||||
}
|
||||
});
|
||||
|
||||
test('collapse() and expand()', () async {
|
||||
final CodeLineEditingController editingController = CodeLineEditingController.fromText('{\n\n}{\n\n}{\n\n}{\n\n}');
|
||||
final CodeChunkController controller = CodeChunkController(editingController,
|
||||
const DefaultCodeChunkAnalyzer());
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
controller.collapse(2);
|
||||
expect(controller.value, const [
|
||||
CodeChunk(0, 2),
|
||||
CodeChunk(2, 3),
|
||||
CodeChunk(3, 5),
|
||||
CodeChunk(5, 7),
|
||||
]);
|
||||
expect(editingController.codeLines, CodeLines.of(const [
|
||||
CodeLine('{'),
|
||||
CodeLine(''),
|
||||
CodeLine('}{', [
|
||||
CodeLine(''),
|
||||
]),
|
||||
CodeLine('}{'),
|
||||
CodeLine(''),
|
||||
CodeLine('}{'),
|
||||
CodeLine(''),
|
||||
CodeLine('}'),
|
||||
]));
|
||||
controller.collapse(3);
|
||||
expect(controller.value, const [
|
||||
CodeChunk(0, 2),
|
||||
CodeChunk(2, 3),
|
||||
CodeChunk(3, 4),
|
||||
CodeChunk(4, 6),
|
||||
]);
|
||||
expect(editingController.codeLines, CodeLines.of(const [
|
||||
CodeLine('{'),
|
||||
CodeLine(''),
|
||||
CodeLine('}{', [
|
||||
CodeLine(''),
|
||||
]),
|
||||
CodeLine('}{', [
|
||||
CodeLine(''),
|
||||
]),
|
||||
CodeLine('}{'),
|
||||
CodeLine(''),
|
||||
CodeLine('}'),
|
||||
]));
|
||||
controller.expand(2);
|
||||
expect(controller.value, const [
|
||||
CodeChunk(0, 2),
|
||||
CodeChunk(2, 4),
|
||||
CodeChunk(4, 5),
|
||||
CodeChunk(5, 7),
|
||||
]);
|
||||
expect(editingController.codeLines, CodeLines.of(const [
|
||||
CodeLine('{'),
|
||||
CodeLine(''),
|
||||
CodeLine('}{'),
|
||||
CodeLine(''),
|
||||
CodeLine('}{', [
|
||||
CodeLine(''),
|
||||
]),
|
||||
CodeLine('}{'),
|
||||
CodeLine(''),
|
||||
CodeLine('}'),
|
||||
]));
|
||||
controller.expand(4);
|
||||
expect(controller.value, const [
|
||||
CodeChunk(0, 2),
|
||||
CodeChunk(2, 4),
|
||||
CodeChunk(4, 6),
|
||||
CodeChunk(6, 8),
|
||||
]);
|
||||
expect(editingController.codeLines, CodeLines.of(const [
|
||||
CodeLine('{'),
|
||||
CodeLine(''),
|
||||
CodeLine('}{'),
|
||||
CodeLine(''),
|
||||
CodeLine('}{'),
|
||||
CodeLine(''),
|
||||
CodeLine('}{'),
|
||||
CodeLine(''),
|
||||
CodeLine('}'),
|
||||
]));
|
||||
controller.dispose();
|
||||
});
|
||||
|
||||
test('findByIndex()', () async {
|
||||
{
|
||||
final CodeChunkController controller = CodeChunkController(CodeLineEditingController(),
|
||||
const DefaultCodeChunkAnalyzer());
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
expect(controller.findByIndex(0), null);
|
||||
expect(controller.findByIndex(1), null);
|
||||
controller.dispose();
|
||||
}
|
||||
{
|
||||
final CodeChunkController controller = CodeChunkController(CodeLineEditingController.fromText('{\n\n}'),
|
||||
const DefaultCodeChunkAnalyzer());
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
expect(controller.findByIndex(0), const CodeChunk(0, 2));
|
||||
expect(controller.findByIndex(1), null);
|
||||
controller.dispose();
|
||||
}
|
||||
{
|
||||
final CodeChunkController controller = CodeChunkController(CodeLineEditingController.fromText('{\n{\n{\n\n}\n}\n}'),
|
||||
const DefaultCodeChunkAnalyzer());
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
expect(controller.findByIndex(0), const CodeChunk(0, 6));
|
||||
expect(controller.findByIndex(1), const CodeChunk(1, 5));
|
||||
expect(controller.findByIndex(2), const CodeChunk(2, 4));
|
||||
expect(controller.findByIndex(3), null);
|
||||
expect(controller.findByIndex(4), null);
|
||||
expect(controller.findByIndex(5), null);
|
||||
controller.dispose();
|
||||
}
|
||||
});
|
||||
|
||||
test('canCollapse()', () async {
|
||||
{
|
||||
final CodeChunkController controller = CodeChunkController(CodeLineEditingController.fromText('{\n}'),
|
||||
const DefaultCodeChunkAnalyzer());
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
expect(controller.canCollapse(0), false);
|
||||
controller.dispose();
|
||||
}
|
||||
{
|
||||
final CodeChunkController controller = CodeChunkController(CodeLineEditingController.fromText('{\n\n}'),
|
||||
const DefaultCodeChunkAnalyzer());
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
expect(controller.canCollapse(0), true);
|
||||
expect(controller.canCollapse(1), false);
|
||||
controller.dispose();
|
||||
}
|
||||
{
|
||||
final CodeChunkController controller = CodeChunkController(CodeLineEditingController.fromText('{\n{\n{\n\n}\n}\n}'),
|
||||
const DefaultCodeChunkAnalyzer());
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
expect(controller.canCollapse(0), true);
|
||||
expect(controller.canCollapse(1), true);
|
||||
expect(controller.canCollapse(2), true);
|
||||
expect(controller.canCollapse(3), false);
|
||||
controller.dispose();
|
||||
}
|
||||
});
|
||||
|
||||
test('auto expand invalid collapsed chunks()', () async {
|
||||
{
|
||||
final CodeLineEditingController editingController = CodeLineEditingController(
|
||||
codeLines: CodeLines.of(const [
|
||||
CodeLine('abc', [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar'),
|
||||
]),
|
||||
CodeLine('123'),
|
||||
])
|
||||
);
|
||||
final CodeChunkController controller = CodeChunkController(editingController, const DefaultCodeChunkAnalyzer());
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
expect(editingController.codeLines, CodeLines.of(const [
|
||||
CodeLine('abc'),
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar'),
|
||||
CodeLine('123'),
|
||||
]));
|
||||
// Edit the code line to create invalid chunks
|
||||
editingController.codeLines = CodeLines.of(const [
|
||||
CodeLine('abc', [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar'),
|
||||
]),
|
||||
CodeLine('abc', [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar'),
|
||||
]),
|
||||
CodeLine('abc', [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar'),
|
||||
])
|
||||
]);
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
expect(editingController.codeLines, CodeLines.of(const [
|
||||
CodeLine('abc'),
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar'),
|
||||
CodeLine('abc'),
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar'),
|
||||
CodeLine('abc'),
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar'),
|
||||
]));
|
||||
// Edit the code line to create two invalid chunks and one valid chunk
|
||||
editingController.codeLines = CodeLines.of(const [
|
||||
CodeLine('abc', [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar'),
|
||||
]),
|
||||
CodeLine('{', [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar'),
|
||||
]),
|
||||
CodeLine('}'),
|
||||
CodeLine('abc', [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar'),
|
||||
])
|
||||
]);
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
expect(editingController.codeLines, CodeLines.of(const [
|
||||
CodeLine('abc'),
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar'),
|
||||
CodeLine('{', [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar'),
|
||||
]),
|
||||
CodeLine('}'),
|
||||
CodeLine('abc'),
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar'),
|
||||
]));
|
||||
controller.dispose();
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,253 @@
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:re_editor/re_editor.dart';
|
||||
|
||||
void main() {
|
||||
group('CodeLineEditingValue constructor ', () {
|
||||
test('`CodeLineEditingValue()`', () {
|
||||
{
|
||||
final CodeLineEditingValue value = CodeLineEditingValue(
|
||||
codeLines: CodeLines.of(const [
|
||||
CodeLine('abc')
|
||||
])
|
||||
);
|
||||
expect(value.codeLines, CodeLines.of(const [
|
||||
CodeLine('abc')
|
||||
]));
|
||||
expect(value.selection, const CodeLineSelection.zero());
|
||||
expect(value.composing, TextRange.empty);
|
||||
}
|
||||
{
|
||||
final CodeLineEditingValue value = CodeLineEditingValue(
|
||||
codeLines: CodeLines.of(const [
|
||||
CodeLine('abc')
|
||||
]),
|
||||
selection: const CodeLineSelection.collapsed(
|
||||
index: 0,
|
||||
offset: 1
|
||||
),
|
||||
composing: const TextRange(
|
||||
start: 1,
|
||||
end: 2
|
||||
)
|
||||
);
|
||||
expect(value.codeLines, CodeLines.of(const [
|
||||
CodeLine('abc')
|
||||
]));
|
||||
expect(value.selection, const CodeLineSelection.collapsed(
|
||||
index: 0,
|
||||
offset: 1
|
||||
));
|
||||
expect(value.composing, const TextRange(
|
||||
start: 1,
|
||||
end: 2
|
||||
));
|
||||
}
|
||||
});
|
||||
|
||||
test('`CodeLineEditingValue.empty()`', () {
|
||||
const CodeLineEditingValue value = CodeLineEditingValue.empty();
|
||||
expect(value.codeLines, CodeLines.of(const [
|
||||
CodeLine.empty
|
||||
]));
|
||||
expect(value.selection, const CodeLineSelection.zero());
|
||||
expect(value.composing, TextRange.empty);
|
||||
});
|
||||
});
|
||||
|
||||
group('CodeLineEditingValue method ', () {
|
||||
test('`copyWith()`', () {
|
||||
final CodeLineEditingValue value = CodeLineEditingValue(
|
||||
codeLines: CodeLines.of(const [
|
||||
CodeLine('abc')
|
||||
]),
|
||||
selection: const CodeLineSelection.collapsed(
|
||||
index: 0,
|
||||
offset: 1
|
||||
),
|
||||
composing: const TextRange(
|
||||
start: 1,
|
||||
end: 2
|
||||
)
|
||||
);
|
||||
expect(value.copyWith(), value);
|
||||
expect(value.copyWith(
|
||||
codeLines: CodeLines.of(const [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar')
|
||||
])
|
||||
), CodeLineEditingValue(
|
||||
codeLines: CodeLines.of(const [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar')
|
||||
]),
|
||||
selection: const CodeLineSelection.collapsed(
|
||||
index: 0,
|
||||
offset: 1
|
||||
),
|
||||
composing: const TextRange(
|
||||
start: 1,
|
||||
end: 2
|
||||
)
|
||||
));
|
||||
expect(value.copyWith(
|
||||
selection: const CodeLineSelection.collapsed(
|
||||
index: 0,
|
||||
offset: 2
|
||||
),
|
||||
), CodeLineEditingValue(
|
||||
codeLines: CodeLines.of(const [
|
||||
CodeLine('abc')
|
||||
]),
|
||||
selection: const CodeLineSelection.collapsed(
|
||||
index: 0,
|
||||
offset: 2
|
||||
),
|
||||
composing: const TextRange(
|
||||
start: 1,
|
||||
end: 2
|
||||
)
|
||||
));
|
||||
expect(value.copyWith(
|
||||
composing: const TextRange(
|
||||
start: 2,
|
||||
end: 3
|
||||
)
|
||||
), CodeLineEditingValue(
|
||||
codeLines: CodeLines.of(const [
|
||||
CodeLine('abc')
|
||||
]),
|
||||
selection: const CodeLineSelection.collapsed(
|
||||
index: 0,
|
||||
offset: 1
|
||||
),
|
||||
composing: const TextRange(
|
||||
start: 2,
|
||||
end: 3
|
||||
)
|
||||
));
|
||||
});
|
||||
});
|
||||
|
||||
group('CodeLineEditingValue operator ', () {
|
||||
test('`==`', () {
|
||||
{
|
||||
final CodeLineEditingValue value1 = CodeLineEditingValue(
|
||||
codeLines: CodeLines.of(const [
|
||||
CodeLine('abc')
|
||||
]),
|
||||
selection: const CodeLineSelection.collapsed(
|
||||
index: 0,
|
||||
offset: 0
|
||||
),
|
||||
composing: const TextRange(
|
||||
start: 0,
|
||||
end: 0
|
||||
)
|
||||
);
|
||||
final CodeLineEditingValue value2 = CodeLineEditingValue(
|
||||
codeLines: CodeLines.of(const [
|
||||
CodeLine('abc')
|
||||
]),
|
||||
selection: const CodeLineSelection.collapsed(
|
||||
index: 0,
|
||||
offset: 0
|
||||
),
|
||||
composing: const TextRange(
|
||||
start: 0,
|
||||
end: 0
|
||||
)
|
||||
);
|
||||
expect(value1, value2);
|
||||
}
|
||||
{
|
||||
final CodeLineEditingValue value1 = CodeLineEditingValue(
|
||||
codeLines: CodeLines.of(const [
|
||||
CodeLine('abc')
|
||||
]),
|
||||
selection: const CodeLineSelection.collapsed(
|
||||
index: 0,
|
||||
offset: 0
|
||||
),
|
||||
composing: const TextRange(
|
||||
start: 0,
|
||||
end: 0
|
||||
)
|
||||
);
|
||||
final CodeLineEditingValue value2 = CodeLineEditingValue(
|
||||
codeLines: CodeLines.of(const [
|
||||
CodeLine('foobar')
|
||||
]),
|
||||
selection: const CodeLineSelection.collapsed(
|
||||
index: 0,
|
||||
offset: 0
|
||||
),
|
||||
composing: const TextRange(
|
||||
start: 0,
|
||||
end: 0
|
||||
)
|
||||
);
|
||||
expect(value1 != value2, true);
|
||||
}
|
||||
{
|
||||
final CodeLineEditingValue value1 = CodeLineEditingValue(
|
||||
codeLines: CodeLines.of(const [
|
||||
CodeLine('abc')
|
||||
]),
|
||||
selection: const CodeLineSelection.collapsed(
|
||||
index: 0,
|
||||
offset: 0
|
||||
),
|
||||
composing: const TextRange(
|
||||
start: 0,
|
||||
end: 0
|
||||
)
|
||||
);
|
||||
final CodeLineEditingValue value2 = CodeLineEditingValue(
|
||||
codeLines: CodeLines.of(const [
|
||||
CodeLine('abc')
|
||||
]),
|
||||
selection: const CodeLineSelection.collapsed(
|
||||
index: 0,
|
||||
offset: 1
|
||||
),
|
||||
composing: const TextRange(
|
||||
start: 0,
|
||||
end: 0
|
||||
)
|
||||
);
|
||||
expect(value1 != value2, true);
|
||||
}
|
||||
{
|
||||
final CodeLineEditingValue value1 = CodeLineEditingValue(
|
||||
codeLines: CodeLines.of(const [
|
||||
CodeLine('abc')
|
||||
]),
|
||||
selection: const CodeLineSelection.collapsed(
|
||||
index: 0,
|
||||
offset: 0
|
||||
),
|
||||
composing: const TextRange(
|
||||
start: 0,
|
||||
end: 0
|
||||
)
|
||||
);
|
||||
final CodeLineEditingValue value2 = CodeLineEditingValue(
|
||||
codeLines: CodeLines.of(const [
|
||||
CodeLine('abc')
|
||||
]),
|
||||
selection: const CodeLineSelection.collapsed(
|
||||
index: 0,
|
||||
offset: 0
|
||||
),
|
||||
composing: const TextRange(
|
||||
start: 1,
|
||||
end: 0
|
||||
)
|
||||
);
|
||||
expect(value1 != value2, true);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:re_editor/re_editor.dart';
|
||||
|
||||
void main() {
|
||||
group('CodeLineExtension', () {
|
||||
test('get textLines', () {
|
||||
expect(''.textLines, const [
|
||||
''
|
||||
]);
|
||||
expect('abc'.textLines, const [
|
||||
'abc'
|
||||
]);
|
||||
expect('abc\nfoo\nbar'.textLines, const [
|
||||
'abc',
|
||||
'foo',
|
||||
'bar'
|
||||
]);
|
||||
expect('abc\r\nfoo\rbar'.textLines, const [
|
||||
'abc',
|
||||
'foo',
|
||||
'bar'
|
||||
]);
|
||||
});
|
||||
test('get codeLines', () {
|
||||
expect('abc\nfoo\nbar'.codeLines, CodeLines.of(const [
|
||||
CodeLine('abc'),
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar')
|
||||
]));
|
||||
});
|
||||
|
||||
test('get codeLinesAsync', () async {
|
||||
expect(await 'abc\nfoo\nbar'.codeLinesAsync, CodeLines.of(const [
|
||||
CodeLine('abc'),
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar')
|
||||
]));
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:re_editor/re_editor.dart';
|
||||
|
||||
void main() {
|
||||
group('CodeLinePosition constructor ', () {
|
||||
test('`CodeLinePosition()`', () {
|
||||
const CodeLinePosition position = CodeLinePosition(
|
||||
index: 1,
|
||||
offset: 2,
|
||||
affinity: TextAffinity.upstream
|
||||
);
|
||||
expect(position.index, 1);
|
||||
expect(position.offset, 2);
|
||||
expect(position.affinity, TextAffinity.upstream);
|
||||
});
|
||||
test('`CodeLinePosition.from()`', () {
|
||||
final CodeLinePosition position = CodeLinePosition.from(
|
||||
index: 1,
|
||||
position: const TextPosition(
|
||||
offset: 2,
|
||||
affinity: TextAffinity.upstream
|
||||
)
|
||||
);
|
||||
expect(position.index, 1);
|
||||
expect(position.offset, 2);
|
||||
expect(position.affinity, TextAffinity.upstream);
|
||||
});
|
||||
});
|
||||
|
||||
group('CodeLinePosition method ', () {
|
||||
test('`copyWith`', () {
|
||||
const CodeLinePosition position = CodeLinePosition(
|
||||
index: 1,
|
||||
offset: 2,
|
||||
affinity: TextAffinity.downstream
|
||||
);
|
||||
expect(position.copyWith(), position);
|
||||
expect(position.copyWith(
|
||||
index: 0
|
||||
), const CodeLinePosition(
|
||||
index: 0,
|
||||
offset: 2,
|
||||
affinity: TextAffinity.downstream
|
||||
));
|
||||
expect(position.copyWith(
|
||||
offset: 0
|
||||
), const CodeLinePosition(
|
||||
index: 1,
|
||||
offset: 0,
|
||||
affinity: TextAffinity.downstream
|
||||
));
|
||||
expect(position.copyWith(
|
||||
affinity: TextAffinity.upstream
|
||||
), const CodeLinePosition(
|
||||
index: 1,
|
||||
offset: 2,
|
||||
affinity: TextAffinity.upstream
|
||||
));
|
||||
expect(position.copyWith(
|
||||
index: 0,
|
||||
offset: 0,
|
||||
affinity: TextAffinity.downstream
|
||||
), const CodeLinePosition(
|
||||
index: 0,
|
||||
offset: 0,
|
||||
affinity: TextAffinity.downstream
|
||||
));
|
||||
});
|
||||
});
|
||||
|
||||
group('CodeLinePosition operator ', () {
|
||||
test('`==`', () {
|
||||
{
|
||||
final CodeLinePosition position1 = CodeLinePosition.from(
|
||||
index: 1,
|
||||
position: const TextPosition(
|
||||
offset: 2,
|
||||
affinity: TextAffinity.upstream
|
||||
)
|
||||
);
|
||||
final CodeLinePosition position2 = CodeLinePosition.from(
|
||||
index: 1,
|
||||
position: const TextPosition(
|
||||
offset: 2,
|
||||
affinity: TextAffinity.upstream
|
||||
)
|
||||
);
|
||||
expect(position1, position2);
|
||||
}
|
||||
{
|
||||
final CodeLinePosition position1 = CodeLinePosition.from(
|
||||
index: 1,
|
||||
position: const TextPosition(
|
||||
offset: 1,
|
||||
affinity: TextAffinity.upstream
|
||||
)
|
||||
);
|
||||
final CodeLinePosition position2 = CodeLinePosition.from(
|
||||
index: 2,
|
||||
position: const TextPosition(
|
||||
offset: 2,
|
||||
affinity: TextAffinity.upstream
|
||||
)
|
||||
);
|
||||
expect(position1 == position2, false);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:re_editor/re_editor.dart';
|
||||
|
||||
void main() {
|
||||
group('CodeLineRange constructor ', () {
|
||||
test('`CodeLineRange()`', () {
|
||||
const CodeLineRange range = CodeLineRange(
|
||||
index: 1,
|
||||
start: 2,
|
||||
end: 3
|
||||
);
|
||||
expect(range.index, 1);
|
||||
expect(range.start, 2);
|
||||
expect(range.end, 3);
|
||||
});
|
||||
|
||||
test('`CodeLineRange.from()`', () {
|
||||
final CodeLineRange range = CodeLineRange.from(
|
||||
index: 1,
|
||||
range: const TextRange(
|
||||
start: 2,
|
||||
end: 3
|
||||
)
|
||||
);
|
||||
expect(range.index, 1);
|
||||
expect(range.start, 2);
|
||||
expect(range.end, 3);
|
||||
});
|
||||
|
||||
test('`CodeLineRange.collapsed()`', () {
|
||||
const CodeLineRange range = CodeLineRange.collapsed(
|
||||
index: 1,
|
||||
offset: 2
|
||||
);
|
||||
expect(range.index, 1);
|
||||
expect(range.start, 2);
|
||||
expect(range.end, 2);
|
||||
});
|
||||
|
||||
test('`CodeLineRange.empty()`', () {
|
||||
const CodeLineRange range = CodeLineRange.empty();
|
||||
expect(range.index, 0);
|
||||
expect(range.start, -1);
|
||||
expect(range.end, -1);
|
||||
});
|
||||
});
|
||||
|
||||
group('CodeLineRange method ', () {
|
||||
test('`copyWith`', () {
|
||||
const CodeLineRange range = CodeLineRange(
|
||||
index: 1,
|
||||
start: 2,
|
||||
end: 3
|
||||
);
|
||||
expect(range.copyWith(), range);
|
||||
expect(range.copyWith(
|
||||
index: 0
|
||||
), const CodeLineRange(
|
||||
index: 0,
|
||||
start: 2,
|
||||
end: 3
|
||||
));
|
||||
expect(range.copyWith(
|
||||
start: 0
|
||||
), const CodeLineRange(
|
||||
index: 1,
|
||||
start: 0,
|
||||
end: 3
|
||||
));
|
||||
expect(range.copyWith(
|
||||
end: 0
|
||||
), const CodeLineRange(
|
||||
index: 1,
|
||||
start: 2,
|
||||
end: 0
|
||||
));
|
||||
expect(range.copyWith(
|
||||
index: 0,
|
||||
start: 0,
|
||||
end: 0
|
||||
), const CodeLineRange(
|
||||
index: 0,
|
||||
start: 0,
|
||||
end: 0
|
||||
));
|
||||
});
|
||||
});
|
||||
|
||||
group('CodeLineRange operator ', () {
|
||||
test('`==`', () {
|
||||
{
|
||||
final CodeLineRange range1 = CodeLineRange.from(
|
||||
index: 1,
|
||||
range: const TextRange(
|
||||
start: 2,
|
||||
end: 3
|
||||
)
|
||||
);
|
||||
final CodeLineRange range2 = CodeLineRange.from(
|
||||
index: 1,
|
||||
range: const TextRange(
|
||||
start: 2,
|
||||
end: 3
|
||||
)
|
||||
);
|
||||
expect(range1, range2);
|
||||
}
|
||||
{
|
||||
final CodeLineRange range1 = CodeLineRange.from(
|
||||
index: 1,
|
||||
range: const TextRange(
|
||||
start: 2,
|
||||
end: 3
|
||||
)
|
||||
);
|
||||
final CodeLineRange range2 = CodeLineRange.from(
|
||||
index: 2,
|
||||
range: const TextRange(
|
||||
start: 2,
|
||||
end: 3
|
||||
)
|
||||
);
|
||||
expect(range1 == range2, false);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,647 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:re_editor/re_editor.dart';
|
||||
|
||||
void main() {
|
||||
group('CodeLineSelection constructor ', () {
|
||||
test('`CodeLineSelection()`', () {
|
||||
const CodeLineSelection selection = CodeLineSelection(
|
||||
baseIndex: 1,
|
||||
baseOffset: 2,
|
||||
extentIndex: 3,
|
||||
extentOffset: 4,
|
||||
baseAffinity: TextAffinity.upstream
|
||||
);
|
||||
expect(selection.baseIndex, 1);
|
||||
expect(selection.baseOffset, 2);
|
||||
expect(selection.extentIndex, 3);
|
||||
expect(selection.extentOffset, 4);
|
||||
expect(selection.baseAffinity, TextAffinity.upstream);
|
||||
});
|
||||
test('`CodeLineSelection.collapsed()`', () {
|
||||
const CodeLineSelection selection = CodeLineSelection.collapsed(
|
||||
index: 1,
|
||||
offset: 2,
|
||||
affinity: TextAffinity.upstream
|
||||
);
|
||||
expect(selection.baseIndex, 1);
|
||||
expect(selection.baseOffset, 2);
|
||||
expect(selection.extentIndex, 1);
|
||||
expect(selection.extentOffset, 2);
|
||||
expect(selection.baseAffinity, TextAffinity.upstream);
|
||||
});
|
||||
test('`CodeLineSelection.fromPosition()`', () {
|
||||
final CodeLineSelection selection = CodeLineSelection.fromPosition(
|
||||
position: const CodeLinePosition(
|
||||
index: 1,
|
||||
offset: 2,
|
||||
affinity: TextAffinity.upstream
|
||||
)
|
||||
);
|
||||
expect(selection.baseIndex, 1);
|
||||
expect(selection.baseOffset, 2);
|
||||
expect(selection.extentIndex, 1);
|
||||
expect(selection.extentOffset, 2);
|
||||
expect(selection.baseAffinity, TextAffinity.upstream);
|
||||
});
|
||||
test('`CodeLineSelection.fromRange()`', () {
|
||||
final CodeLineSelection selection = CodeLineSelection.fromRange(
|
||||
range: const CodeLineRange(
|
||||
index: 1,
|
||||
start: 2,
|
||||
end: 3
|
||||
)
|
||||
);
|
||||
expect(selection.baseIndex, 1);
|
||||
expect(selection.baseOffset, 2);
|
||||
expect(selection.extentIndex, 1);
|
||||
expect(selection.extentOffset, 3);
|
||||
expect(selection.baseAffinity, TextAffinity.downstream);
|
||||
});
|
||||
test('`CodeLineSelection.fromTextSelection()`', () {
|
||||
final CodeLineSelection selection = CodeLineSelection.fromTextSelection(
|
||||
index: 1,
|
||||
selection: const TextSelection(
|
||||
baseOffset: 2,
|
||||
extentOffset: 3,
|
||||
affinity: TextAffinity.upstream
|
||||
)
|
||||
);
|
||||
expect(selection.baseIndex, 1);
|
||||
expect(selection.baseOffset, 2);
|
||||
expect(selection.extentIndex, 1);
|
||||
expect(selection.extentOffset, 3);
|
||||
expect(selection.baseAffinity, TextAffinity.upstream);
|
||||
});
|
||||
test('`CodeLineSelection.zero()`', () {
|
||||
const CodeLineSelection selection = CodeLineSelection.zero();
|
||||
expect(selection.baseIndex, 0);
|
||||
expect(selection.baseOffset, 0);
|
||||
expect(selection.extentIndex, 0);
|
||||
expect(selection.extentOffset, 0);
|
||||
expect(selection.baseAffinity, TextAffinity.downstream);
|
||||
});
|
||||
});
|
||||
|
||||
group('CodeLineSelection getter ', () {
|
||||
test('`base`', () {
|
||||
// Multi code line selected and base before extent
|
||||
{
|
||||
const CodeLineSelection selection = CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 0,
|
||||
extentIndex: 1,
|
||||
extentOffset: 1,
|
||||
);
|
||||
expect(selection.base, const CodeLinePosition(
|
||||
index: 0,
|
||||
offset: 0,
|
||||
affinity: TextAffinity.downstream
|
||||
));
|
||||
}
|
||||
// Multi code line selected and base after extent
|
||||
{
|
||||
const CodeLineSelection selection = CodeLineSelection(
|
||||
extentIndex: 0,
|
||||
extentOffset: 0,
|
||||
baseIndex: 1,
|
||||
baseOffset: 1,
|
||||
);
|
||||
expect(selection.base, const CodeLinePosition(
|
||||
index: 1,
|
||||
offset: 1,
|
||||
affinity: TextAffinity.downstream
|
||||
));
|
||||
}
|
||||
// Single code line selected and base before extent
|
||||
{
|
||||
const CodeLineSelection selection = CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 0,
|
||||
extentIndex: 0,
|
||||
extentOffset: 1,
|
||||
);
|
||||
expect(selection.base, const CodeLinePosition(
|
||||
index: 0,
|
||||
offset: 0,
|
||||
affinity: TextAffinity.downstream
|
||||
));
|
||||
}
|
||||
// Single code line selected and base after extent
|
||||
{
|
||||
const CodeLineSelection selection = CodeLineSelection(
|
||||
extentIndex: 0,
|
||||
extentOffset: 0,
|
||||
baseIndex: 0,
|
||||
baseOffset: 1,
|
||||
);
|
||||
expect(selection.base, const CodeLinePosition(
|
||||
index: 0,
|
||||
offset: 1,
|
||||
affinity: TextAffinity.downstream
|
||||
));
|
||||
}
|
||||
// collapsed and upstream
|
||||
{
|
||||
const CodeLineSelection selection = CodeLineSelection.collapsed(
|
||||
index: 0,
|
||||
offset: 0,
|
||||
affinity: TextAffinity.upstream
|
||||
);
|
||||
expect(selection.base, const CodeLinePosition(
|
||||
index: 0,
|
||||
offset: 0,
|
||||
affinity: TextAffinity.upstream
|
||||
));
|
||||
}
|
||||
// collapsed and downstream
|
||||
{
|
||||
const CodeLineSelection selection = CodeLineSelection.collapsed(
|
||||
index: 0,
|
||||
offset: 0,
|
||||
affinity: TextAffinity.downstream
|
||||
);
|
||||
expect(selection.base, const CodeLinePosition(
|
||||
index: 0,
|
||||
offset: 0,
|
||||
affinity: TextAffinity.downstream
|
||||
));
|
||||
}
|
||||
});
|
||||
|
||||
test('`extent`', () {
|
||||
// Multi code line selected and base before extent
|
||||
{
|
||||
const CodeLineSelection selection = CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 0,
|
||||
extentIndex: 1,
|
||||
extentOffset: 1,
|
||||
);
|
||||
expect(selection.extent, const CodeLinePosition(
|
||||
index: 1,
|
||||
offset: 1,
|
||||
affinity: TextAffinity.downstream
|
||||
));
|
||||
}
|
||||
// Multi code line selected and base after extent
|
||||
{
|
||||
const CodeLineSelection selection = CodeLineSelection(
|
||||
extentIndex: 0,
|
||||
extentOffset: 0,
|
||||
baseIndex: 1,
|
||||
baseOffset: 1,
|
||||
);
|
||||
expect(selection.extent, const CodeLinePosition(
|
||||
index: 0,
|
||||
offset: 0,
|
||||
affinity: TextAffinity.downstream
|
||||
));
|
||||
}
|
||||
// Single code line selected and base before extent
|
||||
{
|
||||
const CodeLineSelection selection = CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 0,
|
||||
extentIndex: 0,
|
||||
extentOffset: 1,
|
||||
);
|
||||
expect(selection.extent, const CodeLinePosition(
|
||||
index: 0,
|
||||
offset: 1,
|
||||
affinity: TextAffinity.downstream
|
||||
));
|
||||
}
|
||||
// Single code line selected and base after extent
|
||||
{
|
||||
const CodeLineSelection selection = CodeLineSelection(
|
||||
extentIndex: 0,
|
||||
extentOffset: 0,
|
||||
baseIndex: 0,
|
||||
baseOffset: 1,
|
||||
);
|
||||
expect(selection.extent, const CodeLinePosition(
|
||||
index: 0,
|
||||
offset: 0,
|
||||
affinity: TextAffinity.downstream
|
||||
));
|
||||
}
|
||||
// collapsed and upstream
|
||||
{
|
||||
const CodeLineSelection selection = CodeLineSelection.collapsed(
|
||||
index: 0,
|
||||
offset: 0,
|
||||
affinity: TextAffinity.upstream
|
||||
);
|
||||
expect(selection.extent, const CodeLinePosition(
|
||||
index: 0,
|
||||
offset: 0,
|
||||
affinity: TextAffinity.upstream
|
||||
));
|
||||
}
|
||||
// collapsed and downstream
|
||||
{
|
||||
const CodeLineSelection selection = CodeLineSelection.collapsed(
|
||||
index: 0,
|
||||
offset: 0,
|
||||
affinity: TextAffinity.downstream
|
||||
);
|
||||
expect(selection.extent, const CodeLinePosition(
|
||||
index: 0,
|
||||
offset: 0,
|
||||
affinity: TextAffinity.downstream
|
||||
));
|
||||
}
|
||||
});
|
||||
|
||||
test('`start`', () {
|
||||
// Multi code line selected and base before extent
|
||||
{
|
||||
const CodeLineSelection selection = CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 0,
|
||||
extentIndex: 1,
|
||||
extentOffset: 1,
|
||||
);
|
||||
expect(selection.start, selection.base);
|
||||
}
|
||||
// Multi code line selected and base after extent
|
||||
{
|
||||
const CodeLineSelection selection = CodeLineSelection(
|
||||
extentIndex: 0,
|
||||
extentOffset: 0,
|
||||
baseIndex: 1,
|
||||
baseOffset: 1,
|
||||
);
|
||||
expect(selection.start, selection.extent);
|
||||
}
|
||||
// Single code line selected and base before extent
|
||||
{
|
||||
const CodeLineSelection selection = CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 0,
|
||||
extentIndex: 0,
|
||||
extentOffset: 1,
|
||||
);
|
||||
expect(selection.start, selection.base);
|
||||
}
|
||||
// Single code line selected and base after extent
|
||||
{
|
||||
const CodeLineSelection selection = CodeLineSelection(
|
||||
extentIndex: 0,
|
||||
extentOffset: 0,
|
||||
baseIndex: 0,
|
||||
baseOffset: 1,
|
||||
);
|
||||
expect(selection.start, selection.extent);
|
||||
}
|
||||
// collapsed
|
||||
{
|
||||
const CodeLineSelection selection = CodeLineSelection.collapsed(
|
||||
index: 0,
|
||||
offset: 0,
|
||||
);
|
||||
expect(selection.start, selection.base);
|
||||
expect(selection.start, selection.extent);
|
||||
}
|
||||
});
|
||||
|
||||
test('`end`', () {
|
||||
// Multi code line selected and base before extent
|
||||
{
|
||||
const CodeLineSelection selection = CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 0,
|
||||
extentIndex: 1,
|
||||
extentOffset: 1,
|
||||
);
|
||||
expect(selection.start, selection.base);
|
||||
}
|
||||
// Multi code line selected and base after extent
|
||||
{
|
||||
const CodeLineSelection selection = CodeLineSelection(
|
||||
extentIndex: 0,
|
||||
extentOffset: 0,
|
||||
baseIndex: 1,
|
||||
baseOffset: 1,
|
||||
);
|
||||
expect(selection.start, selection.extent);
|
||||
}
|
||||
// Single code line selected and base before extent
|
||||
{
|
||||
const CodeLineSelection selection = CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 0,
|
||||
extentIndex: 0,
|
||||
extentOffset: 1,
|
||||
);
|
||||
expect(selection.start, selection.base);
|
||||
}
|
||||
// Single code line selected and base after extent
|
||||
{
|
||||
const CodeLineSelection selection = CodeLineSelection(
|
||||
extentIndex: 0,
|
||||
extentOffset: 0,
|
||||
baseIndex: 0,
|
||||
baseOffset: 1,
|
||||
);
|
||||
expect(selection.start, selection.extent);
|
||||
}
|
||||
// collapsed
|
||||
{
|
||||
const CodeLineSelection selection = CodeLineSelection.collapsed(
|
||||
index: 0,
|
||||
offset: 0,
|
||||
);
|
||||
expect(selection.start, selection.base);
|
||||
expect(selection.start, selection.extent);
|
||||
}
|
||||
});
|
||||
|
||||
test('`startIndex`', () {
|
||||
{
|
||||
const CodeLineSelection selection = CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 0,
|
||||
extentIndex: 1,
|
||||
extentOffset: 1,
|
||||
);
|
||||
expect(selection.startIndex, 0);
|
||||
}
|
||||
{
|
||||
const CodeLineSelection selection = CodeLineSelection(
|
||||
extentIndex: 0,
|
||||
extentOffset: 0,
|
||||
baseIndex: 1,
|
||||
baseOffset: 1,
|
||||
);
|
||||
expect(selection.startIndex, 0);
|
||||
}
|
||||
});
|
||||
|
||||
test('`startOffset`', () {
|
||||
{
|
||||
const CodeLineSelection selection = CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 0,
|
||||
extentIndex: 1,
|
||||
extentOffset: 1,
|
||||
);
|
||||
expect(selection.startOffset, 0);
|
||||
}
|
||||
{
|
||||
const CodeLineSelection selection = CodeLineSelection(
|
||||
extentIndex: 0,
|
||||
extentOffset: 0,
|
||||
baseIndex: 1,
|
||||
baseOffset: 1,
|
||||
);
|
||||
expect(selection.startOffset, 0);
|
||||
}
|
||||
});
|
||||
|
||||
test('`endIndex`', () {
|
||||
{
|
||||
const CodeLineSelection selection = CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 0,
|
||||
extentIndex: 1,
|
||||
extentOffset: 1,
|
||||
);
|
||||
expect(selection.endIndex, 1);
|
||||
}
|
||||
{
|
||||
const CodeLineSelection selection = CodeLineSelection(
|
||||
extentIndex: 0,
|
||||
extentOffset: 0,
|
||||
baseIndex: 1,
|
||||
baseOffset: 1,
|
||||
);
|
||||
expect(selection.endIndex, 1);
|
||||
}
|
||||
});
|
||||
|
||||
test('`endOffset`', () {
|
||||
{
|
||||
const CodeLineSelection selection = CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 0,
|
||||
extentIndex: 1,
|
||||
extentOffset: 1,
|
||||
);
|
||||
expect(selection.endOffset, 1);
|
||||
}
|
||||
{
|
||||
const CodeLineSelection selection = CodeLineSelection(
|
||||
extentIndex: 0,
|
||||
extentOffset: 0,
|
||||
baseIndex: 1,
|
||||
baseOffset: 1,
|
||||
);
|
||||
expect(selection.endOffset, 1);
|
||||
}
|
||||
});
|
||||
|
||||
test('`isCollapsed`', () {
|
||||
{
|
||||
const CodeLineSelection selection = CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 0,
|
||||
extentIndex: 0,
|
||||
extentOffset: 0,
|
||||
);
|
||||
expect(selection.isCollapsed, true);
|
||||
}
|
||||
{
|
||||
const CodeLineSelection selection = CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 0,
|
||||
extentIndex: 0,
|
||||
extentOffset: 1,
|
||||
);
|
||||
expect(selection.isCollapsed, false);
|
||||
}
|
||||
{
|
||||
const CodeLineSelection selection = CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 0,
|
||||
extentIndex: 1,
|
||||
extentOffset: 0,
|
||||
);
|
||||
expect(selection.isCollapsed, false);
|
||||
}
|
||||
});
|
||||
|
||||
test('`isSameLine`', () {
|
||||
{
|
||||
const CodeLineSelection selection = CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 0,
|
||||
extentIndex: 0,
|
||||
extentOffset: 0,
|
||||
);
|
||||
expect(selection.isSameLine, true);
|
||||
}
|
||||
{
|
||||
const CodeLineSelection selection = CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 0,
|
||||
extentIndex: 0,
|
||||
extentOffset: 1,
|
||||
);
|
||||
expect(selection.isSameLine, true);
|
||||
}
|
||||
{
|
||||
const CodeLineSelection selection = CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 0,
|
||||
extentIndex: 1,
|
||||
extentOffset: 0,
|
||||
);
|
||||
expect(selection.isSameLine, false);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
group('CodeLineSelection method ', () {
|
||||
test('`contains()`', () {
|
||||
// Collapsed
|
||||
{
|
||||
const CodeLineSelection selection = CodeLineSelection.collapsed(
|
||||
index: 0,
|
||||
offset: 0
|
||||
);
|
||||
expect(selection.contains(selection), true);
|
||||
expect(selection.contains(const CodeLineSelection.collapsed(
|
||||
index: 0,
|
||||
offset: 1
|
||||
)), false);
|
||||
}
|
||||
// Single code line
|
||||
{
|
||||
const CodeLineSelection selection = CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 0,
|
||||
extentIndex: 0,
|
||||
extentOffset: 3,
|
||||
);
|
||||
expect(selection.contains(selection), true);
|
||||
expect(selection.contains(const CodeLineSelection.collapsed(
|
||||
index: 0,
|
||||
offset: 1
|
||||
)), true);
|
||||
expect(selection.contains(const CodeLineSelection.collapsed(
|
||||
index: 0,
|
||||
offset: 4
|
||||
)), false);
|
||||
expect(selection.contains(const CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 0,
|
||||
extentIndex: 0,
|
||||
extentOffset: 1
|
||||
)), true);
|
||||
}
|
||||
// Multi code line
|
||||
{
|
||||
const CodeLineSelection selection = CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 0,
|
||||
extentIndex: 3,
|
||||
extentOffset: 3,
|
||||
);
|
||||
expect(selection.contains(selection), true);
|
||||
expect(selection.contains(const CodeLineSelection.collapsed(
|
||||
index: 0,
|
||||
offset: 1
|
||||
)), true);
|
||||
expect(selection.contains(const CodeLineSelection.collapsed(
|
||||
index: 0,
|
||||
offset: 4
|
||||
)), true);
|
||||
expect(selection.contains(const CodeLineSelection(
|
||||
baseIndex: 1,
|
||||
baseOffset: 0,
|
||||
extentIndex: 1,
|
||||
extentOffset: 1000
|
||||
)), true);
|
||||
expect(selection.contains(const CodeLineSelection(
|
||||
baseIndex: 1,
|
||||
baseOffset: 0,
|
||||
extentIndex: 2,
|
||||
extentOffset: 1000
|
||||
)), true);
|
||||
expect(selection.contains(const CodeLineSelection(
|
||||
baseIndex: 1,
|
||||
baseOffset: 0,
|
||||
extentIndex: 3,
|
||||
extentOffset: 1000
|
||||
)), false);
|
||||
}
|
||||
});
|
||||
|
||||
test('`copyWith()`', () {
|
||||
const CodeLineSelection selection = CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 0,
|
||||
extentIndex: 3,
|
||||
extentOffset: 3,
|
||||
);
|
||||
expect(selection.copyWith(), selection);
|
||||
expect(selection.copyWith(
|
||||
baseIndex: 3,
|
||||
baseOffset: 3,
|
||||
extentIndex: 0,
|
||||
extentOffset: 0,
|
||||
baseAffinity: TextAffinity.upstream,
|
||||
extentAffinity: TextAffinity.upstream
|
||||
), const CodeLineSelection(
|
||||
baseIndex: 3,
|
||||
baseOffset: 3,
|
||||
extentIndex: 0,
|
||||
extentOffset: 0,
|
||||
baseAffinity: TextAffinity.upstream,
|
||||
extentAffinity: TextAffinity.upstream
|
||||
));
|
||||
expect(selection.copyWith(
|
||||
baseIndex: 3,
|
||||
baseAffinity: TextAffinity.upstream
|
||||
), const CodeLineSelection(
|
||||
baseIndex: 3,
|
||||
baseOffset: 0,
|
||||
extentIndex: 3,
|
||||
extentOffset: 3,
|
||||
baseAffinity: TextAffinity.upstream
|
||||
));
|
||||
expect(selection.copyWith(
|
||||
baseOffset: 3,
|
||||
baseAffinity: TextAffinity.upstream
|
||||
), const CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 3,
|
||||
extentIndex: 3,
|
||||
extentOffset: 3,
|
||||
baseAffinity: TextAffinity.upstream
|
||||
));
|
||||
expect(selection.copyWith(
|
||||
extentIndex: 0,
|
||||
extentAffinity: TextAffinity.upstream
|
||||
), const CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 0,
|
||||
extentIndex: 0,
|
||||
extentOffset: 3,
|
||||
extentAffinity: TextAffinity.upstream
|
||||
));
|
||||
expect(selection.copyWith(
|
||||
extentOffset: 0,
|
||||
extentAffinity: TextAffinity.upstream
|
||||
), const CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 0,
|
||||
extentIndex: 3,
|
||||
extentOffset: 0,
|
||||
extentAffinity: TextAffinity.upstream
|
||||
));
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,266 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:re_editor/re_editor.dart';
|
||||
|
||||
void main() {
|
||||
group('CodeLine getter ', () {
|
||||
test('`length`', () {
|
||||
{
|
||||
const CodeLine codeLine = CodeLine.empty;
|
||||
expect(codeLine.length, 0);
|
||||
}
|
||||
{
|
||||
const CodeLine codeLine = CodeLine('abc');
|
||||
expect(codeLine.length, 3);
|
||||
}
|
||||
{
|
||||
const CodeLine codeLine = CodeLine('abc', [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar')
|
||||
]);
|
||||
expect(codeLine.length, 3);
|
||||
}
|
||||
});
|
||||
|
||||
test('`chunkParent`', () {
|
||||
{
|
||||
const CodeLine codeLine = CodeLine('abc');
|
||||
expect(codeLine.chunkParent, false);
|
||||
}
|
||||
{
|
||||
const CodeLine codeLine = CodeLine('abc', [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar')
|
||||
]);
|
||||
expect(codeLine.chunkParent, true);
|
||||
}
|
||||
});
|
||||
|
||||
test('`lineCount`', () {
|
||||
{
|
||||
const CodeLine codeLine = CodeLine.empty;
|
||||
expect(codeLine.lineCount, 1);
|
||||
}
|
||||
{
|
||||
const CodeLine codeLine = CodeLine('abc');
|
||||
expect(codeLine.lineCount, 1);
|
||||
}
|
||||
{
|
||||
const CodeLine codeLine = CodeLine('abc', [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar')
|
||||
]);
|
||||
expect(codeLine.lineCount, 3);
|
||||
}
|
||||
{
|
||||
const CodeLine codeLine = CodeLine('abc', [
|
||||
CodeLine('foo', [
|
||||
CodeLine('inner', [
|
||||
CodeLine('inner1'),
|
||||
CodeLine('inner2'),
|
||||
CodeLine('inner3'),
|
||||
])
|
||||
]),
|
||||
CodeLine('bar', [
|
||||
CodeLine('inner', [
|
||||
CodeLine('inner4'),
|
||||
CodeLine('inner5'),
|
||||
CodeLine('inner6'),
|
||||
CodeLine('inner7'),
|
||||
])
|
||||
]),
|
||||
]);
|
||||
expect(codeLine.lineCount, 12);
|
||||
}
|
||||
});
|
||||
|
||||
test('`charCount`', () {
|
||||
{
|
||||
const CodeLine codeLine = CodeLine.empty;
|
||||
expect(codeLine.charCount, 0);
|
||||
}
|
||||
{
|
||||
const CodeLine codeLine = CodeLine('abc');
|
||||
expect(codeLine.charCount, 3);
|
||||
}
|
||||
{
|
||||
const CodeLine codeLine = CodeLine('abc', [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar')
|
||||
]);
|
||||
expect(codeLine.charCount, 9);
|
||||
}
|
||||
{
|
||||
const CodeLine codeLine = CodeLine('abc', [
|
||||
CodeLine('foo', [
|
||||
CodeLine('inner', [
|
||||
CodeLine('inner1'),
|
||||
CodeLine('inner2'),
|
||||
CodeLine('inner3'),
|
||||
])
|
||||
]),
|
||||
CodeLine('bar', [
|
||||
CodeLine('inner', [
|
||||
CodeLine('inner4'),
|
||||
CodeLine('inner5'),
|
||||
CodeLine('inner6'),
|
||||
CodeLine('inner7'),
|
||||
])
|
||||
]),
|
||||
]);
|
||||
expect(codeLine.charCount, 61);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
group('CodeLine method ', () {
|
||||
test('`toString()`', () {
|
||||
{
|
||||
const CodeLine codeLine = CodeLine('abc');
|
||||
expect(codeLine.toString(), 'abc');
|
||||
}
|
||||
{
|
||||
const CodeLine codeLine = CodeLine('abc', [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar')
|
||||
]);
|
||||
expect(codeLine.toString(), 'abc');
|
||||
}
|
||||
});
|
||||
|
||||
test('`asString()`', () {
|
||||
{
|
||||
const CodeLine codeLine = CodeLine('abc');
|
||||
expect(codeLine.asString(0, TextLineBreak.lf), 'abc');
|
||||
expect(codeLine.asString(1, TextLineBreak.lf), 'bc');
|
||||
expect(codeLine.asString(3, TextLineBreak.lf), '');
|
||||
}
|
||||
{
|
||||
const CodeLine codeLine = CodeLine('abc', [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar')
|
||||
]);
|
||||
expect(codeLine.asString(0, TextLineBreak.lf), 'abc\nfoo\nbar');
|
||||
expect(codeLine.asString(0, TextLineBreak.crlf), 'abc\r\nfoo\r\nbar');
|
||||
expect(codeLine.asString(1, TextLineBreak.lf), 'bc\nfoo\nbar');
|
||||
expect(codeLine.asString(3, TextLineBreak.lf), '\nfoo\nbar');
|
||||
}
|
||||
{
|
||||
const CodeLine codeLine = CodeLine('abc', [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar'),
|
||||
CodeLine('123', [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar'),
|
||||
])
|
||||
]);
|
||||
expect(codeLine.asString(0, TextLineBreak.lf), 'abc\nfoo\nbar\n123\nfoo\nbar');
|
||||
}
|
||||
});
|
||||
|
||||
test('`flat()`', () {
|
||||
{
|
||||
const CodeLine codeLine = CodeLine('abc');
|
||||
expect(codeLine.flat(), const ['abc']);
|
||||
}
|
||||
{
|
||||
const CodeLine codeLine = CodeLine('abc', [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar')
|
||||
]);
|
||||
expect(codeLine.flat(), const ['abc', 'foo', 'bar']);
|
||||
}
|
||||
{
|
||||
const CodeLine codeLine = CodeLine('abc', [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar'),
|
||||
CodeLine('123', [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar'),
|
||||
])
|
||||
]);
|
||||
expect(codeLine.flat(), const ['abc', 'foo', 'bar', '123', 'foo', 'bar']);
|
||||
}
|
||||
});
|
||||
|
||||
test('`copyWith()`', () {
|
||||
{
|
||||
const CodeLine codeLine = CodeLine('abc');
|
||||
expect(codeLine.copyWith(), codeLine);
|
||||
}
|
||||
{
|
||||
const CodeLine codeLine = CodeLine('abc', [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar')
|
||||
]);
|
||||
expect(codeLine.copyWith(), codeLine);
|
||||
}
|
||||
{
|
||||
final CodeLine codeLine = const CodeLine('abc', [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar')
|
||||
]).copyWith(
|
||||
text: '123',
|
||||
);
|
||||
expect(codeLine.text, '123');
|
||||
expect(codeLine.chunks, const [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar')
|
||||
]);
|
||||
}
|
||||
{
|
||||
final CodeLine codeLine = const CodeLine('abc', [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar')
|
||||
]).copyWith(
|
||||
text: '123',
|
||||
chunks: const []
|
||||
);
|
||||
expect(codeLine.text, '123');
|
||||
expect(codeLine.chunks, const []);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
group('CodeLine operator ', () {
|
||||
test('`==`', () {
|
||||
{
|
||||
final CodeLine codeLine1 = CodeLine('abc' * 1);
|
||||
final CodeLine codeLine2 = CodeLine('abc' * 1);
|
||||
expect(codeLine1, codeLine2);
|
||||
}
|
||||
{
|
||||
final CodeLine codeLine1 = CodeLine('abc' * 1, [
|
||||
CodeLine('foo' * 1),
|
||||
CodeLine('bar' * 1)
|
||||
]);
|
||||
final CodeLine codeLine2 = CodeLine('abc' * 1, [
|
||||
CodeLine('foo' * 1),
|
||||
CodeLine('bar' * 1)
|
||||
]);
|
||||
expect(codeLine1, codeLine2);
|
||||
}
|
||||
{
|
||||
final CodeLine codeLine1 = CodeLine('abc' * 1, [
|
||||
const CodeLine('foo'),
|
||||
const CodeLine('bar')
|
||||
]);
|
||||
final CodeLine codeLine2 = CodeLine('abc' * 2, [
|
||||
const CodeLine('foo'),
|
||||
const CodeLine('bar')
|
||||
]);
|
||||
expect(codeLine1 == codeLine2, false);
|
||||
}
|
||||
{
|
||||
final CodeLine codeLine1 = CodeLine('abc' * 1, [
|
||||
CodeLine('foo' * 1),
|
||||
CodeLine('bar' * 1)
|
||||
]);
|
||||
final CodeLine codeLine2 = CodeLine('abc' * 1, [
|
||||
CodeLine('foo' * 2),
|
||||
CodeLine('bar' * 2)
|
||||
]);
|
||||
expect(codeLine1 == codeLine2, false);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,986 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:re_editor/re_editor.dart';
|
||||
|
||||
void main() {
|
||||
group('CodeFindController getter ', () {
|
||||
test('`allMatchSelections`', () async {
|
||||
{
|
||||
final CodeFindController controller = CodeFindController(CodeLineEditingController());
|
||||
expect(controller.allMatchSelections, null);
|
||||
controller.close();
|
||||
}
|
||||
{
|
||||
final CodeFindController controller = CodeFindController(CodeLineEditingController.fromText('abc'), const CodeFindValue(
|
||||
option: CodeFindOption(
|
||||
pattern: 'a',
|
||||
caseSensitive: false,
|
||||
regex: false
|
||||
),
|
||||
replaceMode: false
|
||||
));
|
||||
expect(controller.allMatchSelections, null);
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
expect(controller.allMatchSelections, const [
|
||||
CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 0,
|
||||
extentIndex: 0,
|
||||
extentOffset: 1
|
||||
)
|
||||
]);
|
||||
controller.close();
|
||||
}
|
||||
{
|
||||
final CodeFindController controller = CodeFindController(CodeLineEditingController.fromText('abc\nfoo\nbar'), const CodeFindValue(
|
||||
option: CodeFindOption(
|
||||
pattern: 'a',
|
||||
caseSensitive: false,
|
||||
regex: false
|
||||
),
|
||||
replaceMode: false
|
||||
));
|
||||
expect(controller.allMatchSelections, null);
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
expect(controller.allMatchSelections, const [
|
||||
CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 0,
|
||||
extentIndex: 0,
|
||||
extentOffset: 1
|
||||
),
|
||||
CodeLineSelection(
|
||||
baseIndex: 2,
|
||||
baseOffset: 1,
|
||||
extentIndex: 2,
|
||||
extentOffset: 2
|
||||
)
|
||||
]);
|
||||
controller.close();
|
||||
}
|
||||
{
|
||||
final CodeFindController controller = CodeFindController(CodeLineEditingController(
|
||||
codeLines: CodeLines.of(const [
|
||||
CodeLine('abc', [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar')
|
||||
]),
|
||||
CodeLine('abc', [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar')
|
||||
]),
|
||||
CodeLine('abc', [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar')
|
||||
])
|
||||
])
|
||||
), const CodeFindValue(
|
||||
option: CodeFindOption(
|
||||
pattern: 'a',
|
||||
caseSensitive: false,
|
||||
regex: false
|
||||
),
|
||||
replaceMode: false
|
||||
));
|
||||
expect(controller.allMatchSelections, null);
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
expect(controller.allMatchSelections, const [
|
||||
CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 0,
|
||||
extentIndex: 0,
|
||||
extentOffset: 1
|
||||
),
|
||||
CodeLineSelection(
|
||||
baseIndex: 1,
|
||||
baseOffset: 0,
|
||||
extentIndex: 1,
|
||||
extentOffset: 1
|
||||
),
|
||||
CodeLineSelection(
|
||||
baseIndex: 2,
|
||||
baseOffset: 0,
|
||||
extentIndex: 2,
|
||||
extentOffset: 1
|
||||
),
|
||||
]);
|
||||
controller.close();
|
||||
}
|
||||
});
|
||||
|
||||
test('`currentMatchSelection`', () async {
|
||||
{
|
||||
final CodeFindController controller = CodeFindController(CodeLineEditingController());
|
||||
expect(controller.currentMatchSelection, null);
|
||||
controller.close();
|
||||
}
|
||||
{
|
||||
final CodeFindController controller = CodeFindController(CodeLineEditingController.fromText('abc'), const CodeFindValue(
|
||||
option: CodeFindOption(
|
||||
pattern: 'a',
|
||||
caseSensitive: false,
|
||||
regex: false
|
||||
),
|
||||
replaceMode: false
|
||||
));
|
||||
expect(controller.currentMatchSelection, null);
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
expect(controller.currentMatchSelection, const CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 0,
|
||||
extentIndex: 0,
|
||||
extentOffset: 1
|
||||
));
|
||||
controller.close();
|
||||
}
|
||||
{
|
||||
final CodeFindController controller = CodeFindController(CodeLineEditingController.fromText('abc\nfoo\nbar'), const CodeFindValue(
|
||||
option: CodeFindOption(
|
||||
pattern: 'a',
|
||||
caseSensitive: false,
|
||||
regex: false
|
||||
),
|
||||
replaceMode: false
|
||||
));
|
||||
expect(controller.currentMatchSelection, null);
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
expect(controller.currentMatchSelection, const CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 0,
|
||||
extentIndex: 0,
|
||||
extentOffset: 1
|
||||
));
|
||||
controller.nextMatch();
|
||||
expect(controller.currentMatchSelection, const CodeLineSelection(
|
||||
baseIndex: 2,
|
||||
baseOffset: 1,
|
||||
extentIndex: 2,
|
||||
extentOffset: 2
|
||||
));
|
||||
controller.close();
|
||||
}
|
||||
{
|
||||
final CodeFindController controller = CodeFindController(CodeLineEditingController(
|
||||
codeLines: CodeLines.of(const [
|
||||
CodeLine('abc', [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar')
|
||||
]),
|
||||
CodeLine('abc', [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar')
|
||||
]),
|
||||
CodeLine('abc', [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar')
|
||||
])
|
||||
])
|
||||
), const CodeFindValue(
|
||||
option: CodeFindOption(
|
||||
pattern: 'a',
|
||||
caseSensitive: false,
|
||||
regex: false
|
||||
),
|
||||
replaceMode: false
|
||||
));
|
||||
expect(controller.currentMatchSelection, null);
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
expect(controller.currentMatchSelection, const CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 0,
|
||||
extentIndex: 0,
|
||||
extentOffset: 1
|
||||
));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
group('CodeFindController method ', () {
|
||||
test('`findMode`', () async {
|
||||
{
|
||||
final CodeFindController controller = CodeFindController(CodeLineEditingController.fromText('abc'));
|
||||
expect(controller.value, null);
|
||||
controller.findMode();
|
||||
expect(controller.value, const CodeFindValue(
|
||||
option: CodeFindOption(
|
||||
pattern: '',
|
||||
caseSensitive: false,
|
||||
regex: false
|
||||
),
|
||||
replaceMode: false
|
||||
));
|
||||
}
|
||||
{
|
||||
final CodeLineEditingController editingController = CodeLineEditingController.fromText('abc');
|
||||
editingController.selection = const CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 1,
|
||||
extentIndex: 0,
|
||||
extentOffset: 2
|
||||
);
|
||||
final CodeFindController controller = CodeFindController(editingController);
|
||||
expect(controller.value, null);
|
||||
controller.findMode();
|
||||
expect(controller.value, const CodeFindValue(
|
||||
option: CodeFindOption(
|
||||
pattern: 'b',
|
||||
caseSensitive: false,
|
||||
regex: false
|
||||
),
|
||||
replaceMode: false,
|
||||
searching: true
|
||||
));
|
||||
expect(controller.findInputController.text, 'b');
|
||||
expect(controller.findInputController.selection, const TextSelection(
|
||||
baseOffset: 0,
|
||||
extentOffset: 1
|
||||
));
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
expect(controller.value, CodeFindValue(
|
||||
option: const CodeFindOption(
|
||||
pattern: 'b',
|
||||
caseSensitive: false,
|
||||
regex: false
|
||||
),
|
||||
replaceMode: false,
|
||||
result: CodeFindResult(
|
||||
index: 0,
|
||||
matches: const [
|
||||
CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 1,
|
||||
extentIndex: 0,
|
||||
extentOffset: 2
|
||||
)
|
||||
],
|
||||
option: const CodeFindOption(
|
||||
pattern: 'b',
|
||||
caseSensitive: false,
|
||||
regex: false
|
||||
),
|
||||
codeLines: CodeLines.of([
|
||||
const CodeLine('abc')
|
||||
]),
|
||||
dirty: false
|
||||
)
|
||||
));
|
||||
}
|
||||
});
|
||||
|
||||
test('`replaceMode`', () async {
|
||||
{
|
||||
final CodeFindController controller = CodeFindController(CodeLineEditingController.fromText('abc'));
|
||||
expect(controller.value, null);
|
||||
controller.replaceMode();
|
||||
expect(controller.value, const CodeFindValue(
|
||||
option: CodeFindOption(
|
||||
pattern: '',
|
||||
caseSensitive: false,
|
||||
regex: false
|
||||
),
|
||||
replaceMode: true,
|
||||
));
|
||||
}
|
||||
{
|
||||
final CodeLineEditingController editingController = CodeLineEditingController.fromText('abc');
|
||||
editingController.selection = const CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 1,
|
||||
extentIndex: 0,
|
||||
extentOffset: 2
|
||||
);
|
||||
final CodeFindController controller = CodeFindController(editingController);
|
||||
expect(controller.value, null);
|
||||
controller.replaceMode();
|
||||
expect(controller.value, const CodeFindValue(
|
||||
option: CodeFindOption(
|
||||
pattern: 'b',
|
||||
caseSensitive: false,
|
||||
regex: false
|
||||
),
|
||||
replaceMode: true,
|
||||
searching: true
|
||||
));
|
||||
expect(controller.findInputController.text, 'b');
|
||||
expect(controller.findInputController.selection, const TextSelection(
|
||||
baseOffset: 0,
|
||||
extentOffset: 1
|
||||
));
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
expect(controller.value, CodeFindValue(
|
||||
option: const CodeFindOption(
|
||||
pattern: 'b',
|
||||
caseSensitive: false,
|
||||
regex: false
|
||||
),
|
||||
replaceMode: true,
|
||||
result: CodeFindResult(
|
||||
index: 0,
|
||||
matches: const [
|
||||
CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 1,
|
||||
extentIndex: 0,
|
||||
extentOffset: 2
|
||||
)
|
||||
],
|
||||
option: const CodeFindOption(
|
||||
pattern: 'b',
|
||||
caseSensitive: false,
|
||||
regex: false
|
||||
),
|
||||
codeLines: CodeLines.of([
|
||||
const CodeLine('abc')
|
||||
]),
|
||||
dirty: false
|
||||
)
|
||||
));
|
||||
}
|
||||
});
|
||||
|
||||
test('`focusOnFindInput`', () {
|
||||
final CodeFindController controller = CodeFindController(CodeLineEditingController());
|
||||
controller.findInputController.text = 'abc';
|
||||
controller.focusOnFindInput();
|
||||
expect(controller.findInputController.selection, const TextSelection(
|
||||
baseOffset: 0,
|
||||
extentOffset: 3
|
||||
));
|
||||
});
|
||||
|
||||
test('`focusOnReplaceInput`', () {
|
||||
final CodeFindController controller = CodeFindController(CodeLineEditingController());
|
||||
controller.replaceInputController.text = 'abc';
|
||||
controller.focusOnReplaceInput();
|
||||
expect(controller.replaceInputController.selection, const TextSelection(
|
||||
baseOffset: 0,
|
||||
extentOffset: 3
|
||||
));
|
||||
});
|
||||
|
||||
test('`toggleMode`', () {
|
||||
final CodeFindController controller = CodeFindController(CodeLineEditingController.fromText('abc'));
|
||||
controller.findMode();
|
||||
expect(controller.value?.replaceMode, false);
|
||||
controller.toggleMode();
|
||||
expect(controller.value?.replaceMode, true);
|
||||
controller.toggleMode();
|
||||
expect(controller.value?.replaceMode, false);
|
||||
controller.toggleMode();
|
||||
expect(controller.value?.replaceMode, true);
|
||||
});
|
||||
|
||||
test('`close`', () {
|
||||
final CodeFindController controller = CodeFindController(CodeLineEditingController.fromText('abc'));
|
||||
controller.findMode();
|
||||
expect(controller.value != null, true);
|
||||
controller.close();
|
||||
expect(controller.value != null, false);
|
||||
controller.findMode();
|
||||
expect(controller.value != null, true);
|
||||
controller.close();
|
||||
expect(controller.value != null, false);
|
||||
});
|
||||
|
||||
test('`toggleRegex`', () {
|
||||
final CodeFindController controller = CodeFindController(CodeLineEditingController.fromText('abc'));
|
||||
controller.findMode();
|
||||
expect(controller.value?.option.regex, false);
|
||||
controller.toggleRegex();
|
||||
expect(controller.value?.option.regex, true);
|
||||
controller.toggleRegex();
|
||||
expect(controller.value?.option.regex, false);
|
||||
controller.toggleRegex();
|
||||
expect(controller.value?.option.regex, true);
|
||||
});
|
||||
|
||||
test('`toggleCaseSensitive`', () {
|
||||
final CodeFindController controller = CodeFindController(CodeLineEditingController.fromText('abc'));
|
||||
controller.findMode();
|
||||
expect(controller.value?.option.caseSensitive, false);
|
||||
controller.toggleCaseSensitive();
|
||||
expect(controller.value?.option.caseSensitive, true);
|
||||
controller.toggleCaseSensitive();
|
||||
expect(controller.value?.option.caseSensitive, false);
|
||||
controller.toggleCaseSensitive();
|
||||
expect(controller.value?.option.caseSensitive, true);
|
||||
});
|
||||
|
||||
test('`previousMatch & nextMatch`', () async {
|
||||
{
|
||||
final CodeFindController controller = CodeFindController(CodeLineEditingController.fromText('abcabcabc'));
|
||||
controller.findMode();
|
||||
controller.findInputController.text = 'a';
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
expect(controller.value, CodeFindValue(
|
||||
option: const CodeFindOption(
|
||||
pattern: 'a',
|
||||
caseSensitive: false,
|
||||
regex: false
|
||||
),
|
||||
replaceMode: false,
|
||||
result: CodeFindResult(
|
||||
index: 0,
|
||||
matches: const [
|
||||
CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 0,
|
||||
extentIndex: 0,
|
||||
extentOffset: 1
|
||||
),
|
||||
CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 3,
|
||||
extentIndex: 0,
|
||||
extentOffset: 4
|
||||
),
|
||||
CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 6,
|
||||
extentIndex: 0,
|
||||
extentOffset: 7
|
||||
)
|
||||
],
|
||||
option: const CodeFindOption(
|
||||
pattern: 'a',
|
||||
caseSensitive: false,
|
||||
regex: false
|
||||
),
|
||||
codeLines: CodeLines.of([
|
||||
const CodeLine('abcabcabc')
|
||||
]),
|
||||
dirty: false
|
||||
)
|
||||
));
|
||||
controller.previousMatch();
|
||||
expect(controller.value, CodeFindValue(
|
||||
option: const CodeFindOption(
|
||||
pattern: 'a',
|
||||
caseSensitive: false,
|
||||
regex: false
|
||||
),
|
||||
replaceMode: false,
|
||||
result: CodeFindResult(
|
||||
index: 2,
|
||||
matches: const [
|
||||
CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 0,
|
||||
extentIndex: 0,
|
||||
extentOffset: 1
|
||||
),
|
||||
CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 3,
|
||||
extentIndex: 0,
|
||||
extentOffset: 4
|
||||
),
|
||||
CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 6,
|
||||
extentIndex: 0,
|
||||
extentOffset: 7
|
||||
)
|
||||
],
|
||||
option: const CodeFindOption(
|
||||
pattern: 'a',
|
||||
caseSensitive: false,
|
||||
regex: false
|
||||
),
|
||||
codeLines: CodeLines.of([
|
||||
const CodeLine('abcabcabc')
|
||||
]),
|
||||
dirty: false
|
||||
)
|
||||
));
|
||||
controller.previousMatch();
|
||||
expect(controller.value, CodeFindValue(
|
||||
option: const CodeFindOption(
|
||||
pattern: 'a',
|
||||
caseSensitive: false,
|
||||
regex: false
|
||||
),
|
||||
replaceMode: false,
|
||||
result: CodeFindResult(
|
||||
index: 1,
|
||||
matches: [
|
||||
const CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 0,
|
||||
extentIndex: 0,
|
||||
extentOffset: 1
|
||||
),
|
||||
const CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 3,
|
||||
extentIndex: 0,
|
||||
extentOffset: 4
|
||||
),
|
||||
const CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 6,
|
||||
extentIndex: 0,
|
||||
extentOffset: 7
|
||||
)
|
||||
],
|
||||
option: const CodeFindOption(
|
||||
pattern: 'a',
|
||||
caseSensitive: false,
|
||||
regex: false
|
||||
),
|
||||
codeLines: CodeLines.of([
|
||||
const CodeLine('abcabcabc')
|
||||
]),
|
||||
dirty: false
|
||||
)
|
||||
));
|
||||
controller.nextMatch();
|
||||
expect(controller.value, CodeFindValue(
|
||||
option: const CodeFindOption(
|
||||
pattern: 'a',
|
||||
caseSensitive: false,
|
||||
regex: false
|
||||
),
|
||||
replaceMode: false,
|
||||
result: CodeFindResult(
|
||||
index: 2,
|
||||
matches: const [
|
||||
CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 0,
|
||||
extentIndex: 0,
|
||||
extentOffset: 1
|
||||
),
|
||||
CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 3,
|
||||
extentIndex: 0,
|
||||
extentOffset: 4
|
||||
),
|
||||
CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 6,
|
||||
extentIndex: 0,
|
||||
extentOffset: 7
|
||||
)
|
||||
],
|
||||
option: const CodeFindOption(
|
||||
pattern: 'a',
|
||||
caseSensitive: false,
|
||||
regex: false
|
||||
),
|
||||
codeLines: CodeLines.of(const [
|
||||
CodeLine('abcabcabc')
|
||||
]),
|
||||
dirty: false
|
||||
)
|
||||
));
|
||||
controller.nextMatch();
|
||||
expect(controller.value, CodeFindValue(
|
||||
option: const CodeFindOption(
|
||||
pattern: 'a',
|
||||
caseSensitive: false,
|
||||
regex: false
|
||||
),
|
||||
replaceMode: false,
|
||||
result: CodeFindResult(
|
||||
index: 0,
|
||||
matches: const [
|
||||
CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 0,
|
||||
extentIndex: 0,
|
||||
extentOffset: 1
|
||||
),
|
||||
CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 3,
|
||||
extentIndex: 0,
|
||||
extentOffset: 4
|
||||
),
|
||||
CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 6,
|
||||
extentIndex: 0,
|
||||
extentOffset: 7
|
||||
)
|
||||
],
|
||||
option: const CodeFindOption(
|
||||
pattern: 'a',
|
||||
caseSensitive: false,
|
||||
regex: false
|
||||
),
|
||||
codeLines: CodeLines.of(const [
|
||||
CodeLine('abcabcabc')
|
||||
]),
|
||||
dirty: false
|
||||
)
|
||||
));
|
||||
}
|
||||
// Test auto expand chubnk
|
||||
{
|
||||
final CodeLineEditingController editingController = CodeLineEditingController(
|
||||
codeLines: CodeLines.of(const [
|
||||
CodeLine('abc', [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar'),
|
||||
]),
|
||||
CodeLine('abc', [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar'),
|
||||
]),
|
||||
CodeLine('abc', [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar'),
|
||||
]),
|
||||
CodeLine('abc', [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar'),
|
||||
])
|
||||
]
|
||||
));
|
||||
final CodeFindController controller = CodeFindController(editingController);
|
||||
controller.findMode();
|
||||
controller.findInputController.text = 'a';
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
expect(editingController.codeLines, CodeLines.of(const [
|
||||
CodeLine('abc', [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar'),
|
||||
]),
|
||||
CodeLine('abc', [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar'),
|
||||
]),
|
||||
CodeLine('abc', [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar'),
|
||||
]),
|
||||
CodeLine('abc', [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar'),
|
||||
])
|
||||
]));
|
||||
controller.nextMatch();
|
||||
expect(editingController.codeLines, CodeLines.of(const [
|
||||
CodeLine('abc'),
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar'),
|
||||
CodeLine('abc', [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar'),
|
||||
]),
|
||||
CodeLine('abc', [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar'),
|
||||
]),
|
||||
CodeLine('abc', [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar'),
|
||||
])
|
||||
]));
|
||||
controller.nextMatch();
|
||||
expect(editingController.codeLines, CodeLines.of(const [
|
||||
CodeLine('abc'),
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar'),
|
||||
CodeLine('abc', [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar'),
|
||||
]),
|
||||
CodeLine('abc', [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar'),
|
||||
]),
|
||||
CodeLine('abc', [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar'),
|
||||
])
|
||||
]));
|
||||
controller.previousMatch();
|
||||
expect(editingController.codeLines, CodeLines.of(const [
|
||||
CodeLine('abc'),
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar'),
|
||||
CodeLine('abc', [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar'),
|
||||
]),
|
||||
CodeLine('abc', [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar'),
|
||||
]),
|
||||
CodeLine('abc', [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar'),
|
||||
])
|
||||
]));
|
||||
controller.previousMatch();
|
||||
expect(editingController.codeLines, CodeLines.of(const [
|
||||
CodeLine('abc'),
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar'),
|
||||
CodeLine('abc', [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar'),
|
||||
]),
|
||||
CodeLine('abc', [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar'),
|
||||
]),
|
||||
CodeLine('abc', [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar'),
|
||||
])
|
||||
]));
|
||||
controller.previousMatch();
|
||||
expect(editingController.codeLines, CodeLines.of(const [
|
||||
CodeLine('abc'),
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar'),
|
||||
CodeLine('abc', [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar'),
|
||||
]),
|
||||
CodeLine('abc', [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar'),
|
||||
]),
|
||||
CodeLine('abc'),
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar'),
|
||||
]));
|
||||
}
|
||||
});
|
||||
|
||||
test('`replaceMatch`', () async {
|
||||
{
|
||||
final CodeLineEditingController editingController = CodeLineEditingController.fromText('abcabcabc');
|
||||
final CodeFindController controller = CodeFindController(editingController);
|
||||
controller.replaceMode();
|
||||
controller.findInputController.text = 'a';
|
||||
controller.replaceInputController.text = 'b';
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
controller.replaceMatch();
|
||||
expect(editingController.codeLines, CodeLines.of(const [
|
||||
CodeLine('bbcabcabc')
|
||||
]));
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
controller.replaceMatch();
|
||||
expect(editingController.codeLines, CodeLines.of(const [
|
||||
CodeLine('bbcbbcabc')
|
||||
]));
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
controller.replaceMatch();
|
||||
expect(editingController.codeLines, CodeLines.of(const [
|
||||
CodeLine('bbcbbcbbc')
|
||||
]));
|
||||
}
|
||||
// replace with same text
|
||||
{
|
||||
final CodeLineEditingController editingController = CodeLineEditingController.fromText('abcabcabc');
|
||||
final CodeFindController controller = CodeFindController(editingController);
|
||||
controller.replaceMode();
|
||||
controller.findInputController.text = 'a';
|
||||
controller.replaceInputController.text = 'a';
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
controller.replaceMatch();
|
||||
expect(editingController.codeLines, CodeLines.of(const [
|
||||
CodeLine('abcabcabc')
|
||||
]));
|
||||
expect(editingController.selection, const CodeLineSelection.collapsed(
|
||||
index: 0,
|
||||
offset: 1
|
||||
));
|
||||
expect(controller.value?.result?.index, 1);
|
||||
expect(controller.value?.result?.dirty, false);
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
controller.replaceMatch();
|
||||
expect(editingController.codeLines, CodeLines.of(const [
|
||||
CodeLine('abcabcabc')
|
||||
]));
|
||||
expect(editingController.selection, const CodeLineSelection.collapsed(
|
||||
index: 0,
|
||||
offset: 4
|
||||
));
|
||||
expect(controller.value?.result?.index, 2);
|
||||
expect(controller.value?.result?.dirty, false);
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
controller.replaceMatch();
|
||||
expect(editingController.codeLines, CodeLines.of(const [
|
||||
CodeLine('abcabcabc')
|
||||
]));
|
||||
expect(editingController.selection, const CodeLineSelection.collapsed(
|
||||
index: 0,
|
||||
offset: 7
|
||||
));
|
||||
expect(controller.value?.result?.index, 0);
|
||||
expect(controller.value?.result?.dirty, false);
|
||||
}
|
||||
// Test code line chunks
|
||||
{
|
||||
final CodeLineEditingController editingController = CodeLineEditingController(
|
||||
codeLines: CodeLines.of(const [
|
||||
CodeLine('abc', [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar')
|
||||
]),
|
||||
CodeLine('abc', [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar')
|
||||
]),
|
||||
CodeLine('abc', [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar')
|
||||
])
|
||||
])
|
||||
);
|
||||
final CodeFindController controller = CodeFindController(editingController);
|
||||
controller.replaceMode();
|
||||
controller.findInputController.text = 'a';
|
||||
controller.replaceInputController.text = 'b';
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
controller.replaceMatch();
|
||||
expect(editingController.codeLines, CodeLines.of(const [
|
||||
CodeLine('bbc'),
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar'),
|
||||
CodeLine('abc', [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar')
|
||||
]),
|
||||
CodeLine('abc', [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar')
|
||||
])
|
||||
]));
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
controller.replaceMatch();
|
||||
expect(editingController.codeLines, CodeLines.of(const [
|
||||
CodeLine('bbc'),
|
||||
CodeLine('foo'),
|
||||
CodeLine('bbr'),
|
||||
CodeLine('abc', [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar')
|
||||
]),
|
||||
CodeLine('abc', [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar')
|
||||
])
|
||||
]));
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
controller.replaceMatch();
|
||||
expect(editingController.codeLines, CodeLines.of(const [
|
||||
CodeLine('bbc'),
|
||||
CodeLine('foo'),
|
||||
CodeLine('bbr'),
|
||||
CodeLine('bbc'),
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar'),
|
||||
CodeLine('abc', [
|
||||
CodeLine('foo'),
|
||||
CodeLine('bar')
|
||||
])
|
||||
]));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
group('CodeEditor ', () {
|
||||
testWidgets('ignores notifications from a previous findController after swap', (tester) async {
|
||||
final CodeLineEditingController editingController = CodeLineEditingController.fromText('abc');
|
||||
final CodeFindController oldFindController = CodeFindController(editingController);
|
||||
final CodeFindController newFindController = CodeFindController(editingController);
|
||||
int buildCount = 0;
|
||||
CodeFindController? lastBuiltController;
|
||||
|
||||
PreferredSizeWidget buildFindWidget(
|
||||
BuildContext context,
|
||||
CodeFindController controller,
|
||||
bool readonly,
|
||||
) {
|
||||
buildCount++;
|
||||
lastBuiltController = controller;
|
||||
return const PreferredSize(
|
||||
preferredSize: Size.zero,
|
||||
child: SizedBox.shrink(),
|
||||
);
|
||||
}
|
||||
|
||||
await tester.pumpWidget(MaterialApp(
|
||||
home: CodeEditor(
|
||||
controller: editingController,
|
||||
findController: oldFindController,
|
||||
findBuilder: buildFindWidget,
|
||||
autofocus: false,
|
||||
),
|
||||
));
|
||||
|
||||
expect(lastBuiltController, same(oldFindController));
|
||||
|
||||
await tester.pumpWidget(MaterialApp(
|
||||
home: CodeEditor(
|
||||
controller: editingController,
|
||||
findController: newFindController,
|
||||
findBuilder: buildFindWidget,
|
||||
autofocus: false,
|
||||
),
|
||||
));
|
||||
|
||||
expect(lastBuiltController, same(newFindController));
|
||||
final int buildCountAfterSwap = buildCount;
|
||||
|
||||
oldFindController.findMode();
|
||||
await tester.pump();
|
||||
|
||||
expect(buildCount, buildCountAfterSwap);
|
||||
expect(lastBuiltController, same(newFindController));
|
||||
|
||||
newFindController.findMode();
|
||||
await tester.pump();
|
||||
|
||||
expect(buildCount, greaterThan(buildCountAfterSwap));
|
||||
expect(lastBuiltController, same(newFindController));
|
||||
|
||||
await tester.pumpWidget(const MaterialApp(home: SizedBox.shrink()));
|
||||
|
||||
oldFindController.dispose();
|
||||
newFindController.dispose();
|
||||
editingController.dispose();
|
||||
});
|
||||
|
||||
testWidgets('ignores stale findController notifications after the editor is removed', (tester) async {
|
||||
final CodeLineEditingController editingController = CodeLineEditingController.fromText('abc');
|
||||
final CodeFindController oldFindController = CodeFindController(editingController);
|
||||
final CodeFindController newFindController = CodeFindController(editingController);
|
||||
|
||||
await tester.pumpWidget(MaterialApp(
|
||||
home: CodeEditor(
|
||||
controller: editingController,
|
||||
findController: oldFindController,
|
||||
autofocus: false,
|
||||
),
|
||||
));
|
||||
|
||||
await tester.pumpWidget(MaterialApp(
|
||||
home: CodeEditor(
|
||||
controller: editingController,
|
||||
findController: newFindController,
|
||||
autofocus: false,
|
||||
),
|
||||
));
|
||||
|
||||
await tester.pumpWidget(const MaterialApp(home: SizedBox.shrink()));
|
||||
|
||||
oldFindController.findMode();
|
||||
await tester.pump();
|
||||
|
||||
expect(tester.takeException(), isNull);
|
||||
|
||||
oldFindController.dispose();
|
||||
newFindController.dispose();
|
||||
editingController.dispose();
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:re_editor/re_editor.dart';
|
||||
|
||||
void main() {
|
||||
group('CodeFindOption getter ', () {
|
||||
test('`regExp`', () async {
|
||||
{
|
||||
const CodeFindOption option = CodeFindOption(
|
||||
pattern: 'a',
|
||||
caseSensitive: false,
|
||||
regex: false
|
||||
);
|
||||
expect(option.regExp, RegExp('a', caseSensitive: false));
|
||||
}
|
||||
{
|
||||
const CodeFindOption option = CodeFindOption(
|
||||
pattern: 'a',
|
||||
caseSensitive: true,
|
||||
regex: false
|
||||
);
|
||||
expect(option.regExp, RegExp('a', caseSensitive: true));
|
||||
}
|
||||
{
|
||||
const CodeFindOption option = CodeFindOption(
|
||||
pattern: 'a',
|
||||
caseSensitive: false,
|
||||
regex: true
|
||||
);
|
||||
expect(option.regExp, RegExp('a', caseSensitive: false));
|
||||
}
|
||||
{
|
||||
const CodeFindOption option = CodeFindOption(
|
||||
pattern: '*',
|
||||
caseSensitive: false,
|
||||
regex: false
|
||||
);
|
||||
expect(option.regExp, RegExp('\\*', caseSensitive: false));
|
||||
}
|
||||
});
|
||||
});
|
||||
group('CodeFindOption method ', () {
|
||||
test('`copyWith`', () async {
|
||||
const CodeFindOption option = CodeFindOption(
|
||||
pattern: '',
|
||||
caseSensitive: false,
|
||||
regex: false
|
||||
);
|
||||
expect(option.copyWith(), option);
|
||||
expect(option.copyWith(
|
||||
pattern: 'a'
|
||||
), const CodeFindOption(
|
||||
pattern: 'a',
|
||||
caseSensitive: false,
|
||||
regex: false
|
||||
));
|
||||
expect(option.copyWith(
|
||||
caseSensitive: true,
|
||||
), const CodeFindOption(
|
||||
pattern: '',
|
||||
caseSensitive: true,
|
||||
regex: false
|
||||
));
|
||||
expect(option.copyWith(
|
||||
regex: true,
|
||||
), const CodeFindOption(
|
||||
pattern: '',
|
||||
caseSensitive: false,
|
||||
regex: true
|
||||
));
|
||||
expect(option.copyWith(
|
||||
pattern: 'abc',
|
||||
caseSensitive: true,
|
||||
regex: true
|
||||
), const CodeFindOption(
|
||||
pattern: 'abc',
|
||||
caseSensitive: true,
|
||||
regex: true
|
||||
));
|
||||
});
|
||||
});
|
||||
group('CodeFindOption operator ', () {
|
||||
test('`==`', () async {
|
||||
expect(const CodeFindOption(
|
||||
pattern: 'a',
|
||||
caseSensitive: true,
|
||||
regex: true
|
||||
) == const CodeFindOption(
|
||||
pattern: 'a',
|
||||
caseSensitive: true,
|
||||
regex: true
|
||||
), true);
|
||||
expect(const CodeFindOption(
|
||||
pattern: 'a',
|
||||
caseSensitive: true,
|
||||
regex: true
|
||||
) == const CodeFindOption(
|
||||
pattern: 'b',
|
||||
caseSensitive: true,
|
||||
regex: true
|
||||
), false);
|
||||
expect(const CodeFindOption(
|
||||
pattern: 'a',
|
||||
caseSensitive: false,
|
||||
regex: true
|
||||
) == const CodeFindOption(
|
||||
pattern: 'a',
|
||||
caseSensitive: true,
|
||||
regex: true
|
||||
), false);
|
||||
expect(const CodeFindOption(
|
||||
pattern: 'a',
|
||||
caseSensitive: true,
|
||||
regex: false
|
||||
) == const CodeFindOption(
|
||||
pattern: 'a',
|
||||
caseSensitive: true,
|
||||
regex: true
|
||||
), false);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,661 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:re_editor/re_editor.dart';
|
||||
|
||||
void main() {
|
||||
group('CodeFindResult getter ', () {
|
||||
test('`previous & next & current`', () async {
|
||||
const CodeFindResult result = CodeFindResult(
|
||||
index: 0,
|
||||
matches: [
|
||||
CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 1,
|
||||
extentIndex: 0,
|
||||
extentOffset: 2
|
||||
),
|
||||
CodeLineSelection(
|
||||
baseIndex: 1,
|
||||
baseOffset: 1,
|
||||
extentIndex: 1,
|
||||
extentOffset: 2
|
||||
),
|
||||
CodeLineSelection(
|
||||
baseIndex: 2,
|
||||
baseOffset: 1,
|
||||
extentIndex: 2,
|
||||
extentOffset: 2
|
||||
)
|
||||
],
|
||||
option: CodeFindOption(
|
||||
pattern: '',
|
||||
caseSensitive: false,
|
||||
regex: false,
|
||||
),
|
||||
codeLines: CodeLines([]),
|
||||
dirty: false
|
||||
);
|
||||
expect(result.currentMatch, const CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 1,
|
||||
extentIndex: 0,
|
||||
extentOffset: 2
|
||||
));
|
||||
expect(result.next, result.copyWith(
|
||||
index: 1
|
||||
));
|
||||
expect(result.next.currentMatch, const CodeLineSelection(
|
||||
baseIndex: 1,
|
||||
baseOffset: 1,
|
||||
extentIndex: 1,
|
||||
extentOffset: 2
|
||||
));
|
||||
expect(result.next.next, result.copyWith(
|
||||
index: 2
|
||||
));
|
||||
expect(result.next.next.currentMatch, const CodeLineSelection(
|
||||
baseIndex: 2,
|
||||
baseOffset: 1,
|
||||
extentIndex: 2,
|
||||
extentOffset: 2
|
||||
));
|
||||
expect(result.next.next.next, result.copyWith(
|
||||
index: 0
|
||||
));
|
||||
expect(result.next.next.next.currentMatch, const CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 1,
|
||||
extentIndex: 0,
|
||||
extentOffset: 2
|
||||
));
|
||||
expect(result.previous, result.copyWith(
|
||||
index: 2
|
||||
));
|
||||
expect(result.previous.currentMatch, const CodeLineSelection(
|
||||
baseIndex: 2,
|
||||
baseOffset: 1,
|
||||
extentIndex: 2,
|
||||
extentOffset: 2
|
||||
));
|
||||
expect(result.previous.previous, result.copyWith(
|
||||
index: 1
|
||||
));
|
||||
expect(result.previous.previous.currentMatch, const CodeLineSelection(
|
||||
baseIndex: 1,
|
||||
baseOffset: 1,
|
||||
extentIndex: 1,
|
||||
extentOffset: 2
|
||||
));
|
||||
expect(result.previous.previous.previous, result.copyWith(
|
||||
index: 0
|
||||
));
|
||||
expect(result.previous.previous.previous.currentMatch, const CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 1,
|
||||
extentIndex: 0,
|
||||
extentOffset: 2
|
||||
));
|
||||
});
|
||||
});
|
||||
|
||||
group('CodeFindResult method ', () {
|
||||
test('`copyWith`', () async {
|
||||
const CodeFindResult result = CodeFindResult(
|
||||
index: 0,
|
||||
matches: [
|
||||
CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 1,
|
||||
extentIndex: 0,
|
||||
extentOffset: 2
|
||||
),
|
||||
CodeLineSelection(
|
||||
baseIndex: 1,
|
||||
baseOffset: 1,
|
||||
extentIndex: 1,
|
||||
extentOffset: 2
|
||||
),
|
||||
CodeLineSelection(
|
||||
baseIndex: 2,
|
||||
baseOffset: 1,
|
||||
extentIndex: 2,
|
||||
extentOffset: 2
|
||||
)
|
||||
],
|
||||
option: CodeFindOption(
|
||||
pattern: '',
|
||||
caseSensitive: false,
|
||||
regex: false,
|
||||
),
|
||||
codeLines: CodeLines([]),
|
||||
dirty: false
|
||||
);
|
||||
expect(result.copyWith(), result);
|
||||
expect(result.copyWith(
|
||||
index: 1
|
||||
), const CodeFindResult(
|
||||
index: 1,
|
||||
matches: [
|
||||
CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 1,
|
||||
extentIndex: 0,
|
||||
extentOffset: 2
|
||||
),
|
||||
CodeLineSelection(
|
||||
baseIndex: 1,
|
||||
baseOffset: 1,
|
||||
extentIndex: 1,
|
||||
extentOffset: 2
|
||||
),
|
||||
CodeLineSelection(
|
||||
baseIndex: 2,
|
||||
baseOffset: 1,
|
||||
extentIndex: 2,
|
||||
extentOffset: 2
|
||||
)
|
||||
],
|
||||
option: CodeFindOption(
|
||||
pattern: '',
|
||||
caseSensitive: false,
|
||||
regex: false,
|
||||
),
|
||||
codeLines: CodeLines([]),
|
||||
dirty: false
|
||||
));
|
||||
expect(result.copyWith(
|
||||
matches: []
|
||||
), const CodeFindResult(
|
||||
index: 0,
|
||||
matches: [],
|
||||
option: CodeFindOption(
|
||||
pattern: '',
|
||||
caseSensitive: false,
|
||||
regex: false,
|
||||
),
|
||||
codeLines: CodeLines([]),
|
||||
dirty: false
|
||||
));
|
||||
expect(result.copyWith(
|
||||
option: const CodeFindOption(
|
||||
pattern: 'a',
|
||||
caseSensitive: true,
|
||||
regex: true,
|
||||
),
|
||||
), const CodeFindResult(
|
||||
index: 0,
|
||||
matches: [
|
||||
CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 1,
|
||||
extentIndex: 0,
|
||||
extentOffset: 2
|
||||
),
|
||||
CodeLineSelection(
|
||||
baseIndex: 1,
|
||||
baseOffset: 1,
|
||||
extentIndex: 1,
|
||||
extentOffset: 2
|
||||
),
|
||||
CodeLineSelection(
|
||||
baseIndex: 2,
|
||||
baseOffset: 1,
|
||||
extentIndex: 2,
|
||||
extentOffset: 2
|
||||
)
|
||||
],
|
||||
option: CodeFindOption(
|
||||
pattern: 'a',
|
||||
caseSensitive: true,
|
||||
regex: true,
|
||||
),
|
||||
codeLines: CodeLines([]),
|
||||
dirty: false
|
||||
));
|
||||
expect(result.copyWith(
|
||||
codeLines: CodeLines.of([
|
||||
const CodeLine('abc')
|
||||
])
|
||||
), CodeFindResult(
|
||||
index: 0,
|
||||
matches: const [
|
||||
CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 1,
|
||||
extentIndex: 0,
|
||||
extentOffset: 2
|
||||
),
|
||||
CodeLineSelection(
|
||||
baseIndex: 1,
|
||||
baseOffset: 1,
|
||||
extentIndex: 1,
|
||||
extentOffset: 2
|
||||
),
|
||||
CodeLineSelection(
|
||||
baseIndex: 2,
|
||||
baseOffset: 1,
|
||||
extentIndex: 2,
|
||||
extentOffset: 2
|
||||
)
|
||||
],
|
||||
option: const CodeFindOption(
|
||||
pattern: '',
|
||||
caseSensitive: false,
|
||||
regex: false,
|
||||
),
|
||||
codeLines: CodeLines.of([
|
||||
const CodeLine('abc')
|
||||
]),
|
||||
dirty: false
|
||||
));
|
||||
expect(result.copyWith(
|
||||
dirty: true
|
||||
), const CodeFindResult(
|
||||
index: 0,
|
||||
matches: [
|
||||
CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 1,
|
||||
extentIndex: 0,
|
||||
extentOffset: 2
|
||||
),
|
||||
CodeLineSelection(
|
||||
baseIndex: 1,
|
||||
baseOffset: 1,
|
||||
extentIndex: 1,
|
||||
extentOffset: 2
|
||||
),
|
||||
CodeLineSelection(
|
||||
baseIndex: 2,
|
||||
baseOffset: 1,
|
||||
extentIndex: 2,
|
||||
extentOffset: 2
|
||||
)
|
||||
],
|
||||
option: CodeFindOption(
|
||||
pattern: '',
|
||||
caseSensitive: false,
|
||||
regex: false,
|
||||
),
|
||||
codeLines: CodeLines([]),
|
||||
dirty: true
|
||||
));
|
||||
});
|
||||
});
|
||||
|
||||
group('CodeFindResult operator ', () {
|
||||
test('`==`', () async {
|
||||
expect(CodeFindResult(
|
||||
index: 0,
|
||||
matches: const [
|
||||
CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 1,
|
||||
extentIndex: 0,
|
||||
extentOffset: 2
|
||||
),
|
||||
CodeLineSelection(
|
||||
baseIndex: 1,
|
||||
baseOffset: 1,
|
||||
extentIndex: 1,
|
||||
extentOffset: 2
|
||||
),
|
||||
CodeLineSelection(
|
||||
baseIndex: 2,
|
||||
baseOffset: 1,
|
||||
extentIndex: 2,
|
||||
extentOffset: 2
|
||||
)
|
||||
],
|
||||
option: const CodeFindOption(
|
||||
pattern: '',
|
||||
caseSensitive: false,
|
||||
regex: false,
|
||||
),
|
||||
codeLines: CodeLines.of([
|
||||
const CodeLine('abc')
|
||||
]),
|
||||
dirty: true
|
||||
) == CodeFindResult(
|
||||
index: 0,
|
||||
matches: const [
|
||||
CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 1,
|
||||
extentIndex: 0,
|
||||
extentOffset: 2
|
||||
),
|
||||
CodeLineSelection(
|
||||
baseIndex: 1,
|
||||
baseOffset: 1,
|
||||
extentIndex: 1,
|
||||
extentOffset: 2
|
||||
),
|
||||
CodeLineSelection(
|
||||
baseIndex: 2,
|
||||
baseOffset: 1,
|
||||
extentIndex: 2,
|
||||
extentOffset: 2
|
||||
)
|
||||
],
|
||||
option: const CodeFindOption(
|
||||
pattern: '',
|
||||
caseSensitive: false,
|
||||
regex: false,
|
||||
),
|
||||
codeLines: CodeLines.of([
|
||||
const CodeLine('abc')
|
||||
]),
|
||||
dirty: true
|
||||
), true);
|
||||
expect(CodeFindResult(
|
||||
index: 1,
|
||||
matches: const [
|
||||
CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 1,
|
||||
extentIndex: 0,
|
||||
extentOffset: 2
|
||||
),
|
||||
CodeLineSelection(
|
||||
baseIndex: 1,
|
||||
baseOffset: 1,
|
||||
extentIndex: 1,
|
||||
extentOffset: 2
|
||||
),
|
||||
CodeLineSelection(
|
||||
baseIndex: 2,
|
||||
baseOffset: 1,
|
||||
extentIndex: 2,
|
||||
extentOffset: 2
|
||||
)
|
||||
],
|
||||
option: const CodeFindOption(
|
||||
pattern: '',
|
||||
caseSensitive: false,
|
||||
regex: false,
|
||||
),
|
||||
codeLines: CodeLines.of([
|
||||
const CodeLine('abc')
|
||||
]),
|
||||
dirty: true
|
||||
) == CodeFindResult(
|
||||
index: 0,
|
||||
matches: const [
|
||||
CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 1,
|
||||
extentIndex: 0,
|
||||
extentOffset: 2
|
||||
),
|
||||
CodeLineSelection(
|
||||
baseIndex: 1,
|
||||
baseOffset: 1,
|
||||
extentIndex: 1,
|
||||
extentOffset: 2
|
||||
),
|
||||
CodeLineSelection(
|
||||
baseIndex: 2,
|
||||
baseOffset: 1,
|
||||
extentIndex: 2,
|
||||
extentOffset: 2
|
||||
)
|
||||
],
|
||||
option: const CodeFindOption(
|
||||
pattern: '',
|
||||
caseSensitive: false,
|
||||
regex: false,
|
||||
),
|
||||
codeLines: CodeLines.of([
|
||||
const CodeLine('abc')
|
||||
]),
|
||||
dirty: true
|
||||
), false);
|
||||
expect(CodeFindResult(
|
||||
index: 0,
|
||||
matches: const [
|
||||
CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 1,
|
||||
extentIndex: 0,
|
||||
extentOffset: 2
|
||||
),
|
||||
CodeLineSelection(
|
||||
baseIndex: 1,
|
||||
baseOffset: 1,
|
||||
extentIndex: 1,
|
||||
extentOffset: 2
|
||||
),
|
||||
],
|
||||
option: const CodeFindOption(
|
||||
pattern: '',
|
||||
caseSensitive: false,
|
||||
regex: false,
|
||||
),
|
||||
codeLines: CodeLines.of([
|
||||
const CodeLine('abc')
|
||||
]),
|
||||
dirty: true
|
||||
) == CodeFindResult(
|
||||
index: 0,
|
||||
matches: const [
|
||||
CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 1,
|
||||
extentIndex: 0,
|
||||
extentOffset: 2
|
||||
),
|
||||
CodeLineSelection(
|
||||
baseIndex: 1,
|
||||
baseOffset: 1,
|
||||
extentIndex: 1,
|
||||
extentOffset: 2
|
||||
),
|
||||
CodeLineSelection(
|
||||
baseIndex: 2,
|
||||
baseOffset: 1,
|
||||
extentIndex: 2,
|
||||
extentOffset: 2
|
||||
)
|
||||
],
|
||||
option: const CodeFindOption(
|
||||
pattern: '',
|
||||
caseSensitive: false,
|
||||
regex: false,
|
||||
),
|
||||
codeLines: CodeLines.of([
|
||||
const CodeLine('abc')
|
||||
]),
|
||||
dirty: true
|
||||
), false);
|
||||
expect(CodeFindResult(
|
||||
index: 0,
|
||||
matches: const [
|
||||
CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 1,
|
||||
extentIndex: 0,
|
||||
extentOffset: 2
|
||||
),
|
||||
CodeLineSelection(
|
||||
baseIndex: 1,
|
||||
baseOffset: 1,
|
||||
extentIndex: 1,
|
||||
extentOffset: 2
|
||||
),
|
||||
CodeLineSelection(
|
||||
baseIndex: 2,
|
||||
baseOffset: 1,
|
||||
extentIndex: 2,
|
||||
extentOffset: 2
|
||||
)
|
||||
],
|
||||
option: const CodeFindOption(
|
||||
pattern: 'a',
|
||||
caseSensitive: false,
|
||||
regex: false,
|
||||
),
|
||||
codeLines: CodeLines.of([
|
||||
const CodeLine('abc')
|
||||
]),
|
||||
dirty: true
|
||||
) == CodeFindResult(
|
||||
index: 0,
|
||||
matches: const [
|
||||
CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 1,
|
||||
extentIndex: 0,
|
||||
extentOffset: 2
|
||||
),
|
||||
CodeLineSelection(
|
||||
baseIndex: 1,
|
||||
baseOffset: 1,
|
||||
extentIndex: 1,
|
||||
extentOffset: 2
|
||||
),
|
||||
CodeLineSelection(
|
||||
baseIndex: 2,
|
||||
baseOffset: 1,
|
||||
extentIndex: 2,
|
||||
extentOffset: 2
|
||||
)
|
||||
],
|
||||
option: const CodeFindOption(
|
||||
pattern: '',
|
||||
caseSensitive: false,
|
||||
regex: false,
|
||||
),
|
||||
codeLines: CodeLines.of([
|
||||
const CodeLine('abc')
|
||||
]),
|
||||
dirty: true
|
||||
), false);
|
||||
expect(CodeFindResult(
|
||||
index: 0,
|
||||
matches: const [
|
||||
CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 1,
|
||||
extentIndex: 0,
|
||||
extentOffset: 2
|
||||
),
|
||||
CodeLineSelection(
|
||||
baseIndex: 1,
|
||||
baseOffset: 1,
|
||||
extentIndex: 1,
|
||||
extentOffset: 2
|
||||
),
|
||||
CodeLineSelection(
|
||||
baseIndex: 2,
|
||||
baseOffset: 1,
|
||||
extentIndex: 2,
|
||||
extentOffset: 2
|
||||
)
|
||||
],
|
||||
option: const CodeFindOption(
|
||||
pattern: '',
|
||||
caseSensitive: false,
|
||||
regex: false,
|
||||
),
|
||||
codeLines: CodeLines.of([
|
||||
const CodeLine('a')
|
||||
]),
|
||||
dirty: true
|
||||
) == CodeFindResult(
|
||||
index: 0,
|
||||
matches: const [
|
||||
CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 1,
|
||||
extentIndex: 0,
|
||||
extentOffset: 2
|
||||
),
|
||||
CodeLineSelection(
|
||||
baseIndex: 1,
|
||||
baseOffset: 1,
|
||||
extentIndex: 1,
|
||||
extentOffset: 2
|
||||
),
|
||||
CodeLineSelection(
|
||||
baseIndex: 2,
|
||||
baseOffset: 1,
|
||||
extentIndex: 2,
|
||||
extentOffset: 2
|
||||
)
|
||||
],
|
||||
option: const CodeFindOption(
|
||||
pattern: '',
|
||||
caseSensitive: false,
|
||||
regex: false,
|
||||
),
|
||||
codeLines: CodeLines.of([
|
||||
const CodeLine('abc')
|
||||
]),
|
||||
dirty: true
|
||||
), false);
|
||||
expect(CodeFindResult(
|
||||
index: 0,
|
||||
matches: const [
|
||||
CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 1,
|
||||
extentIndex: 0,
|
||||
extentOffset: 2
|
||||
),
|
||||
CodeLineSelection(
|
||||
baseIndex: 1,
|
||||
baseOffset: 1,
|
||||
extentIndex: 1,
|
||||
extentOffset: 2
|
||||
),
|
||||
CodeLineSelection(
|
||||
baseIndex: 2,
|
||||
baseOffset: 1,
|
||||
extentIndex: 2,
|
||||
extentOffset: 2
|
||||
)
|
||||
],
|
||||
option: const CodeFindOption(
|
||||
pattern: '',
|
||||
caseSensitive: false,
|
||||
regex: false,
|
||||
),
|
||||
codeLines: CodeLines.of([
|
||||
const CodeLine('abc')
|
||||
]),
|
||||
dirty: true
|
||||
) == CodeFindResult(
|
||||
index: 0,
|
||||
matches: const [
|
||||
CodeLineSelection(
|
||||
baseIndex: 0,
|
||||
baseOffset: 1,
|
||||
extentIndex: 0,
|
||||
extentOffset: 2
|
||||
),
|
||||
CodeLineSelection(
|
||||
baseIndex: 1,
|
||||
baseOffset: 1,
|
||||
extentIndex: 1,
|
||||
extentOffset: 2
|
||||
),
|
||||
CodeLineSelection(
|
||||
baseIndex: 2,
|
||||
baseOffset: 1,
|
||||
extentIndex: 2,
|
||||
extentOffset: 2
|
||||
)
|
||||
],
|
||||
option: const CodeFindOption(
|
||||
pattern: '',
|
||||
caseSensitive: false,
|
||||
regex: false,
|
||||
),
|
||||
codeLines: CodeLines.of([
|
||||
const CodeLine('abc')
|
||||
]),
|
||||
dirty: false
|
||||
), false);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,221 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:re_editor/re_editor.dart';
|
||||
|
||||
void main() {
|
||||
group('CodeFindValue constructor ', () {
|
||||
test('`empty`', () async {
|
||||
const CodeFindValue value = CodeFindValue.empty();
|
||||
expect(value.option, const CodeFindOption(
|
||||
pattern: '',
|
||||
caseSensitive: false,
|
||||
regex: false,
|
||||
));
|
||||
expect(value.replaceMode, false);
|
||||
expect(value.result, null);
|
||||
});
|
||||
});
|
||||
group('CodeFindValue method ', () {
|
||||
test('`copyWith`', () async {
|
||||
const CodeFindValue value = CodeFindValue.empty();
|
||||
{
|
||||
final CodeFindValue newValue = value.copyWith(
|
||||
result: CodeFindResult(
|
||||
index: 0,
|
||||
matches: [],
|
||||
option: value.option,
|
||||
codeLines: const CodeLines([]),
|
||||
dirty: false
|
||||
)
|
||||
);
|
||||
expect(newValue.result, CodeFindResult(
|
||||
index: 0,
|
||||
matches: [],
|
||||
option: value.option,
|
||||
codeLines: const CodeLines([]),
|
||||
dirty: false
|
||||
));
|
||||
expect(newValue.replaceMode, value.replaceMode);
|
||||
expect(newValue.option, value.option);
|
||||
}
|
||||
{
|
||||
final CodeFindValue newValue = value.copyWith(
|
||||
replaceMode: true,
|
||||
result: null
|
||||
);
|
||||
expect(newValue.result, null);
|
||||
expect(newValue.replaceMode, true);
|
||||
expect(newValue.option, value.option);
|
||||
}
|
||||
{
|
||||
final CodeFindValue newValue = value.copyWith(
|
||||
option: const CodeFindOption(
|
||||
pattern: 'a',
|
||||
caseSensitive: true,
|
||||
regex: true
|
||||
),
|
||||
result: null
|
||||
);
|
||||
expect(newValue.result, null);
|
||||
expect(newValue.replaceMode, value.replaceMode);
|
||||
expect(newValue.option, const CodeFindOption(
|
||||
pattern: 'a',
|
||||
caseSensitive: true,
|
||||
regex: true
|
||||
));
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
group('CodeFindValue operator ', () {
|
||||
test('`==`', () async {
|
||||
expect(const CodeFindValue(
|
||||
option: CodeFindOption(
|
||||
pattern: '',
|
||||
caseSensitive: false,
|
||||
regex: false,
|
||||
),
|
||||
replaceMode: false,
|
||||
result: CodeFindResult(
|
||||
index: 0,
|
||||
matches: [],
|
||||
option: CodeFindOption(
|
||||
pattern: '',
|
||||
caseSensitive: false,
|
||||
regex: false,
|
||||
),
|
||||
codeLines: CodeLines([]),
|
||||
dirty: false
|
||||
)
|
||||
) == const CodeFindValue(
|
||||
option: CodeFindOption(
|
||||
pattern: '',
|
||||
caseSensitive: false,
|
||||
regex: false,
|
||||
),
|
||||
replaceMode: false,
|
||||
result: CodeFindResult(
|
||||
index: 0,
|
||||
matches: [],
|
||||
option: CodeFindOption(
|
||||
pattern: '',
|
||||
caseSensitive: false,
|
||||
regex: false,
|
||||
),
|
||||
codeLines: CodeLines([]),
|
||||
dirty: false
|
||||
)
|
||||
), true);
|
||||
expect(const CodeFindValue(
|
||||
option: CodeFindOption(
|
||||
pattern: '',
|
||||
caseSensitive: false,
|
||||
regex: false,
|
||||
),
|
||||
replaceMode: false,
|
||||
result: CodeFindResult(
|
||||
index: 0,
|
||||
matches: [],
|
||||
option: CodeFindOption(
|
||||
pattern: '',
|
||||
caseSensitive: false,
|
||||
regex: false,
|
||||
),
|
||||
codeLines: CodeLines([]),
|
||||
dirty: false
|
||||
)
|
||||
) == const CodeFindValue(
|
||||
option: CodeFindOption(
|
||||
pattern: 'a',
|
||||
caseSensitive: false,
|
||||
regex: false,
|
||||
),
|
||||
replaceMode: false,
|
||||
result: CodeFindResult(
|
||||
index: 0,
|
||||
matches: [],
|
||||
option: CodeFindOption(
|
||||
pattern: '',
|
||||
caseSensitive: false,
|
||||
regex: false,
|
||||
),
|
||||
codeLines: CodeLines([]),
|
||||
dirty: false
|
||||
)
|
||||
), false);
|
||||
expect(const CodeFindValue(
|
||||
option: CodeFindOption(
|
||||
pattern: '',
|
||||
caseSensitive: false,
|
||||
regex: false,
|
||||
),
|
||||
replaceMode: false,
|
||||
result: CodeFindResult(
|
||||
index: 0,
|
||||
matches: [],
|
||||
option: CodeFindOption(
|
||||
pattern: '',
|
||||
caseSensitive: false,
|
||||
regex: false,
|
||||
),
|
||||
codeLines: CodeLines([]),
|
||||
dirty: false
|
||||
)
|
||||
) == const CodeFindValue(
|
||||
option: CodeFindOption(
|
||||
pattern: '',
|
||||
caseSensitive: false,
|
||||
regex: false,
|
||||
),
|
||||
replaceMode: true,
|
||||
result: CodeFindResult(
|
||||
index: 0,
|
||||
matches: [],
|
||||
option: CodeFindOption(
|
||||
pattern: '',
|
||||
caseSensitive: false,
|
||||
regex: false,
|
||||
),
|
||||
codeLines: CodeLines([]),
|
||||
dirty: false
|
||||
)
|
||||
), false);
|
||||
expect(const CodeFindValue(
|
||||
option: CodeFindOption(
|
||||
pattern: '',
|
||||
caseSensitive: false,
|
||||
regex: false,
|
||||
),
|
||||
replaceMode: false,
|
||||
result: CodeFindResult(
|
||||
index: 0,
|
||||
matches: [],
|
||||
option: CodeFindOption(
|
||||
pattern: '',
|
||||
caseSensitive: false,
|
||||
regex: false,
|
||||
),
|
||||
codeLines: CodeLines([]),
|
||||
dirty: false
|
||||
)
|
||||
) == const CodeFindValue(
|
||||
option: CodeFindOption(
|
||||
pattern: '',
|
||||
caseSensitive: false,
|
||||
regex: false,
|
||||
),
|
||||
replaceMode: false,
|
||||
result: CodeFindResult(
|
||||
index: 1,
|
||||
matches: [],
|
||||
option: CodeFindOption(
|
||||
pattern: '',
|
||||
caseSensitive: false,
|
||||
regex: false,
|
||||
),
|
||||
codeLines: CodeLines([]),
|
||||
dirty: false
|
||||
)
|
||||
), false);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{"abc": {"foo": ["bar"]},"123": [{"foo": "bar","bar": "foo"},{"foo": "bar","bar": "foo"}],"foo": "bar"}
|
||||
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"abc": {
|
||||
"foo": [
|
||||
"bar"
|
||||
]
|
||||
},
|
||||
"123": [
|
||||
{
|
||||
"foo": "bar",
|
||||
"bar": "foo"
|
||||
},
|
||||
{
|
||||
"foo": "bar",
|
||||
"bar": "foo"
|
||||
}
|
||||
],
|
||||
"foo": "bar"
|
||||
}
|
||||
Reference in new issue
Block a user