@@ -4,72 +4,73 @@ 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+
8+ group ('InsertionCodeModifier' , () {
9+
810 const modifier = InsertionCodeModifier (openChar: '1' , closeString: '23' );
9- const text = 'Hello World' ;
10- final selection = TextSelection .fromPosition (const TextPosition (offset: 0 ));
1111 const editorParams = EditorParams ();
1212
13- final result = modifier.updateString (text, selection, editorParams);
13+ test ('inserts at the start of string correctly' , () {
14+ const text = 'Hello World' ;
15+ final selection = TextSelection
16+ .fromPosition (const TextPosition (offset: 0 ));
1417
15- expect (result! .text, '123Hello World' );
16- expect (result.selection.baseOffset, 1 );
17- expect (result.selection.extentOffset, 1 );
18- });
18+ final result =
19+ modifier.updateString (text, selection, editorParams);
1920
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 ();
21+ expect (result! .text, '123Hello World' );
22+ expect (result.selection.baseOffset, 1 );
23+ expect (result.selection.extentOffset, 1 );
24+ });
2525
26- final result = modifier.updateString (text, selection, editorParams);
26+ test ('inserts in the middle of string correctly' , () {
27+ const text = 'Hello World' ;
28+ final selection = TextSelection
29+ .fromPosition (const TextPosition (offset: 5 ));
2730
28- expect (result! .text, 'Hello123 World' );
29- expect (result.selection.baseOffset, 6 );
30- expect (result.selection.extentOffset, 6 );
31- });
31+ final result = modifier.updateString (text, selection, editorParams);
3232
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 ();
33+ expect (result! .text, 'Hello123 World' );
34+ expect (result.selection.baseOffset, 6 );
35+ expect (result.selection.extentOffset, 6 );
36+ });
3937
40- final result = modifier.updateString (text, selection, editorParams);
38+ test ('inserts at the end of string correctly' , () {
39+ const text = 'Hello World' ;
40+ final selection =
41+ TextSelection .fromPosition (const TextPosition (offset: text.length));
4142
42- expect (result! .text, 'Hello World123' );
43- expect (result.selection.baseOffset, text.length + 1 );
44- expect (result.selection.extentOffset, text.length + 1 );
45- });
43+ final result = modifier.updateString (text, selection, editorParams);
4644
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 ();
45+ expect (result! .text, 'Hello World123' );
46+ expect (result.selection.baseOffset, text.length + 1 );
47+ expect (result.selection.extentOffset, text.length + 1 );
48+ });
5549
56- final result = modifier.updateString (text, selection, editorParams);
50+ test ('inserts in the middle of string with selection correctly' , () {
51+ const text = 'Hello World' ;
52+ const selection = TextSelection (
53+ baseOffset: 5 ,
54+ extentOffset: 7 ,
55+ );
5756
58- expect (result! .text, 'Hello123orld' );
59- expect (result.selection.baseOffset, 6 );
60- expect (result.selection.extentOffset, 6 );
61- });
57+ final result = modifier.updateString (text, selection, editorParams);
6258
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 ();
59+ expect (result! .text, 'Hello123orld' );
60+ expect (result.selection.baseOffset, 6 );
61+ expect (result.selection.extentOffset, 6 );
62+ });
63+
64+ test ('inserts at empty string correctly' , () {
65+ const text = '' ;
66+ final selection = TextSelection
67+ .fromPosition (const TextPosition (offset: 0 ));
6868
69- final result = modifier.updateString (text, selection, editorParams);
69+ final result = modifier.updateString (text, selection, editorParams);
7070
71- expect (result! .text, '123' );
72- expect (result.selection.baseOffset, 1 );
73- expect (result.selection.extentOffset, 1 );
71+ expect (result! .text, '123' );
72+ expect (result.selection.baseOffset, 1 );
73+ expect (result.selection.extentOffset, 1 );
74+ });
7475 });
7576}
0 commit comments