Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: pkg/fixnum/test/int_32_test.dart

Issue 34223002: Throw FormatException when Int32/Int64.parseRadix() encounters bad digit (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Formatting fix Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/fixnum/lib/src/int64.dart ('k') | pkg/fixnum/test/int_64_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 library Int32test; 5 library Int32test;
6 import 'package:fixnum/fixnum.dart'; 6 import 'package:fixnum/fixnum.dart';
7 import 'package:unittest/unittest.dart'; 7 import 'package:unittest/unittest.dart';
8 8
9 void main() { 9 void main() {
10 group("isX tests", () { 10 group("isX tests", () {
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 test("toInt32", () { 297 test("toInt32", () {
298 expect(new Int32(17).toInt32(), new Int32(17)); 298 expect(new Int32(17).toInt32(), new Int32(17));
299 expect(new Int32(-17).toInt32(), new Int32(-17)); 299 expect(new Int32(-17).toInt32(), new Int32(-17));
300 }); 300 });
301 test("toInt64", () { 301 test("toInt64", () {
302 expect(new Int32(17).toInt64(), new Int64(17)); 302 expect(new Int32(17).toInt64(), new Int64(17));
303 expect(new Int32(-17).toInt64(), new Int64(-17)); 303 expect(new Int32(-17).toInt64(), new Int64(-17));
304 }); 304 });
305 }); 305 });
306 306
307 group("parse", () {
308 test("base 10", () {
309 checkInt(int x) {
310 expect(Int32.parseRadix('$x', 10), new Int32(x));
311 }
312 checkInt(0);
313 checkInt(1);
314 checkInt(1000);
315 checkInt(12345678);
316 checkInt(2147483647);
317 checkInt(2147483648);
318 checkInt(4294967295);
319 checkInt(4294967296);
320 expect(() => Int32.parseRadix('xyzzy', -1), throwsArgumentError);
321 expect(() => Int32.parseRadix('plugh', 10),
322 throwsA(new isInstanceOf<FormatException>()));
323 });
324
325 test("parseRadix", () {
326 check(String s, int r, String x) {
327 expect(Int32.parseRadix(s, r).toString(), x);
328 }
329 check('deadbeef', 16, '-559038737');
330 check('95', 12, '113');
331 });
332 });
333
307 group("string representation", () { 334 group("string representation", () {
308 test("toString", () { 335 test("toString", () {
309 expect(new Int32(0).toString(), "0"); 336 expect(new Int32(0).toString(), "0");
310 expect(new Int32(1).toString(), "1"); 337 expect(new Int32(1).toString(), "1");
311 expect(new Int32(-1).toString(), "-1"); 338 expect(new Int32(-1).toString(), "-1");
312 expect(new Int32(1000).toString(), "1000"); 339 expect(new Int32(1000).toString(), "1000");
313 expect(new Int32(-1000).toString(), "-1000"); 340 expect(new Int32(-1000).toString(), "-1000");
314 expect(new Int32(123456789).toString(), "123456789"); 341 expect(new Int32(123456789).toString(), "123456789");
315 expect(new Int32(2147483647).toString(), "2147483647"); 342 expect(new Int32(2147483647).toString(), "2147483647");
316 expect(new Int32(2147483648).toString(), "-2147483648"); 343 expect(new Int32(2147483648).toString(), "-2147483648");
(...skipping 14 matching lines...) Expand all
331 expect(new Int32(-1).shiftRightUnsigned(8).toHexString(), "ffffff"); 358 expect(new Int32(-1).shiftRightUnsigned(8).toHexString(), "ffffff");
332 }); 359 });
333 }); 360 });
334 361
335 group("toRadixString", () { 362 group("toRadixString", () {
336 test("returns base n string representation", () { 363 test("returns base n string representation", () {
337 expect(new Int32(123456789).toRadixString(5), "223101104124"); 364 expect(new Int32(123456789).toRadixString(5), "223101104124");
338 }); 365 });
339 }); 366 });
340 } 367 }
OLDNEW
« no previous file with comments | « pkg/fixnum/lib/src/int64.dart ('k') | pkg/fixnum/test/int_64_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698