@@ -24,4 +24,59 @@ void main() {
2424 expect (FontWeight .lerp (FontWeight .w400, null , 1 ), equals (FontWeight .w400));
2525 });
2626 });
27+ group ('TextRange' , () {
28+ test ('empty ranges are correct' , () {
29+ const TextRange range = TextRange (start: - 1 , end: - 1 );
30+ expect (range, equals (const TextRange .collapsed (- 1 )));
31+ expect (range, equals (TextRange .empty));
32+ });
33+ test ('isValid works' , () {
34+ expect (TextRange .empty.isValid, isFalse);
35+ expect (const TextRange (start: 0 , end: 0 ).isValid, isTrue);
36+ expect (const TextRange (start: 0 , end: 10 ).isValid, isTrue);
37+ expect (const TextRange (start: 10 , end: 10 ).isValid, isTrue);
38+ expect (const TextRange (start: - 1 , end: 10 ).isValid, isFalse);
39+ expect (const TextRange (start: 10 , end: 0 ).isValid, isTrue);
40+ expect (const TextRange (start: 10 , end: - 1 ).isValid, isFalse);
41+ });
42+ test ('isCollapsed works' , () {
43+ expect (TextRange .empty.isCollapsed, isTrue);
44+ expect (const TextRange (start: 0 , end: 0 ).isCollapsed, isTrue);
45+ expect (const TextRange (start: 0 , end: 10 ).isCollapsed, isFalse);
46+ expect (const TextRange (start: 10 , end: 10 ).isCollapsed, isTrue);
47+ expect (const TextRange (start: - 1 , end: 10 ).isCollapsed, isFalse);
48+ expect (const TextRange (start: 10 , end: 0 ).isCollapsed, isFalse);
49+ expect (const TextRange (start: 10 , end: - 1 ).isCollapsed, isFalse);
50+ });
51+ test ('isNormalized works' , () {
52+ expect (TextRange .empty.isNormalized, isTrue);
53+ expect (const TextRange (start: 0 , end: 0 ).isNormalized, isTrue);
54+ expect (const TextRange (start: 0 , end: 10 ).isNormalized, isTrue);
55+ expect (const TextRange (start: 10 , end: 10 ).isNormalized, isTrue);
56+ expect (const TextRange (start: - 1 , end: 10 ).isNormalized, isTrue);
57+ expect (const TextRange (start: 10 , end: 0 ).isNormalized, isFalse);
58+ expect (const TextRange (start: 10 , end: - 1 ).isNormalized, isFalse);
59+ });
60+ test ('textBefore works' , () {
61+ expect (const TextRange (start: 0 , end: 0 ).textBefore ('hello' ), isEmpty);
62+ expect (const TextRange (start: 1 , end: 1 ).textBefore ('hello' ), equals ('h' ));
63+ expect (const TextRange (start: 1 , end: 2 ).textBefore ('hello' ), equals ('h' ));
64+ expect (const TextRange (start: 5 , end: 5 ).textBefore ('hello' ), equals ('hello' ));
65+ expect (const TextRange (start: 0 , end: 5 ).textBefore ('hello' ), isEmpty);
66+ });
67+ test ('textAfter works' , () {
68+ expect (const TextRange (start: 0 , end: 0 ).textAfter ('hello' ), equals ('hello' ));
69+ expect (const TextRange (start: 1 , end: 1 ).textAfter ('hello' ), equals ('ello' ));
70+ expect (const TextRange (start: 1 , end: 2 ).textAfter ('hello' ), equals ('llo' ));
71+ expect (const TextRange (start: 5 , end: 5 ).textAfter ('hello' ), isEmpty);
72+ expect (const TextRange (start: 0 , end: 5 ).textAfter ('hello' ), isEmpty);
73+ });
74+ test ('textInside works' , () {
75+ expect (const TextRange (start: 0 , end: 0 ).textInside ('hello' ), isEmpty);
76+ expect (const TextRange (start: 1 , end: 1 ).textInside ('hello' ), isEmpty);
77+ expect (const TextRange (start: 1 , end: 2 ).textInside ('hello' ), equals ('e' ));
78+ expect (const TextRange (start: 5 , end: 5 ).textInside ('hello' ), isEmpty);
79+ expect (const TextRange (start: 0 , end: 5 ).textInside ('hello' ), equals ('hello' ));
80+ });
81+ });
2782}
0 commit comments