| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
| 6 | 6 |
| 7 main() { | 7 main() { |
| 8 // Test that we accept radix 2 to 36 and that we use lower-case | 8 // Test that we accept radix 2 to 36 and that we use lower-case |
| 9 // letters. | 9 // letters. |
| 10 var expected = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', | 10 var expected = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', |
| 11 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', | 11 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', |
| 12 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', | 12 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', |
| 13 'u', 'v', 'w', 'x', 'y', 'z']; | 13 'u', 'v', 'w', 'x', 'y', 'z']; |
| 14 for (var radix = 2; radix < 37; radix++) { | 14 for (var radix = 2; radix <= 36; radix++) { |
| 15 for (var i = 0; i < radix; i++) { | 15 for (var i = 0; i < radix; i++) { |
| 16 Expect.equals(expected[i], i.toRadixString(radix)); | 16 Expect.equals(expected[i], i.toRadixString(radix)); |
| 17 } | 17 } |
| 18 } | 18 } |
| 19 | 19 |
| 20 var illegalRadices = [ -1, 0, 1, 37 ]; | 20 var illegalRadices = [ -1, 0, 1, 37 ]; |
| 21 for (var radix in illegalRadices) { | 21 for (var radix in illegalRadices) { |
| 22 try { | 22 try { |
| 23 42.toRadixString(radix); | 23 42.toRadixString(radix); |
| 24 Expect.fail("Exception expected"); | 24 Expect.fail("Exception expected"); |
| 25 } on ArgumentError catch (e) { | 25 } on ArgumentError catch (e) { |
| 26 // Nothing to do. | 26 // Nothing to do. |
| 27 } | 27 } |
| 28 } | 28 } |
| 29 |
| 30 // Try large numbers (regression test for issue 15316). |
| 31 var bignums = [ |
| 32 0x80000000, |
| 33 0x100000000, |
| 34 0x10000000000000, |
| 35 0x10000000000001, // 53 significant bits. |
| 36 0x20000000000000, |
| 37 0x20000000000002, |
| 38 0x1000000000000000, |
| 39 0x1000000000000100, |
| 40 0x2000000000000000, |
| 41 0x2000000000000200, |
| 42 0x8000000000000000, |
| 43 0x8000000000000800, |
| 44 0x10000000000000000, |
| 45 0x10000000000001000, |
| 46 ]; |
| 47 for (var bignum in bignums) { |
| 48 for (int radix = 2; radix <= 36; radix++) { |
| 49 String digits = bignum.toRadixString(radix); |
| 50 int result = int.parse(digits, radix: radix); |
| 51 Expect.equals(bignum, result, "$bignum -> $digits/$radix"); |
| 52 } |
| 53 } |
| 29 } | 54 } |
| OLD | NEW |