Index: pkg/intl/test/number_format_test.dart |
diff --git a/pkg/intl/test/number_format_test.dart b/pkg/intl/test/number_format_test.dart |
index 048d6ad538d69d78e7b1283b9dd4b1078329ea82..2306470a5ff994334a249d1cdb81c72c98dcfba5 100644 |
--- a/pkg/intl/test/number_format_test.dart |
+++ b/pkg/intl/test/number_format_test.dart |
@@ -7,13 +7,16 @@ |
library number_format_test; |
import 'package:unittest/unittest.dart'; |
-import 'package:intl/number_format.dart'; |
+import 'package:intl/number_symbols.dart'; |
+import 'package:intl/number_symbols_data.dart'; |
import 'package:intl/intl.dart'; |
+import 'number_test_data.dart'; |
+import 'dart:math'; |
/** |
* Tests the Numeric formatting library in dart. |
*/ |
-var testNumbers = const { |
+var testNumbers = { |
"0.001": 0.001, |
"0.01": 0.01, |
"0.1": 0.1, |
@@ -23,21 +26,59 @@ var testNumbers = const { |
"100": 100, |
"1,000": 1000, |
"2,000,000,000,000": 2000000000000, |
- "10,000,000,000,000,000,000,000,000,000,000": |
- 10000000000000000000000000000000, |
"0.123": 0.123, |
"1,234": 1234.0, |
"1.234": 1.234, |
"1.23": 1.230, |
- "NaN": 0/0, |
- "∞": 1/0, |
- "-∞": -1/0}; |
+ "NaN": double.NAN, |
+ "∞": double.INFINITY, |
+ "-∞": double.NEGATIVE_INFINITY, |
+ "3.142": PI}; |
+ |
+var testExponential = const { |
+ "1E-3" : 0.001, |
+ "1E-2": 0.01, |
+ "1.23E0" : 1.23 |
+ }; |
+ |
+// TODO(alanknight): Test against currency, which requires generating data |
+// for the three different forms that this now supports. |
+// TODO(alanknight): Test against scientific, which requires significant |
+// digit support. |
+List<NumberFormat> standardFormats(String locale) { |
+ return [ |
+ new NumberFormat.decimalPattern(locale), |
+ new NumberFormat.percentPattern(locale) |
+ ]; |
+} |
+ |
+inJavaScript() => 1 is double; |
main() { |
- test('Basic number printing', () { |
- var number = new NumberFormat(); |
- expect(number.format(3.14),"3.14"); |
- }); |
+ if (!inJavaScript()) { |
+ testNumbers["10,000,000,000,000,000,000,000,000,000,000"] = |
+ 10000000000000000000000000000000; |
+ } |
+ |
+ // For data from a list of locales, run each locale's data as a separate |
+ // test so we can see exactly which ones pass or fail. |
+ var mainList = numberTestData; |
+ var sortedLocales = new List.from(numberFormatSymbols.keys); |
+ sortedLocales.sort((a, b) => a.compareTo(b)); |
+ for (var locale in sortedLocales) { |
+ var testFormats = standardFormats(locale); |
+ var list = mainList.take(testFormats.length + 1).iterator; |
+ mainList = mainList.skip(testFormats.length + 1); |
+ var nextLocaleFromList = (list..moveNext()).current; |
+ test("Test against ICU data for $locale", () { |
+ expect(locale, nextLocaleFromList); |
+ for (var format in testFormats) { |
+ var formatted = format.format(123); |
+ var expected = (list..moveNext()).current; |
+ expect(formatted, expected); |
+ } |
+ }); |
+ } |
test('Simple set of numbers', () { |
var number = new NumberFormat(); |
@@ -46,4 +87,12 @@ main() { |
expect(formatted, x); |
} |
}); |
-} |
+ |
+ test('Exponential form', () { |
+ var number = new NumberFormat("#.###E0"); |
+ for (var x in testExponential.keys) { |
+ var formatted = number.format(testExponential[x]); |
+ expect(formatted, x); |
+ } |
+ }); |
+} |