mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 16:41:07 +00:00
![Robert Nystrom](/assets/img/avatar_default.png)
Change-Id: I764d0457da85b2935e1d83309eab4c4b5b3ea000 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/126204 Commit-Queue: Bob Nystrom <rnystrom@google.com> Reviewed-by: Lasse R.H. Nielsen <lrn@google.com> Auto-Submit: Bob Nystrom <rnystrom@google.com>
76 lines
2.8 KiB
Dart
76 lines
2.8 KiB
Dart
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
// Test for int.parse with limited 64-bit integers.
|
|
|
|
import "package:expect/expect.dart";
|
|
|
|
main() {
|
|
const int ERROR = 42;
|
|
int returnError(String s) => ERROR;
|
|
|
|
Expect.equals(0, int.parse("0"));
|
|
Expect.equals(1, int.parse("1"));
|
|
Expect.equals(-1, int.parse("-1"));
|
|
|
|
Expect.equals(0x7ffffffffffffffe, int.parse("0x7ffffffffffffffe"));
|
|
Expect.equals(0x7fffffffffffffff, int.parse("0x7fffffffffffffff"));
|
|
Expect.equals(-0x7fffffffffffffff, int.parse("-0x7fffffffffffffff"));
|
|
Expect.equals(-0x7fffffffffffffff - 1, int.parse("-0x8000000000000000"));
|
|
Expect.equals(1 << 63, int.parse("0x8000000000000000"));
|
|
|
|
Expect.equals(8999999999999999999, int.parse("8999999999999999999"));
|
|
Expect.equals(-8999999999999999999, int.parse("-8999999999999999999"));
|
|
Expect.equals(9223372036854775807, int.parse("9223372036854775807"));
|
|
Expect.equals(-9223372036854775807, int.parse("-9223372036854775807"));
|
|
Expect.equals(-9223372036854775807 - 1, int.parse("-9223372036854775808"));
|
|
|
|
Expect.equals(ERROR, int.parse("-0x8000000000000001", onError: returnError));
|
|
Expect.equals(ERROR, int.parse("9223372036854775808", onError: returnError));
|
|
Expect.equals(ERROR, int.parse("9223372036854775809", onError: returnError));
|
|
Expect.equals(ERROR, int.parse("-9223372036854775809", onError: returnError));
|
|
Expect.equals(ERROR, int.parse("10000000000000000000", onError: returnError));
|
|
|
|
Expect.equals(
|
|
0x7fffffffffffffff,
|
|
int.parse(
|
|
"111111111111111111111111111111111111111111111111111111111111111",
|
|
radix: 2));
|
|
Expect.equals(
|
|
-0x7fffffffffffffff,
|
|
int.parse(
|
|
"-111111111111111111111111111111111111111111111111111111111111111",
|
|
radix: 2));
|
|
Expect.equals(
|
|
-0x7fffffffffffffff - 1,
|
|
int.parse(
|
|
"-1000000000000000000000000000000000000000000000000000000000000000",
|
|
radix: 2));
|
|
|
|
Expect.equals(
|
|
ERROR,
|
|
int.parse(
|
|
"1000000000000000000000000000000000000000000000000000000000000000",
|
|
radix: 2,
|
|
onError: returnError));
|
|
Expect.equals(
|
|
ERROR,
|
|
int.parse(
|
|
"1111111111111111111111111111111111111111111111111111111111111110",
|
|
radix: 2,
|
|
onError: returnError));
|
|
Expect.equals(
|
|
ERROR,
|
|
int.parse(
|
|
"1111111111111111111111111111111111111111111111111111111111111111",
|
|
radix: 2,
|
|
onError: returnError));
|
|
Expect.equals(
|
|
ERROR,
|
|
int.parse(
|
|
"-1000000000000000000000000000000000000000000000000000000000000001",
|
|
radix: 2,
|
|
onError: returnError));
|
|
}
|