| 1 | import 'package:cw_core/format_fixed.dart'; |
| 2 | import 'package:flutter_test/flutter_test.dart'; |
| 3 | |
| 4 | void main() { |
| 5 | group('formatFixed', () { |
| 6 | group('formatFixed, no fractional digits and trimming zeros', () { |
| 7 | test('should format 1000000 into 1', |
| 8 | () => expect(formatFixed(BigInt.parse("1000000"), 6), '1')); |
| 9 | |
| 10 | test('should format 1000001 into 1.000001', |
| 11 | () => expect(formatFixed(BigInt.parse("1000001"), 6), '1.000001')); |
| 12 | }); |
| 13 | |
| 14 | group('formatFixed, different fractional digits and trimming zeros', () { |
| 15 | test( |
| 16 | 'should format 1000001 into 1', |
| 17 | () => expect(formatFixed(BigInt.parse("1000001"), 6, fractionalDigits: 5), '1'), |
| 18 | ); |
| 19 | |
| 20 | test( |
| 21 | 'should format 1000000 into 1, fractionalDigits > decimals', |
| 22 | () => expect(formatFixed(BigInt.parse("1000000"), 6, fractionalDigits: 12), '1'), |
| 23 | ); |
| 24 | |
| 25 | test( |
| 26 | 'should format 1000001 into 1.000001, fractionalDigits > decimals', |
| 27 | () => expect( |
| 28 | formatFixed(BigInt.parse("1000001"), 6, fractionalDigits: 12), |
| 29 | '1.000001', |
| 30 | ), |
| 31 | ); |
| 32 | }); |
| 33 | |
| 34 | group('formatFixed, less fractional digits and not trimming zeros', () { |
| 35 | test( |
| 36 | 'should format 1000000 into 1.000000', |
| 37 | () => expect( |
| 38 | formatFixed(BigInt.parse("1000000"), 6, trimZeros: false), |
| 39 | '1.000000', |
| 40 | ), |
| 41 | ); |
| 42 | |
| 43 | test( |
| 44 | 'should format 1000001 into 1.00000', |
| 45 | () => expect( |
| 46 | formatFixed(BigInt.parse("1000001"), 6, fractionalDigits: 5, trimZeros: false), |
| 47 | '1.00000', |
| 48 | ), |
| 49 | ); |
| 50 | |
| 51 | test( |
| 52 | 'should format 1000000 into 1.000000', |
| 53 | () => expect( |
| 54 | formatFixed(BigInt.parse("1000000"), 6, fractionalDigits: 12, trimZeros: false), |
| 55 | '1.000000', |
| 56 | ), |
| 57 | ); |
| 58 | }); |
| 59 | }); |
| 60 | } |