| 1 | import 'package:cw_core/crypto_amount_format.dart'; |
| 2 | import 'package:flutter_test/flutter_test.dart'; |
| 3 | |
| 4 | void main() { |
| 5 | group('String.withMaxDecimals', () { |
| 6 | test('should return the original string when it has fewer decimal places than the max', () { |
| 7 | final input = '123.45'; |
| 8 | final result = input.withMaxDecimals(3); |
| 9 | |
| 10 | expect(result, equals(input)); |
| 11 | }); |
| 12 | |
| 13 | test('should truncate decimal places when the string has more than the max', () { |
| 14 | final input = '123.4567'; |
| 15 | final result = input.withMaxDecimals(2); |
| 16 | |
| 17 | expect(result, equals('123.45')); |
| 18 | }); |
| 19 | |
| 20 | test('should handle strings with no decimal places', () { |
| 21 | final input = '123'; |
| 22 | final result = input.withMaxDecimals(2); |
| 23 | |
| 24 | expect(result, equals(input)); |
| 25 | }); |
| 26 | |
| 27 | test('should handle strings with multiple decimal points', () { |
| 28 | final input = '123.45.67'; |
| 29 | final result = input.withMaxDecimals(4); |
| 30 | |
| 31 | expect(result, equals('123.4567')); |
| 32 | }); |
| 33 | }); |
| 34 | |
| 35 | group('String.withLocalSeperator', () { |
| 36 | group('Locale en_US', () { |
| 37 | const locale = 'en_US'; |
| 38 | |
| 39 | test('should not have a grouping separator', () { |
| 40 | final input = '123.45'; |
| 41 | final result = input.withLocalSeperator(locale); |
| 42 | |
| 43 | expect(result, equals(input)); |
| 44 | }); |
| 45 | |
| 46 | test('should have a grouping seperator', () { |
| 47 | final input = '1123.4567'; |
| 48 | final result = input.withLocalSeperator(locale); |
| 49 | |
| 50 | expect(result, equals('1,123.4567')); |
| 51 | }); |
| 52 | |
| 53 | test('should have multiple grouping seperator', () { |
| 54 | final input = '1000000.4567'; |
| 55 | final result = input.withLocalSeperator(locale); |
| 56 | |
| 57 | expect(result, equals('1,000,000.4567')); |
| 58 | }); |
| 59 | }); |
| 60 | |
| 61 | group('Locale de_DE', () { |
| 62 | const locale = 'de_DE'; |
| 63 | |
| 64 | test('should not have a grouping separator', () { |
| 65 | final input = '123.45'; |
| 66 | final result = input.withLocalSeperator(locale); |
| 67 | |
| 68 | expect(result, equals('123,45')); |
| 69 | }); |
| 70 | |
| 71 | test('should have a grouping seperator', () { |
| 72 | final input = '1123.4567'; |
| 73 | final result = input.withLocalSeperator(locale); |
| 74 | |
| 75 | expect(result, equals('1.123,4567')); |
| 76 | }); |
| 77 | |
| 78 | test('should have multiple grouping seperator', () { |
| 79 | final input = '1000000.4567'; |
| 80 | final result = input.withLocalSeperator(locale); |
| 81 | |
| 82 | expect(result, equals('1.000.000,4567')); |
| 83 | }); |
| 84 | }); |
| 85 | |
| 86 | group('Locale de_CH', () { |
| 87 | const locale = 'de_CH'; |
| 88 | |
| 89 | test('should not have a grouping separator', () { |
| 90 | final input = '123.45'; |
| 91 | final result = input.withLocalSeperator(locale); |
| 92 | |
| 93 | expect(result, equals('123.45')); |
| 94 | }); |
| 95 | |
| 96 | test('should have a grouping seperator', () { |
| 97 | final input = '1123.4567'; |
| 98 | final result = input.withLocalSeperator(locale); |
| 99 | |
| 100 | expect(result, equals('1’123.4567')); |
| 101 | }); |
| 102 | |
| 103 | test('should have multiple grouping seperator', () { |
| 104 | final input = '1000000.4567'; |
| 105 | final result = input.withLocalSeperator(locale); |
| 106 | |
| 107 | expect(result, equals('1’000’000.4567')); |
| 108 | }); |
| 109 | }); |
| 110 | |
| 111 | group('With XMR Suffix', () { |
| 112 | const locale = 'de_CH'; |
| 113 | |
| 114 | test('should handle suffix expected', () { |
| 115 | final input = '1123.4567 XMR'; |
| 116 | final result = input.withLocalSeperator(locale); |
| 117 | |
| 118 | expect(result, equals('1’123.4567 XMR')); |
| 119 | }); |
| 120 | |
| 121 | test('should handle suffix odd spacing', () { |
| 122 | final input = '1123.4567 XMR '; |
| 123 | final result = input.withLocalSeperator(locale); |
| 124 | |
| 125 | expect(result, equals('1’123.4567 XMR ')); |
| 126 | }); |
| 127 | }); |
| 128 | |
| 129 | group('With > < prefix', () { |
| 130 | const locale = 'de_CH'; |
| 131 | |
| 132 | test('should handle prefix and suffix', () { |
| 133 | final input = '> 1123.4567 XMR'; |
| 134 | final result = input.withLocalSeperator(locale); |
| 135 | |
| 136 | expect(result, equals('> 1’123.4567 XMR')); |
| 137 | }); |
| 138 | |
| 139 | test('should handle prefix and suffix odd spacing', () { |
| 140 | final input = '< 1123.4567 XMR '; |
| 141 | final result = input.withLocalSeperator(locale); |
| 142 | |
| 143 | expect(result, equals('< 1’123.4567 XMR ')); |
| 144 | }); |
| 145 | |
| 146 | test('should handle just prefix', () { |
| 147 | final input = '< 1123.4567'; |
| 148 | final result = input.withLocalSeperator(locale); |
| 149 | |
| 150 | expect(result, equals('< 1’123.4567')); |
| 151 | }); |
| 152 | }); |
| 153 | }); |
| 154 | } |