Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 100215f

Browse files
committed
Add tests
1 parent 73b06b7 commit 100215f

File tree

2 files changed

+110
-0
lines changed

2 files changed

+110
-0
lines changed

lib/web_ui/test/text_test.dart

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,4 +262,59 @@ void main() async {
262262

263263
debugEmulateFlutterTesterEnvironment = true;
264264
});
265+
group('TextRange', () {
266+
test('empty ranges are correct', () {
267+
const TextRange range = TextRange(start: -1, end: -1);
268+
expect(range, equals(const TextRange.collapsed(-1)));
269+
expect(range, equals(TextRange.empty));
270+
});
271+
test('isValid works', () {
272+
expect(TextRange.empty.isValid, isFalse);
273+
expect(const TextRange(start: 0, end: 0).isValid, isTrue);
274+
expect(const TextRange(start: 0, end: 10).isValid, isTrue);
275+
expect(const TextRange(start: 10, end: 10).isValid, isTrue);
276+
expect(const TextRange(start: -1, end: 10).isValid, isFalse);
277+
expect(const TextRange(start: 10, end: 0).isValid, isTrue);
278+
expect(const TextRange(start: 10, end: -1).isValid, isFalse);
279+
});
280+
test('isCollapsed works', () {
281+
expect(TextRange.empty.isCollapsed, isTrue);
282+
expect(const TextRange(start: 0, end: 0).isCollapsed, isTrue);
283+
expect(const TextRange(start: 0, end: 10).isCollapsed, isFalse);
284+
expect(const TextRange(start: 10, end: 10).isCollapsed, isTrue);
285+
expect(const TextRange(start: -1, end: 10).isCollapsed, isFalse);
286+
expect(const TextRange(start: 10, end: 0).isCollapsed, isFalse);
287+
expect(const TextRange(start: 10, end: -1).isCollapsed, isFalse);
288+
});
289+
test('isNormalized works', () {
290+
expect(TextRange.empty.isNormalized, isTrue);
291+
expect(const TextRange(start: 0, end: 0).isNormalized, isTrue);
292+
expect(const TextRange(start: 0, end: 10).isNormalized, isTrue);
293+
expect(const TextRange(start: 10, end: 10).isNormalized, isTrue);
294+
expect(const TextRange(start: -1, end: 10).isNormalized, isTrue);
295+
expect(const TextRange(start: 10, end: 0).isNormalized, isFalse);
296+
expect(const TextRange(start: 10, end: -1).isNormalized, isFalse);
297+
});
298+
test('textBefore works', () {
299+
expect(const TextRange(start: 0, end: 0).textBefore('hello'), isEmpty);
300+
expect(const TextRange(start: 1, end: 1).textBefore('hello'), equals('h'));
301+
expect(const TextRange(start: 1, end: 2).textBefore('hello'), equals('h'));
302+
expect(const TextRange(start: 5, end: 5).textBefore('hello'), equals('hello'));
303+
expect(const TextRange(start: 0, end: 5).textBefore('hello'), isEmpty);
304+
});
305+
test('textAfter works', () {
306+
expect(const TextRange(start: 0, end: 0).textAfter('hello'), equals('hello'));
307+
expect(const TextRange(start: 1, end: 1).textAfter('hello'), equals('ello'));
308+
expect(const TextRange(start: 1, end: 2).textAfter('hello'), equals('llo'));
309+
expect(const TextRange(start: 5, end: 5).textAfter('hello'), isEmpty);
310+
expect(const TextRange(start: 0, end: 5).textAfter('hello'), isEmpty);
311+
});
312+
test('textInside works', () {
313+
expect(const TextRange(start: 0, end: 0).textInside('hello'), isEmpty);
314+
expect(const TextRange(start: 1, end: 1).textInside('hello'), isEmpty);
315+
expect(const TextRange(start: 1, end: 2).textInside('hello'), equals('e'));
316+
expect(const TextRange(start: 5, end: 5).textInside('hello'), isEmpty);
317+
expect(const TextRange(start: 0, end: 5).textInside('hello'), equals('hello'));
318+
});
319+
});
265320
}

testing/dart/text_test.dart

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)