OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library intl_test; | 5 library fixnum_test; |
6 | 6 |
7 import 'package:intl/intl.dart'; | 7 import 'package:intl/intl.dart'; |
8 import 'package:unittest/unittest.dart'; | 8 import 'package:test/test.dart'; |
9 import 'package:fixnum/fixnum.dart'; | 9 import 'package:fixnum/fixnum.dart'; |
10 | 10 |
11 var int64Values = { | 11 var int64Values = { |
12 new Int64(12345): ["USD12,345.00", "1,234,500%"], | 12 new Int64(12345): ["USD12,345.00", "1,234,500%"], |
| 13 new Int64(-12345): ["-USD12,345.00", "-1,234,500%"], |
13 new Int64(0x7FFFFFFFFFFFF): [ | 14 new Int64(0x7FFFFFFFFFFFF): [ |
14 "USD2,251,799,813,685,247.00", | 15 "USD2,251,799,813,685,247.00", |
15 "225,179,981,368,524,700%" | 16 "225,179,981,368,524,700%" |
16 ], | 17 ], |
17 Int64.parseHex('7FFFFFFFFFFFFFF'): [ | 18 Int64.parseHex('7FFFFFFFFFFFFFF'): [ |
18 "USD576,460,752,303,423,487.00", | 19 "USD576,460,752,303,423,487.00", |
19 "57,646,075,230,342,348,700%" | 20 "57,646,075,230,342,348,700%" |
20 ], | 21 ], |
21 Int64.parseHex('8000000000000000'): [ | 22 Int64.parseHex('8000000000000000'): [ |
22 "-USD9,223,372,036,854,775,808.00", | 23 "-USD9,223,372,036,854,775,808.00", |
23 "-922,337,203,685,477,580,800%" | 24 "-922,337,203,685,477,580,800%" |
24 ] | 25 ] |
25 }; | 26 }; |
26 | 27 |
27 var int32Values = { | 28 var int32Values = { |
28 new Int32(12345): ["USD12,345.00", "1,234,500%"], | 29 new Int32(12345): ["USD12,345.00", "1,234,500%"], |
29 new Int32(0x7FFFF): ["USD524,287.00", "52,428,700%"], | 30 new Int32(0x7FFFF): ["USD524,287.00", "52,428,700%"], |
30 Int32.parseHex('7FFFFFF'): ["USD134,217,727.00", "13,421,772,700%"], | 31 Int32.parseHex('7FFFFFF'): ["USD134,217,727.00", "13,421,772,700%"], |
| 32 Int32.parseHex('7FFFFFFF'): ["USD2,147,483,647.00", "214,748,364,700%"], |
31 Int32.parseHex('80000000'): ["-USD2,147,483,648.00", "-214,748,364,800%"] | 33 Int32.parseHex('80000000'): ["-USD2,147,483,648.00", "-214,748,364,800%"] |
32 }; | 34 }; |
33 | 35 |
| 36 var microMoneyValues = { |
| 37 new MicroMoney(new Int64(12345670000)): ["USD12,345.67", "1,234,567%"], |
| 38 new MicroMoney(new Int64(12345671000)): ["USD12,345.67", "1,234,567%"], |
| 39 new MicroMoney(new Int64(12345678000)): ["USD12,345.68", "1,234,568%"], |
| 40 new MicroMoney(new Int64(-12345670000)): ["-USD12,345.67", "-1,234,567%"], |
| 41 new MicroMoney(new Int64(-12345671000)): ["-USD12,345.67", "-1,234,567%"], |
| 42 new MicroMoney(new Int64(-12345678000)): ["-USD12,345.68", "-1,234,568%"], |
| 43 new MicroMoney(new Int64(12340000000)): ["USD12,340.00", "1,234,000%"], |
| 44 new MicroMoney(new Int64(0x7FFFFFFFFFFFF)): [ |
| 45 "USD2,251,799,813.69", |
| 46 "225,179,981,369%" |
| 47 ], |
| 48 new MicroMoney(Int64.parseHex('7FFFFFFFFFFFFFF')): [ |
| 49 "USD576,460,752,303.42", |
| 50 "57,646,075,230,342%" |
| 51 ], |
| 52 new MicroMoney(Int64.parseHex('7FFFFFFFFFFFFFFF')): [ |
| 53 "USD9,223,372,036,854.78", |
| 54 "922,337,203,685,478%" |
| 55 ], |
| 56 new MicroMoney(Int64.parseHex('8000000000000000')): [ |
| 57 "-USD9,223,372,036,854.78", |
| 58 "-922,337,203,685,478%" |
| 59 ] |
| 60 }; |
| 61 |
34 main() { | 62 main() { |
35 test('int64', () { | 63 test('int64', () { |
36 int64Values.forEach((number, expected) { | 64 int64Values.forEach((number, expected) { |
37 var currency = new NumberFormat.currencyPattern().format(number); | 65 var currency = new NumberFormat.currency().format(number); |
38 expect(currency, expected.first); | 66 expect(currency, expected.first); |
39 var percent = new NumberFormat.percentPattern().format(number); | 67 var percent = new NumberFormat.percentPattern().format(number); |
40 expect(percent, expected[1]); | 68 expect(percent, expected[1]); |
41 }); | 69 }); |
42 }); | 70 }); |
43 | 71 |
44 test('int32', () { | 72 test('int32', () { |
45 int32Values.forEach((number, expected) { | 73 int32Values.forEach((number, expected) { |
| 74 var currency = new NumberFormat.currency().format(number); |
| 75 expect(currency, expected.first); |
| 76 var percent = new NumberFormat.percentPattern().format(number); |
| 77 expect(percent, expected[1]); |
| 78 }); |
| 79 }); |
| 80 |
| 81 test('micro money', () { |
| 82 microMoneyValues.forEach((number, expected) { |
46 var currency = new NumberFormat.currencyPattern().format(number); | 83 var currency = new NumberFormat.currencyPattern().format(number); |
47 expect(currency, expected.first); | 84 expect(currency, expected.first); |
48 var percent = new NumberFormat.percentPattern().format(number); | 85 var percent = new NumberFormat.percentPattern().format(number); |
49 expect(percent, expected[1]); | 86 expect(percent, expected[1]); |
50 }); | 87 }); |
51 }); | 88 }); |
52 } | 89 } |
OLD | NEW |