Initial commit: CookIT recipe collection and week planner
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
7d7a0bc60b
173 files changed
+22803
No files matched your search
@@ -0,0 +1,37 @@
|
||||
import 'package:cookit/src/recipes/text_breaks.dart';
|
||||
import 'package:flutter/painting.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
String shown(String text) => withNaturalBreaks(text).replaceAll('', '|');
|
||||
|
||||
test('breaks after hyphens, ampersands and slashes, and between words written together', () {
|
||||
expect(shown('ApfelWeißkohlPfanne&Schupfi'), 'Apfel|Weißkohl|Pfanne&|Schupfi');
|
||||
expect(shown('Brokkoli-Sahne-Nudeln'), 'Brokkoli-|Sahne-|Nudeln');
|
||||
expect(shown('AvocadoMinze Smoothie'), 'Avocado|Minze Smoothie');
|
||||
expect(shown('Salz/Pfeffer'), 'Salz/|Pfeffer');
|
||||
expect(shown('Öl-Ärger'), 'Öl-|Ärger');
|
||||
});
|
||||
|
||||
test('leaves ordinary names and abbreviations alone', () {
|
||||
expect(shown('Tomatensoße mit Spätzle'), 'Tomatensoße mit Spätzle');
|
||||
expect(shown('BBQ Burger'), 'BBQ Burger');
|
||||
expect(shown('Gef. Hähnchenfilet'), 'Gef. Hähnchenfilet');
|
||||
expect(shown('Rösti - knusprig'), 'Rösti - knusprig');
|
||||
expect(withNaturalBreaks('ApfelWeißkohl').replaceAll('', ''), 'ApfelWeißkohl');
|
||||
});
|
||||
|
||||
test('a line now ends at a natural break, not mid-word', () {
|
||||
// Test font: every glyph is fontSize wide. Room for 15 glyphs.
|
||||
List<double> lineWidths(String text) {
|
||||
final p = TextPainter(
|
||||
text: TextSpan(text: text, style: const TextStyle(fontSize: 10)),
|
||||
textDirection: TextDirection.ltr,
|
||||
)..layout(maxWidth: 155);
|
||||
return [for (final l in p.computeLineMetrics()) l.width];
|
||||
}
|
||||
|
||||
expect(lineWidths('ApfelWeißkohlPfanne'), [150, 40]); // "ApfelWeißkohlPf" | "anne"
|
||||
expect(lineWidths(withNaturalBreaks('ApfelWeißkohlPfanne')), [130, 60]); // "ApfelWeißkohl" | "Pfanne"
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user