68 lines
1.6 KiB
Dart
68 lines
1.6 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:kooltap/utils/money.dart';
|
|
|
|
void main() {
|
|
group('Cents.asEuro', () {
|
|
test('formats cents in Belgian notation', () {
|
|
expect(1234.asEuro, '€ 12,34');
|
|
});
|
|
|
|
test('formats zero', () {
|
|
expect(0.asEuro, '€ 0,00');
|
|
});
|
|
|
|
test('formats whole euros with two decimals', () {
|
|
expect(500.asEuro, '€ 5,00');
|
|
});
|
|
|
|
test('groups thousands', () {
|
|
expect(123456.asEuro, '€ 1.234,56');
|
|
});
|
|
});
|
|
|
|
group('parseEuroToCents', () {
|
|
test('accepts a comma or a dot as decimal separator', () {
|
|
expect(parseEuroToCents('2,50'), 250);
|
|
expect(parseEuroToCents('2.50'), 250);
|
|
});
|
|
|
|
test('accepts whole euros and a single decimal', () {
|
|
expect(parseEuroToCents('3'), 300);
|
|
expect(parseEuroToCents('3,5'), 350);
|
|
expect(parseEuroToCents('0'), 0);
|
|
});
|
|
|
|
test('ignores surrounding whitespace', () {
|
|
expect(parseEuroToCents(' 4,20 '), 420);
|
|
});
|
|
|
|
test('is exact where doubles would round', () {
|
|
expect(parseEuroToCents('0,29'), 29);
|
|
expect(parseEuroToCents('1,15'), 115);
|
|
expect(parseEuroToCents('4,35'), 435);
|
|
});
|
|
|
|
test('rejects more than two decimals instead of rounding', () {
|
|
expect(parseEuroToCents('2,505'), isNull);
|
|
});
|
|
|
|
test('rejects anything that is not a plain amount', () {
|
|
for (final input in [
|
|
'',
|
|
'-1',
|
|
'abc',
|
|
'1e3',
|
|
'NaN',
|
|
'Infinity',
|
|
'1.000,50',
|
|
'2,',
|
|
',50',
|
|
'€2',
|
|
'1234567',
|
|
]) {
|
|
expect(parseEuroToCents(input), isNull, reason: input);
|
|
}
|
|
});
|
|
});
|
|
}
|