| OLD | NEW |
| 1 /** | 1 /** |
| 2 * Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 2 * Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 3 * for details. All rights reserved. Use of this source code is governed by a | 3 * for details. All rights reserved. Use of this source code is governed by a |
| 4 * BSD-style license that can be found in the LICENSE file. | 4 * BSD-style license that can be found in the LICENSE file. |
| 5 */ | 5 */ |
| 6 | 6 |
| 7 library number_format_test; | 7 library number_format_test; |
| 8 | 8 |
| 9 import 'package:unittest/unittest.dart'; | 9 import 'package:unittest/unittest.dart'; |
| 10 import 'package:intl/number_symbols_data.dart'; | 10 import 'package:intl/number_symbols_data.dart'; |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 test('Exponential form', () { | 136 test('Exponential form', () { |
| 137 var number = new NumberFormat("#.###E0"); | 137 var number = new NumberFormat("#.###E0"); |
| 138 for (var x in testExponential.keys) { | 138 for (var x in testExponential.keys) { |
| 139 var formatted = number.format(testExponential[x]); | 139 var formatted = number.format(testExponential[x]); |
| 140 expect(formatted, x); | 140 expect(formatted, x); |
| 141 var readBack = number.parse(formatted); | 141 var readBack = number.parse(formatted); |
| 142 expect(testExponential[x], readBack); | 142 expect(testExponential[x], readBack); |
| 143 } | 143 } |
| 144 }); | 144 }); |
| 145 | 145 |
| 146 test('Percent with no decimals and no integer part', () { |
| 147 var number = new NumberFormat("#%"); |
| 148 var formatted = number.format(0.12); |
| 149 expect(formatted, "12%"); |
| 150 var readBack = number.parse(formatted); |
| 151 expect(0.12, readBack); |
| 152 }); |
| 153 |
| 146 // We can't do these in the normal tests because those also format the | 154 // We can't do these in the normal tests because those also format the |
| 147 // numbers and we're reading them in a format where they won't print | 155 // numbers and we're reading them in a format where they won't print |
| 148 // back the same way. | 156 // back the same way. |
| 149 test('Parsing modifiers,e.g. percent, in the base format', () { | 157 test('Parsing modifiers,e.g. percent, in the base format', () { |
| 150 var number = new NumberFormat(); | 158 var number = new NumberFormat(); |
| 151 var modified = { "12%" : 0.12, "12\u2030" : 0.012}; | 159 var modified = { "12%" : 0.12, "12\u2030" : 0.012}; |
| 152 modified.addAll(testExponential); | 160 modified.addAll(testExponential); |
| 153 for (var x in modified.keys) { | 161 for (var x in modified.keys) { |
| 154 var parsed = number.parse(x); | 162 var parsed = number.parse(x); |
| 155 expect(parsed, modified[x]); | 163 expect(parsed, modified[x]); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 }); | 202 }); |
| 195 | 203 |
| 196 test('Unparseable', () { | 204 test('Unparseable', () { |
| 197 var format = new NumberFormat.currencyPattern(); | 205 var format = new NumberFormat.currencyPattern(); |
| 198 expect(() => format.parse("abcdefg"), throwsFormatException); | 206 expect(() => format.parse("abcdefg"), throwsFormatException); |
| 199 expect(() => format.parse(""), throwsFormatException); | 207 expect(() => format.parse(""), throwsFormatException); |
| 200 expect(() => format.parse("1.0zzz"), throwsFormatException); | 208 expect(() => format.parse("1.0zzz"), throwsFormatException); |
| 201 expect(() => format.parse("-∞+1"), throwsFormatException); | 209 expect(() => format.parse("-∞+1"), throwsFormatException); |
| 202 }); | 210 }); |
| 203 } | 211 } |
| OLD | NEW |