OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2014 Google Inc. All rights reserved. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style |
| 5 * license that can be found in the LICENSE file or at |
| 6 * https://developers.google.com/open-source/licenses/bsd |
| 7 */ |
| 8 |
| 9 part of charted.test.locale; |
| 10 |
| 11 testNumberFormat() { |
| 12 EnUsLocale locale = new EnUsLocale(); |
| 13 NumberFormat formatter = new NumberFormat(locale); |
| 14 |
| 15 group('NumberFormat.format returns a format function that', () { |
| 16 test('performs correctly with [[fill]align]', () { |
| 17 FormatFunction format1 = formatter.format('d<6'); |
| 18 expect(format1(123), equals('123ddd')); |
| 19 FormatFunction format2 = formatter.format('d>6'); |
| 20 expect(format2(123), equals('ddd123')); |
| 21 FormatFunction format3 = formatter.format('d^6'); |
| 22 expect(format3(123), equals('dd123d')); |
| 23 FormatFunction format4 = formatter.format('d=+6'); |
| 24 expect(format4(123), equals('+dd123')); |
| 25 FormatFunction format5 = formatter.format('06'); |
| 26 expect(format5(123), equals('000123')); |
| 27 }); |
| 28 test('performs correctly with [sign]', () { |
| 29 FormatFunction format1 = formatter.format('+'); |
| 30 expect(format1(123), equals('+123')); |
| 31 expect(format1(0), equals('+0')); |
| 32 expect(format1(-123), equals('-123')); |
| 33 FormatFunction format2 = formatter.format('-'); |
| 34 expect(format2(123), equals('-123')); |
| 35 expect(format2(0), equals('-0')); |
| 36 expect(format2(-123), equals('-123')); |
| 37 FormatFunction format3 = formatter.format(''); |
| 38 expect(format3(123), equals('123')); |
| 39 expect(format3(0), equals('0')); |
| 40 expect(format3(-123), equals('-123')); |
| 41 FormatFunction format4 = formatter.format(' '); |
| 42 expect(format4(123), equals(' 123')); |
| 43 expect(format4(0), equals(' 0')); |
| 44 expect(format4(-123), equals('-123')); |
| 45 }); |
| 46 test('performs correctly with [#]', () { |
| 47 FormatFunction format1 = formatter.format('#b'); |
| 48 expect(format1(123), equals('0b1111011')); |
| 49 FormatFunction format2 = formatter.format('#o'); |
| 50 expect(format2(123), equals('0o173')); |
| 51 FormatFunction format3 = formatter.format('#x'); |
| 52 expect(format3(123), equals('0x7b')); |
| 53 }); |
| 54 test('performs correctly with [,]', () { |
| 55 FormatFunction format1 = formatter.format(','); |
| 56 expect(format1(123), equals('123')); |
| 57 expect(format1(12345), equals('12,345')); |
| 58 }); |
| 59 test('performs correctly with [.precision]', () { |
| 60 FormatFunction format1 = formatter.format('.2f'); |
| 61 expect(format1(123.4), equals('123.40')); |
| 62 expect(format1(123.45), equals('123.45')); |
| 63 expect(format1(123.4567), equals('123.46')); |
| 64 }); |
| 65 test('performs correctly with other values of [type]', () { |
| 66 FormatFunction format1 = formatter.format('d'); |
| 67 expect(format1(123), equals('123')); |
| 68 FormatFunction format2 = formatter.format('e'); |
| 69 expect(format2(123), equals('1e+2')); |
| 70 FormatFunction format4 = formatter.format('g'); |
| 71 expect(format4(123), equals('1e+2')); |
| 72 FormatFunction format5 = formatter.format('c'); |
| 73 expect(format5(49), equals('1')); |
| 74 }); |
| 75 }); |
| 76 } |
OLD | NEW |