47 lines
1.6 KiB
Dart
47 lines
1.6 KiB
Dart
import 'package:cookit/src/recipes/amount.dart';
|
||||
|
|
import 'package:flutter_test/flutter_test.dart';
|
|||
|
|
import 'package:intl/date_symbol_data_local.dart';
|
|||
|
|
|
|||
|
|
void main() {
|
|||
|
|
setUpAll(() => initializeDateFormatting('de'));
|
|||
|
|
|
|||
|
|
group('parseAmount', () {
|
|||
|
|
final cases = <String, Amount?>{
|
|||
|
|
'': (amount: null, amountMax: null),
|
|||
|
|
'2': (amount: 2, amountMax: null),
|
|||
|
|
'1,5': (amount: 1.5, amountMax: null),
|
|||
|
|
'0.25': (amount: 0.25, amountMax: null),
|
|||
|
|
'½': (amount: 0.5, amountMax: null),
|
|||
|
|
'1½': (amount: 1.5, amountMax: null),
|
|||
|
|
'1/2': (amount: 0.5, amountMax: null),
|
|||
|
|
'1 1/2': (amount: 1.5, amountMax: null),
|
|||
|
|
'2-3': (amount: 2, amountMax: 3),
|
|||
|
|
'10 – 12': (amount: 10, amountMax: 12),
|
|||
|
|
'1 bis 2': (amount: 1, amountMax: 2),
|
|||
|
|
'etwas': null,
|
|||
|
|
'2-': null,
|
|||
|
|
};
|
|||
|
|
cases.forEach((input, expected) {
|
|||
|
|
test('"$input"', () => expect(parseAmount(input), expected));
|
|||
|
|
});
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
group('formatAmount', () {
|
|||
|
|
test('uses fraction glyphs and German decimals', () {
|
|||
|
|
expect(formatAmount(1.5, null), '1½');
|
|||
|
|
expect(formatAmount(0.25, null), '¼');
|
|||
|
|
expect(formatAmount(0.333, null), '⅓');
|
|||
|
|
expect(formatAmount(2, null), '2');
|
|||
|
|
expect(formatAmount(1.4, null), '1,4');
|
|||
|
|
expect(formatAmount(1000, null), '1.000');
|
|||
|
|
expect(formatAmount(2, 3), '2–3');
|
|||
|
|
expect(formatAmount(null, null), '');
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
test('round-trips through parseAmount', () {
|
|||
|
|
for (final value in [0.5, 1.5, 2.0, 1.4, 250.0]) {
|
|||
|
|
expect(parseAmount(formatAmount(value, null))!.amount, closeTo(value, 0.001));
|
|||
|
|
}
|
|||
|
|
});
|
|||
|
|
});
|
|||
|
|
}
|