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

Commit 0ec6f6c

Browse files
authored
[web][1/3] Start first batch of auto-generated (already passing) tests for line break (#19586)
1 parent cfa3d90 commit 0ec6f6c

File tree

2 files changed

+4923
-0
lines changed

2 files changed

+4923
-0
lines changed

lib/web_ui/test/text/line_breaker_test.dart

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import 'package:test/test.dart';
88
import 'package:ui/src/engine.dart';
99
import 'package:ui/ui.dart';
1010

11+
import 'line_breaker_test_data.dart';
12+
1113
void main() {
1214
group('nextLineBreak', () {
1315
test('Does not go beyond the ends of a string', () {
@@ -159,6 +161,42 @@ void main() {
159161
Line('foo', LineBreakType.endOfText),
160162
]);
161163
});
164+
165+
test('comprehensive test', () {
166+
for (int t = 0; t < data.length; t++) {
167+
final TestCase testCase = data[t];
168+
final String text = testCase.toText();
169+
170+
int lastLineBreak = 0;
171+
for (int i = 0; i < testCase.signs.length; i++) {
172+
final Sign sign = testCase.signs[i];
173+
final LineBreakResult result = nextLineBreak(text, lastLineBreak);
174+
if (sign.isBreakOpportunity) {
175+
// The line break should've been found at index `i`.
176+
expect(
177+
result.index,
178+
i,
179+
reason: 'Failed at test case number $t:\n'
180+
'${testCase.toString()}\n'
181+
'"$text"\n'
182+
'\nExpected line break at {$lastLineBreak - $i} but found line break at {$lastLineBreak - ${result.index}}.',
183+
);
184+
lastLineBreak = i;
185+
} else {
186+
// This isn't a line break opportunity so the line break should be
187+
// somewhere after index `i`.
188+
expect(
189+
result.index,
190+
greaterThan(i),
191+
reason: 'Failed at test case number $t:\n'
192+
'${testCase.toString()}\n'
193+
'"$text"\n'
194+
'\nUnexpected line break found at {$lastLineBreak - $i}.',
195+
);
196+
}
197+
}
198+
}
199+
});
162200
});
163201
}
164202

0 commit comments

Comments
 (0)