@@ -8,6 +8,8 @@ import 'package:test/test.dart';
8
8
import 'package:ui/src/engine.dart' ;
9
9
import 'package:ui/ui.dart' ;
10
10
11
+ import 'line_breaker_test_data.dart' ;
12
+
11
13
void main () {
12
14
group ('nextLineBreak' , () {
13
15
test ('Does not go beyond the ends of a string' , () {
@@ -159,6 +161,42 @@ void main() {
159
161
Line ('foo' , LineBreakType .endOfText),
160
162
]);
161
163
});
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
+ '\n Expected 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
+ '\n Unexpected line break found at {$lastLineBreak - $i }.' ,
195
+ );
196
+ }
197
+ }
198
+ }
199
+ });
162
200
});
163
201
}
164
202
0 commit comments