fix: alot
This commit is contained in:
@@ -19,4 +19,49 @@ void main() {
|
||||
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);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user