-
Notifications
You must be signed in to change notification settings - Fork 95
Expand file tree
/
Copy pathcode_controller_set_value_test.dart
More file actions
103 lines (88 loc) · 2.96 KB
/
code_controller_set_value_test.dart
File metadata and controls
103 lines (88 loc) · 2.96 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import '../common/create_app.dart';
void main() {
test('Composing-only updates are applied', () {
final controller = createController('');
controller.value = const TextEditingValue(
text: 'ni',
selection: TextSelection.collapsed(offset: 2),
composing: TextRange(start: 0, end: 1),
);
controller.value = const TextEditingValue(
text: 'ni',
selection: TextSelection.collapsed(offset: 2),
composing: TextRange(start: 0, end: 2),
);
expect(controller.value.composing, const TextRange(start: 0, end: 2));
controller.dispose();
});
test('Composing text is committed correctly after IME selection', () {
final controller = createController('}');
controller.selection = const TextSelection.collapsed(offset: 1);
controller.value = const TextEditingValue(
text: '} ni',
selection: TextSelection.collapsed(offset: 4),
composing: TextRange(start: 2, end: 4),
);
controller.value = const TextEditingValue(
text: '} 你',
selection: TextSelection.collapsed(offset: 3),
composing: TextRange.empty,
);
expect(controller.text, '} 你');
expect(controller.fullText, '} 你');
controller.dispose();
});
testWidgets(
'Backspace or delete at a folded block collapse point '
'=> Do nothing.', (wt) async {
final examples = [
//
const _Example(
'Backspace after newline after folded block',
initialFullText: 'int main(){\n}\n',
// \
initialSelection: TextSelection.collapsed(offset: 12),
foldedBlocks: [0],
finalVisibleText: 'int main(){\n',
key: LogicalKeyboardKey.backspace,
),
const _Example(
'Delete at the collapsed position of a folded block',
initialFullText: 'int main(){\n}\n',
// \
initialSelection: TextSelection.collapsed(offset: 11),
foldedBlocks: [0],
finalVisibleText: 'int main(){\n',
key: LogicalKeyboardKey.delete,
),
];
for (final example in examples) {
final controller = await pumpController(wt, example.initialFullText);
// ignore: prefer_foreach
for (final foldingLineIndex in example.foldedBlocks) {
controller.foldAt(foldingLineIndex);
}
controller.selection = example.initialSelection;
await wt.sendKeyEvent(example.key);
expect(controller.value.text, example.finalVisibleText);
}
});
}
class _Example {
final String name;
final String initialFullText;
final TextSelection initialSelection;
final List<int> foldedBlocks;
final String finalVisibleText;
final LogicalKeyboardKey key;
const _Example(
this.name, {
required this.initialFullText,
required this.foldedBlocks,
required this.finalVisibleText,
required this.key,
required this.initialSelection,
});
}