-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathinsertion_test.dart
75 lines (60 loc) · 2.74 KB
/
insertion_test.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import 'package:flutter/services.dart';
import 'package:flutter_code_editor/src/code_field/editor_params.dart';
import 'package:flutter_code_editor/src/code_modifiers/insertion.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
test('inserts at the start of string correctly', () {
const modifier = InsertionCodeModifier(openChar: '1', closeString: '23');
const text = 'Hello World';
final selection = TextSelection.fromPosition(const TextPosition(offset: 0));
const editorParams = EditorParams();
final result = modifier.updateString(text, selection, editorParams);
expect(result!.text, '123Hello World');
expect(result.selection.baseOffset, 1);
expect(result.selection.extentOffset, 1);
});
test('inserts in the middle of string correctly', () {
const modifier = InsertionCodeModifier(openChar: '1', closeString: '23');
const text = 'Hello World';
final selection = TextSelection.fromPosition(const TextPosition(offset: 5));
const editorParams = EditorParams();
final result = modifier.updateString(text, selection, editorParams);
expect(result!.text, 'Hello123 World');
expect(result.selection.baseOffset, 6);
expect(result.selection.extentOffset, 6);
});
test('inserts at the end of string correctly', () {
const modifier = InsertionCodeModifier(openChar: '1', closeString: '23');
const text = 'Hello World';
final selection =
TextSelection.fromPosition(const TextPosition(offset: text.length));
const editorParams = EditorParams();
final result = modifier.updateString(text, selection, editorParams);
expect(result!.text, 'Hello World123');
expect(result.selection.baseOffset, text.length + 1);
expect(result.selection.extentOffset, text.length + 1);
});
test('inserts in the middle of string with selection correctly', () {
const modifier = InsertionCodeModifier(openChar: '1', closeString: '23');
const text = 'Hello World';
const selection = TextSelection(
baseOffset: 5,
extentOffset: 7,
);
const editorParams = EditorParams();
final result = modifier.updateString(text, selection, editorParams);
expect(result!.text, 'Hello123orld');
expect(result.selection.baseOffset, 6);
expect(result.selection.extentOffset, 6);
});
test('inserts at empty string correctly', () {
const modifier = InsertionCodeModifier(openChar: '1', closeString: '23');
const text = '';
final selection = TextSelection.fromPosition(const TextPosition(offset: 0));
const editorParams = EditorParams();
final result = modifier.updateString(text, selection, editorParams);
expect(result!.text, '123');
expect(result.selection.baseOffset, 1);
expect(result.selection.extentOffset, 1);
});
}