Files
fanuzu/app/test/keep_words_test.dart

31 lines
1.3 KiB
Dart
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import 'package:fancake/core/ui/app_dialog.dart' show keepWords;
import 'package:flutter/painting.dart';
import 'package:flutter_test/flutter_test.dart';
/// 10/6 실기기 D-4 — 광고 안내 모달 제목이 「얻으세 / 요.」로 낱말 중간에서 바뀌었다.
void main() {
test('줄은 공백에서만 바뀐다', () {
const text = '더 많은 기여의 기회를 얻으세요.';
final joined = keepWords(text);
expect(joined.replaceAll('⁠', ''), text);
// 여러 폭에서 줄 끝이 늘 공백 앞뒤다.
// 가장 긴 어절(「얻으세요.」)보다 넓은 폭만 — 그보다 좁으면 엔진이 어절 안을 끊는다.
for (var width = 160.0; width <= 400; width += 7) {
final painter = TextPainter(
text: TextSpan(text: joined, style: const TextStyle(fontSize: 25)),
textDirection: TextDirection.ltr,
)..layout(maxWidth: width);
for (final line in painter.computeLineMetrics().skip(1)) {
final start = painter
.getPositionForOffset(Offset(0, line.baseline - line.ascent + 1))
.offset;
expect(
start == 0 || joined[start - 1] == ' ',
isTrue,
reason: 'width $width: 「${joined.substring(start).replaceAll('⁠', '')}」',
);
}
}
});
}