@@ -4,72 +4,70 @@ import 'package:flutter_code_editor/src/code_modifiers/insertion.dart';
44import 'package:flutter_test/flutter_test.dart' ;
55
66void main () {
7- test ( 'inserts at the start of string correctly ' , () {
7+ group ( 'InsertionCodeModifier ' , () {
88 const modifier = InsertionCodeModifier (openChar: '1' , closeString: '23' );
9- const text = 'Hello World' ;
10- final selection = TextSelection .fromPosition (const TextPosition (offset: 0 ));
119 const editorParams = EditorParams ();
1210
13- final result = modifier.updateString (text, selection, editorParams);
11+ test ('inserts at the start of string correctly' , () {
12+ const text = 'Hello World' ;
13+ final selection =
14+ TextSelection .fromPosition (const TextPosition (offset: 0 ));
1415
15- expect (result! .text, '123Hello World' );
16- expect (result.selection.baseOffset, 1 );
17- expect (result.selection.extentOffset, 1 );
18- });
16+ final result = modifier.updateString (text, selection, editorParams);
1917
20- test ('inserts in the middle of string correctly' , () {
21- const modifier = InsertionCodeModifier (openChar: '1' , closeString: '23' );
22- const text = 'Hello World' ;
23- final selection = TextSelection .fromPosition (const TextPosition (offset: 5 ));
24- const editorParams = EditorParams ();
18+ expect (result! .text, '123Hello World' );
19+ expect (result.selection.baseOffset, 1 );
20+ expect (result.selection.extentOffset, 1 );
21+ });
2522
26- final result = modifier.updateString (text, selection, editorParams);
23+ test ('inserts in the middle of string correctly' , () {
24+ const text = 'Hello World' ;
25+ final selection =
26+ TextSelection .fromPosition (const TextPosition (offset: 5 ));
2727
28- expect (result! .text, 'Hello123 World' );
29- expect (result.selection.baseOffset, 6 );
30- expect (result.selection.extentOffset, 6 );
31- });
28+ final result = modifier.updateString (text, selection, editorParams);
3229
33- test ('inserts at the end of string correctly' , () {
34- const modifier = InsertionCodeModifier (openChar: '1' , closeString: '23' );
35- const text = 'Hello World' ;
36- final selection =
37- TextSelection .fromPosition (const TextPosition (offset: text.length));
38- const editorParams = EditorParams ();
30+ expect (result! .text, 'Hello123 World' );
31+ expect (result.selection.baseOffset, 6 );
32+ expect (result.selection.extentOffset, 6 );
33+ });
3934
40- final result = modifier.updateString (text, selection, editorParams);
35+ test ('inserts at the end of string correctly' , () {
36+ const text = 'Hello World' ;
37+ final selection =
38+ TextSelection .fromPosition (const TextPosition (offset: text.length));
4139
42- expect (result! .text, 'Hello World123' );
43- expect (result.selection.baseOffset, text.length + 1 );
44- expect (result.selection.extentOffset, text.length + 1 );
45- });
40+ final result = modifier.updateString (text, selection, editorParams);
4641
47- test ('inserts in the middle of string with selection correctly' , () {
48- const modifier = InsertionCodeModifier (openChar: '1' , closeString: '23' );
49- const text = 'Hello World' ;
50- const selection = TextSelection (
51- baseOffset: 5 ,
52- extentOffset: 7 ,
53- );
54- const editorParams = EditorParams ();
42+ expect (result! .text, 'Hello World123' );
43+ expect (result.selection.baseOffset, text.length + 1 );
44+ expect (result.selection.extentOffset, text.length + 1 );
45+ });
5546
56- final result = modifier.updateString (text, selection, editorParams);
47+ test ('inserts in the middle of string with selection correctly' , () {
48+ const text = 'Hello World' ;
49+ const selection = TextSelection (
50+ baseOffset: 5 ,
51+ extentOffset: 7 ,
52+ );
5753
58- expect (result! .text, 'Hello123orld' );
59- expect (result.selection.baseOffset, 6 );
60- expect (result.selection.extentOffset, 6 );
61- });
54+ final result = modifier.updateString (text, selection, editorParams);
6255
63- test ('inserts at empty string correctly' , () {
64- const modifier = InsertionCodeModifier (openChar: '1' , closeString: '23' );
65- const text = '' ;
66- final selection = TextSelection .fromPosition (const TextPosition (offset: 0 ));
67- const editorParams = EditorParams ();
56+ expect (result! .text, 'Hello123orld' );
57+ expect (result.selection.baseOffset, 6 );
58+ expect (result.selection.extentOffset, 6 );
59+ });
60+
61+ test ('inserts at empty string correctly' , () {
62+ const text = '' ;
63+ final selection =
64+ TextSelection .fromPosition (const TextPosition (offset: 0 ));
6865
69- final result = modifier.updateString (text, selection, editorParams);
66+ final result = modifier.updateString (text, selection, editorParams);
7067
71- expect (result! .text, '123' );
72- expect (result.selection.baseOffset, 1 );
73- expect (result.selection.extentOffset, 1 );
68+ expect (result! .text, '123' );
69+ expect (result.selection.baseOffset, 1 );
70+ expect (result.selection.extentOffset, 1 );
71+ });
7472 });
7573}
0 commit comments