Index: test/int64_test.dart |
diff --git a/test/int64_test.dart b/test/int64_test.dart |
index e7caa8fd6636db39355d903e52588a3798a367dd..c4498226fa79753d818371d17b88871327210cd2 100644 |
--- a/test/int64_test.dart |
+++ b/test/int64_test.dart |
@@ -35,6 +35,14 @@ void main() { |
}); |
}); |
+ argumentErrorTest(name, op, [receiver = Int64.ONE]) { |
+ throwsArgumentErrorMentioning(substring) => |
+ throwsA((e) => e is ArgumentError && '$e'.contains(substring)); |
+ |
+ expect(() => op(receiver, null), throwsArgumentErrorMentioning('null')); |
+ expect(() => op(receiver, 'foo'), throwsArgumentErrorMentioning(r'"foo"')); |
+ } |
+ |
group("is-tests", () { |
test("isEven", () { |
expect((-Int64.ONE).isEven, false); |
@@ -96,6 +104,7 @@ void main() { |
expect(n3 + n4, new Int64(-11110)); |
expect(n5 + n6, new Int64.fromInts(0x89ab89ab, 0xcdeff011)); |
expect(Int64.MAX_VALUE + 1, Int64.MIN_VALUE); |
+ argumentErrorTest("+", (a, b) => a + b); |
}); |
test("-", () { |
@@ -104,6 +113,7 @@ void main() { |
expect(n3 - n4, new Int64(8642)); |
expect(n5 - n6, new Int64.fromInts(0x9abd2345, 0x89ab6789)); |
expect(Int64.MIN_VALUE - 1, Int64.MAX_VALUE); |
+ argumentErrorTest("-", (a, b) => a - b); |
}); |
test("unary -", () { |
@@ -141,6 +151,7 @@ void main() { |
expect(Int64.MIN_VALUE * new Int64(2), Int64.ZERO); |
expect(Int64.MIN_VALUE * new Int64(1), Int64.MIN_VALUE); |
expect(Int64.MIN_VALUE * new Int64(-1), Int64.MIN_VALUE); |
+ argumentErrorTest("*", (a, b) => a * b); |
}); |
test("~/", () { |
@@ -213,7 +224,7 @@ void main() { |
expect(Int64.MIN_VALUE ~/ new Int64(1), Int64.MIN_VALUE); |
expect(Int64.MIN_VALUE ~/ new Int64(-1), Int64.MIN_VALUE); |
expect(() => new Int64(17) ~/ Int64.ZERO, throws); |
- expect(() => new Int64(17) ~/ null, throwsArgumentError); |
+ argumentErrorTest("~/", (a, b) => a ~/ b); |
}); |
test("%", () { |
@@ -253,6 +264,7 @@ void main() { |
new Int64(-0x12345678.remainder(0x22))); |
expect(new Int32(0x12345678).remainder(new Int64(0x22)), |
new Int64(0x12345678.remainder(0x22))); |
+ argumentErrorTest("%", (a, b) => a % b); |
}); |
test("clamp", () { |
@@ -327,7 +339,7 @@ void main() { |
expect(largePosPlusOne < largePos, false); |
expect(Int64.MIN_VALUE < Int64.MAX_VALUE, true); |
expect(Int64.MAX_VALUE < Int64.MIN_VALUE, false); |
- expect(() => new Int64(17) < null, throwsArgumentError); |
+ argumentErrorTest("<", (a, b) => a < b); |
}); |
test("<=", () { |
@@ -346,7 +358,7 @@ void main() { |
expect(largePosPlusOne <= largePos, false); |
expect(Int64.MIN_VALUE <= Int64.MAX_VALUE, true); |
expect(Int64.MAX_VALUE <= Int64.MIN_VALUE, false); |
- expect(() => new Int64(17) <= null, throwsArgumentError); |
+ argumentErrorTest("<=", (a, b) => a <= b); |
}); |
test("==", () { |
@@ -393,7 +405,7 @@ void main() { |
expect(largePosPlusOne >= largePos, true); |
expect(Int64.MIN_VALUE >= Int64.MAX_VALUE, false); |
expect(Int64.MAX_VALUE >= Int64.MIN_VALUE, true); |
- expect(() => new Int64(17) >= null, throwsArgumentError); |
+ argumentErrorTest(">=", (a, b) => a >= b); |
}); |
test(">", () { |
@@ -414,7 +426,7 @@ void main() { |
expect(Int64.ZERO > Int64.MIN_VALUE, true); |
expect(Int64.MIN_VALUE > Int64.MAX_VALUE, false); |
expect(Int64.MAX_VALUE > Int64.MIN_VALUE, true); |
- expect(() => new Int64(17) > null, throwsArgumentError); |
+ argumentErrorTest(">", (a, b) => a > b); |
}); |
}); |
@@ -430,6 +442,7 @@ void main() { |
expect(n3 & n2, new Int64(8708)); |
expect(n4 & n5, new Int64(0x1034) << 32); |
expect(() => n1 & null, throwsArgumentError); |
+ argumentErrorTest("&", (a, b) => a & b); |
}); |
test("|", () { |
@@ -437,6 +450,7 @@ void main() { |
expect(n3 | n2, new Int64(-66)); |
expect(n4 | n5, new Int64(0x9a76) << 32); |
expect(() => n1 | null, throwsArgumentError); |
+ argumentErrorTest("|", (a, b) => a | b); |
}); |
test("^", () { |
@@ -444,6 +458,7 @@ void main() { |
expect(n3 ^ n2, new Int64(-8774)); |
expect(n4 ^ n5, new Int64(0x8a42) << 32); |
expect(() => n1 ^ null, throwsArgumentError); |
+ argumentErrorTest("^", (a, b) => a ^ b); |
}); |
test("~", () { |
@@ -592,8 +607,8 @@ void main() { |
expect(Int64.MIN_VALUE.toSigned(64), Int64.MIN_VALUE); |
expect(Int64.MAX_VALUE.toSigned(63), -Int64.ONE); |
expect(Int64.MIN_VALUE.toSigned(63), Int64.ZERO); |
- expect(() => Int64.ONE.toSigned(0), throws); |
- expect(() => Int64.ONE.toSigned(65), throws); |
+ expect(() => Int64.ONE.toSigned(0), throwsRangeError); |
+ expect(() => Int64.ONE.toSigned(65), throwsRangeError); |
}); |
test("toUnsigned", () { |
expect((Int64.ONE << 44).toUnsigned(45), Int64.ONE << 44); |
@@ -606,8 +621,8 @@ void main() { |
expect(Int64.MIN_VALUE.toUnsigned(64), Int64.MIN_VALUE); |
expect(Int64.MAX_VALUE.toUnsigned(63), Int64.MAX_VALUE); |
expect(Int64.MIN_VALUE.toUnsigned(63), Int64.ZERO); |
- expect(() => Int64.ONE.toUnsigned(-1), throws); |
- expect(() => Int64.ONE.toUnsigned(65), throws); |
+ expect(() => Int64.ONE.toUnsigned(-1), throwsRangeError); |
+ expect(() => Int64.ONE.toUnsigned(65), throwsRangeError); |
}); |
test("toDouble", () { |
expect(new Int64(0).toDouble(), same(0.0)); |
@@ -619,14 +634,12 @@ void main() { |
expect(new Int64(-2147483648).toDouble(), same(-2147483648.0)); |
expect(new Int64(4503599627370495).toDouble(), same(4503599627370495.0)); |
expect(new Int64(4503599627370496).toDouble(), same(4503599627370496.0)); |
- expect( |
- new Int64(-4503599627370495).toDouble(), same(-4503599627370495.0)); |
- expect( |
- new Int64(-4503599627370496).toDouble(), same(-4503599627370496.0)); |
- expect(Int64 |
- .parseInt("-10000000000000000") |
- .toDouble() |
- .toStringAsFixed(1), "-10000000000000000.0"); |
+ expect(new Int64(-4503599627370495).toDouble(), |
+ same(-4503599627370495.0)); |
+ expect(new Int64(-4503599627370496).toDouble(), |
+ same(-4503599627370496.0)); |
+ expect(Int64.parseInt("-10000000000000000").toDouble().toStringAsFixed(1), |
+ "-10000000000000000.0"); |
expect(Int64.parseInt("-10000000000000001").toDouble().toStringAsFixed(1), |
"-10000000000000000.0"); |
expect(Int64.parseInt("-10000000000000002").toDouble().toStringAsFixed(1), |
@@ -657,9 +670,8 @@ void main() { |
expect(new Int64(4503599627370496).toInt(), 4503599627370496); |
expect(new Int64(-4503599627370495).toInt(), -4503599627370495); |
expect(new Int64(-4503599627370496).toInt(), -4503599627370496); |
- expect(Int64 |
- .parseInt("-10000000000000000") |
- .toInt(), same(-10000000000000000)); |
+ expect(Int64.parseInt("-10000000000000000").toInt(), |
+ same(-10000000000000000)); |
expect(Int64.parseInt("-10000000000000001").toInt(), |
same(-10000000000000001)); |
expect(Int64.parseInt("-10000000000000002").toInt(), |
@@ -775,13 +787,18 @@ void main() { |
check("9223372036854775807", 10, "9223372036854775807"); |
// Overflow during parsing. |
check("9223372036854775808", 10, "-9223372036854775808"); |
+ |
+ expect(() => Int64.parseRadix('0', 1), throwsRangeError); |
+ expect(() => Int64.parseRadix('0', 37), throwsRangeError); |
+ expect(() => Int64.parseRadix('xyzzy', -1), throwsRangeError); |
+ expect(() => Int64.parseRadix('xyzzy', 10), throwsFormatException); |
}); |
test("parseRadixN", () { |
check(String s, int r) { |
expect(Int64.parseRadix(s, r).toRadixString(r), s); |
} |
- check("2ppp111222333", 33); // This value & radix requires three chunks. |
+ check("2ppp111222333", 33); // This value & radix requires three chunks. |
}); |
}); |
@@ -836,8 +853,8 @@ void main() { |
"111111111111111111111111111111111111111111111111111111111111111"); |
expect(Int64.MAX_VALUE.toRadixString(3), |
"2021110011022210012102010021220101220221"); |
- expect( |
- Int64.MAX_VALUE.toRadixString(4), "13333333333333333333333333333333"); |
+ expect(Int64.MAX_VALUE.toRadixString(4), |
+ "13333333333333333333333333333333"); |
expect(Int64.MAX_VALUE.toRadixString(5), "1104332401304422434310311212"); |
expect(Int64.MAX_VALUE.toRadixString(6), "1540241003031030222122211"); |
expect(Int64.MAX_VALUE.toRadixString(7), "22341010611245052052300"); |