|
28 | 28 |
|
29 | 29 | describe('Currency instance format method', function () {
|
30 | 30 | test('formats basic amounts with default precision', function () {
|
31 |
| - expect(Currency::UnitedStates->format(1000))->toBe('$1,000.00') |
32 |
| - ->and(Currency::Eurozone->format(1000))->toBe('€1,000.00') |
33 |
| - ->and(Currency::Japan->format(1000))->toBe('¥1,000.00') |
34 |
| - ->and(Currency::UnitedKingdom->format(1000))->toBe('£1,000.00'); |
| 31 | + expect(Currency::UnitedStates->format(1000))->toBe('$10.00') |
| 32 | + ->and(Currency::Eurozone->format(1000))->toBe('€10.00') |
| 33 | + ->and(Currency::Japan->format(1000))->toBe('¥10.00') |
| 34 | + ->and(Currency::UnitedKingdom->format(1000))->toBe('£10.00'); |
35 | 35 | });
|
36 | 36 |
|
37 | 37 | test('formats amounts with custom precision', function () {
|
38 |
| - expect(Currency::UnitedStates->format(1000, 0))->toBe('$1,000') |
39 |
| - ->and(Currency::UnitedStates->format(1000, 3))->toBe('$1,000.000') |
40 |
| - ->and(Currency::Japan->format(1000, 0))->toBe('¥1,000'); |
| 38 | + expect(Currency::UnitedStates->format(1000, 0))->toBe('$10') |
| 39 | + ->and(Currency::UnitedStates->format(1000, 3))->toBe('$10.000') |
| 40 | + ->and(Currency::Japan->format(1000, 0))->toBe('¥10'); |
41 | 41 | });
|
42 | 42 |
|
43 | 43 | test('formats large amounts correctly', function () {
|
44 |
| - expect(Currency::UnitedStates->format(1234567))->toBe('$1,234,567.00') |
45 |
| - ->and(Currency::Eurozone->format(1234567))->toBe('€1,234,567.00'); |
| 44 | + expect(Currency::UnitedStates->format(1234567))->toBe('$12,345.67') |
| 45 | + ->and(Currency::Eurozone->format(1234567))->toBe('€12,345.67'); |
46 | 46 | });
|
47 | 47 |
|
48 | 48 | test('formats small amounts correctly', function () {
|
49 |
| - expect(Currency::UnitedStates->format(1))->toBe('$1.00') |
| 49 | + expect(Currency::UnitedStates->format(1))->toBe('$0.01') |
50 | 50 | ->and(Currency::UnitedStates->format(0))->toBe('$0.00');
|
51 | 51 | });
|
52 | 52 |
|
53 | 53 | test('handles different currency symbol placements', function () {
|
54 |
| - expect(Currency::UnitedStates->format(100))->toBe('$100.00') |
55 |
| - ->and(Currency::Eurozone->format(100))->toBe('€100.00'); |
| 54 | + expect(Currency::UnitedStates->format(100))->toBe('$1.00') |
| 55 | + ->and(Currency::Eurozone->format(100))->toBe('€1.00'); |
56 | 56 | });
|
57 | 57 | });
|
58 | 58 |
|
59 | 59 | describe('Currency static format method', function () {
|
60 | 60 | test('formats with custom symbol and default settings', function () {
|
61 |
| - expect(Currency::format(1000, '$'))->toBe('$1,000.00') |
62 |
| - ->and(Currency::format(1000, '€'))->toBe('€1,000.00') |
63 |
| - ->and(Currency::format(1000, '£'))->toBe('£1,000.00'); |
| 61 | + expect(Currency::format(1000, '$'))->toBe('$10.00') |
| 62 | + ->and(Currency::format(1000, '€'))->toBe('€10.00') |
| 63 | + ->and(Currency::format(1000, '£'))->toBe('£10.00'); |
64 | 64 | });
|
65 | 65 |
|
66 | 66 | test('formats with custom precision', function () {
|
67 |
| - expect(Currency::format(1000, '$', 0))->toBe('$1,000') |
68 |
| - ->and(Currency::format(1000, '$', 3))->toBe('$1,000.000') |
69 |
| - ->and(Currency::format(1000, '$', 1))->toBe('$1,000.0'); |
| 67 | + expect(Currency::format(1000, '$', 0))->toBe('$10') |
| 68 | + ->and(Currency::format(1000, '$', 3))->toBe('$10.000') |
| 69 | + ->and(Currency::format(1000, '$', 1))->toBe('$10.0'); |
70 | 70 | });
|
71 | 71 |
|
72 | 72 | test('formats with custom decimal separator', function () {
|
73 |
| - expect(Currency::format(1000, '€', 2, ','))->toBe('€1,000,00') |
74 |
| - ->and(Currency::format(1500, '$', 2, ','))->toBe('$1,500,00'); |
| 73 | + expect(Currency::format(1000, '€', 2, ','))->toBe('€10,00') |
| 74 | + ->and(Currency::format(1500, '$', 2, ','))->toBe('$15,00'); |
75 | 75 | });
|
76 | 76 |
|
77 | 77 | test('formats with custom thousands separator', function () {
|
78 |
| - expect(Currency::format(1000, '$', 2, '.', ' '))->toBe('$1 000.00') |
79 |
| - ->and(Currency::format(12345, '€', 2, ',', '.'))->toBe('€12.345,00'); |
| 78 | + expect(Currency::format(1000, '$', 2, '.', ' '))->toBe('$10.00') |
| 79 | + ->and(Currency::format(12345, '€', 2, ',', '.'))->toBe('€123,45'); |
80 | 80 | });
|
81 | 81 |
|
82 | 82 | test('formats with all custom parameters', function () {
|
83 |
| - expect(Currency::format(12345, 'CHF', 1, ',', '.'))->toBe('CHF12.345,0') |
84 |
| - ->and(Currency::format(98765, 'kr', 0, '.', ' '))->toBe('kr98 765'); |
| 83 | + expect(Currency::format(12345, 'CHF', 1, ',', '.'))->toBe('CHF123,5') |
| 84 | + ->and(Currency::format(98765, 'kr', 0, '.', ' '))->toBe('kr988'); |
85 | 85 | });
|
86 | 86 |
|
87 | 87 | test('handles edge cases with zero amounts', function () {
|
|
90 | 90 | });
|
91 | 91 |
|
92 | 92 | test('handles large numbers', function () {
|
93 |
| - expect(Currency::format(1234567890, '$'))->toBe('$1,234,567,890.00') |
94 |
| - ->and(Currency::format(1000000, '€', 2, ',', '.'))->toBe('€1.000.000,00'); |
| 93 | + expect(Currency::format(1234567890, '$'))->toBe('$12,345,678.90') |
| 94 | + ->and(Currency::format(1000000, '€', 2, ',', '.'))->toBe('€10.000,00'); |
95 | 95 | });
|
96 | 96 | });
|
97 | 97 |
|
|
109 | 109 |
|
110 | 110 | describe('Currency format real-world scenarios', function () {
|
111 | 111 | test('formats common financial amounts', function () {
|
112 |
| - expect(Currency::UnitedStates->format(99))->toBe('$99.00') |
113 |
| - ->and(Currency::UnitedStates->format(9999))->toBe('$9,999.00') |
114 |
| - ->and(Currency::UnitedStates->format(10000))->toBe('$10,000.00') |
115 |
| - ->and(Currency::UnitedStates->format(1000000))->toBe('$1,000,000.00'); |
| 112 | + expect(Currency::UnitedStates->format(99))->toBe('$0.99') |
| 113 | + ->and(Currency::UnitedStates->format(9999))->toBe('$99.99') |
| 114 | + ->and(Currency::UnitedStates->format(10000))->toBe('$100.00') |
| 115 | + ->and(Currency::UnitedStates->format(1000000))->toBe('$10,000.00'); |
116 | 116 | });
|
117 | 117 |
|
118 | 118 | test('formats different currency styles', function () {
|
119 |
| - expect(Currency::Brazil->format(1000))->toBe('R$1,000.00') |
120 |
| - ->and(Currency::SouthAfrica->format(1000))->toBe('R1,000.00') |
121 |
| - ->and(Currency::Poland->format(1000))->toBe('zł1,000.00') |
122 |
| - ->and(Currency::Thailand->format(1000))->toBe('฿1,000.00'); |
| 119 | + expect(Currency::Brazil->format(1000))->toBe('R$10.00') |
| 120 | + ->and(Currency::SouthAfrica->format(1000))->toBe('R10.00') |
| 121 | + ->and(Currency::Poland->format(1000))->toBe('zł10.00') |
| 122 | + ->and(Currency::Thailand->format(1000))->toBe('฿10.00'); |
123 | 123 | });
|
124 | 124 |
|
125 | 125 | test('supports various precision requirements', function () {
|
126 | 126 | // No decimals for currencies like Japanese Yen
|
127 |
| - expect(Currency::Japan->format(1000, 0))->toBe('¥1,000') |
| 127 | + expect(Currency::Japan->format(1000, 0))->toBe('¥10') |
128 | 128 | // Standard 2 decimals for most currencies
|
129 |
| - ->and(Currency::UnitedStates->format(1000, 2))->toBe('$1,000.00') |
| 129 | + ->and(Currency::UnitedStates->format(1000, 2))->toBe('$10.00') |
130 | 130 | // High precision for specialized use
|
131 |
| - ->and(Currency::UnitedStates->format(1000, 8))->toBe('$1,000.00000000'); |
| 131 | + ->and(Currency::UnitedStates->format(1000, 8))->toBe('$10.00000000'); |
132 | 132 | });
|
133 | 133 | });
|
134 | 134 | });
|
|
0 commit comments