Migrate test block 7 to Dart 2.0.

duration2_test.dart converted to a static-only test and skipped where appropriate for non-strong.  error_stack_trace_test converted to a multitest and error_stack_trace1_test modified to use more modern catch convention for stack traces.

R=bkonyi@google.com, rnystrom@google.com

Review-Url: https://codereview.chromium.org/2987793002 .
This commit is contained in:
Janice Collins 2017-08-03 08:55:27 -07:00
parent 328c30324c
commit 28a856828b
36 changed files with 17 additions and 978 deletions

View file

@ -1,27 +0,0 @@
// Copyright (c) 2015, 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.
import "package:expect/expect.dart";
main() {
// If the duration class multiplies "str" * microseconds-per-day (instead of
// (microseconds-per-day * "str") it will try to build up a huge string and
// terminate with an out-of-memory exception instead of an ArgumentError or
// TypeError.
// See dartbug.com/22309
String longString = "str" * 1000;
Expect.throws(() => new Duration(days: longString),
(e) => e is ArgumentError || e is TypeError || e is NoSuchMethodError);
Expect.throws(() => new Duration(hours: longString),
(e) => e is ArgumentError || e is TypeError || e is NoSuchMethodError);
Expect.throws(() => new Duration(minutes: longString),
(e) => e is ArgumentError || e is TypeError || e is NoSuchMethodError);
Expect.throws(() => new Duration(seconds: longString),
(e) => e is ArgumentError || e is TypeError || e is NoSuchMethodError);
Expect.throws(() => new Duration(milliseconds: longString),
(e) => e is ArgumentError || e is TypeError || e is NoSuchMethodError);
Expect.throws(() => new Duration(microseconds: longString),
(e) => e is ArgumentError || e is TypeError || e is NoSuchMethodError);
}

View file

@ -1,29 +0,0 @@
// Copyright (c) 2013, 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.
import "package:expect/expect.dart";
class A {
get foo => cyclicStatic;
}
var a = new A();
var cyclicStatic = (() => a.foo + 1)();
cyclicInitialization() {
return cyclicStatic;
}
main() {
bool hasThrown = false;
try {
cyclicStatic + 1;
} catch (e2) {
var e = e2;
hasThrown = true;
Expect.isTrue(
e.stackTrace is StackTrace, "$e doesn't have a non-null stack trace");
}
Expect.isTrue(hasThrown);
}

View file

@ -1,83 +0,0 @@
// Copyright (c) 2013, 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.
import "package:expect/expect.dart";
void argument() {
throw new ArgumentError(499);
}
void noSuchMethod() {
(499).doesNotExist();
}
void nullThrown() {
throw null;
}
void range() {
throw new RangeError.range(0, 1, 2);
}
void fallThrough() {
nested() {}
switch (5) {
case 5:
nested();
default:
Expect.fail("Should not reach");
}
}
abstract class A {
foo();
}
void abstractClassInstantiation() {
new A();
}
void unsupported() {
throw new UnsupportedError("unsupported");
}
void unimplemented() {
throw new UnimplementedError("unimplemented");
}
void state() {
return [1, 2].single;
}
void type() {
return 1 + "string";
}
main() {
List<Function> errorFunctions = [
argument,
noSuchMethod,
nullThrown,
range,
fallThrough,
abstractClassInstantiation,
unsupported,
unimplemented,
state,
type
];
for (var f in errorFunctions) {
bool hasThrown = false;
try {
f();
} catch (e) {
hasThrown = true;
Expect.isTrue(
e.stackTrace is StackTrace, "$e doesn't have a non-null stack trace");
}
Expect.isTrue(hasThrown);
}
}

View file

@ -156,6 +156,12 @@ nan_infinity_test/01: RuntimeError
[ $compiler == dart2js && $runtime == drt && $csp && $minified ]
core_runtime_types_test: Pass, Fail # Issue 27913
[ $compiler != dartdevc ]
error_stack_trace_test/static: MissingCompileTimeError
[ $compiler == dartdevc ]
error_stack_trace_test/nullThrown: RuntimeError # .stackTrace not present for exception caught from 'throw null;'
[ $runtime == flutter ]
apply3_test: CompileTimeError # mirrors not supported
bool_from_environment_test: Fail # Flutter Issue 9111
@ -355,6 +361,7 @@ symbol_test/none: RuntimeError # Issue 27394
string_static_test: MissingCompileTimeError
[ $compiler == dart2js && $runtime != none && !$dart2js_with_kernel]
error_stack_trace1_test: RuntimeError # Issue 12399
symbol_reserved_word_test/03: RuntimeError # Issue 19972, new Symbol('void') should be allowed.
regexp/pcre_test: Pass, Slow # Issue 21593

View file

@ -27,9 +27,9 @@ main() {
bool hasThrown = false;
try {
B.Ba();
} catch (e) {
} catch (e, stackTrace) {
hasThrown = true;
var trace = e.stackTrace.toString();
var trace = stackTrace.toString();
print(trace);
Expect.isTrue(trace.contains("Bc"));
Expect.isTrue(trace.contains("Bb"));

View file

@ -8,8 +8,9 @@ void argument() {
throw new ArgumentError(499);
}
// Verify that
void noSuchMethod() {
(499).doesNotExist();
(499 as dynamic).doesNotExist();
}
void nullThrown() {
@ -20,25 +21,10 @@ void range() {
throw new RangeError.range(0, 1, 2);
}
void fallThrough() {
nested() {}
switch (5) {
case 5:
nested();
default:
Expect.fail("Should not reach");
}
}
abstract class A {
foo();
}
void abstractClassInstantiation() {
new A();
}
void unsupported() {
throw new UnsupportedError("unsupported");
}
@ -48,25 +34,24 @@ void unimplemented() {
}
void state() {
return [1, 2].single;
[1, 2].single;
}
void type() {
return 1 + "string";
void cast() {
dynamic d = 1;
d as String;
}
main() {
List<Function> errorFunctions = [
argument,
noSuchMethod,
nullThrown,
nullThrown, //# nullThrown: ok
range,
fallThrough,
abstractClassInstantiation,
unsupported,
unimplemented,
state,
type
cast,
];
for (var f in errorFunctions) {

View file

@ -1,12 +0,0 @@
// Copyright (c) 2013, 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.
import 'package:expect/expect.dart';
main() {
Expect.throws(() => double.INFINITY.round(), (e) => e is UnsupportedError);
Expect.throws(
() => double.NEGATIVE_INFINITY.round(), (e) => e is UnsupportedError);
Expect.throws(() => double.NAN.round(), (e) => e is UnsupportedError);
}

View file

@ -1,12 +0,0 @@
// Copyright (c) 2013, 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.
import 'package:expect/expect.dart';
main() {
Expect.equals(0, 0.49999999999999994.round());
Expect.equals(0, (-0.49999999999999994).round());
Expect.isTrue(0.49999999999999994.round() is int);
Expect.isTrue((-0.49999999999999994).round() is int);
}

View file

@ -1,38 +0,0 @@
// Copyright (c) 2013, 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.
import 'package:expect/expect.dart';
main() {
// The following numbers are on the border of 52 bits.
// For example: 4503599627370499 + 0.5 => 4503599627370500.
Expect.equals(4503599627370496, 4503599627370496.0.round());
Expect.equals(4503599627370497, 4503599627370497.0.round());
Expect.equals(4503599627370498, 4503599627370498.0.round());
Expect.equals(4503599627370499, 4503599627370499.0.round());
Expect.equals(9007199254740991, 9007199254740991.0.round());
Expect.equals(9007199254740992, 9007199254740992.0.round());
Expect.equals(-4503599627370496, (-4503599627370496.0).round());
Expect.equals(-4503599627370497, (-4503599627370497.0).round());
Expect.equals(-4503599627370498, (-4503599627370498.0).round());
Expect.equals(-4503599627370499, (-4503599627370499.0).round());
Expect.equals(-9007199254740991, (-9007199254740991.0).round());
Expect.equals(-9007199254740992, (-9007199254740992.0).round());
Expect.isTrue(4503599627370496.0.round() is int);
Expect.isTrue(4503599627370497.0.round() is int);
Expect.isTrue(4503599627370498.0.round() is int);
Expect.isTrue(4503599627370499.0.round() is int);
Expect.isTrue(9007199254740991.0.round() is int);
Expect.isTrue(9007199254740992.0.round() is int);
Expect.isTrue((-4503599627370496.0).round() is int);
Expect.isTrue((-4503599627370497.0).round() is int);
Expect.isTrue((-4503599627370498.0).round() is int);
Expect.isTrue((-4503599627370499.0).round() is int);
Expect.isTrue((-9007199254740991.0).round() is int);
Expect.isTrue((-9007199254740992.0).round() is int);
}

View file

@ -1,54 +0,0 @@
// Copyright (c) 2013, 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.
import 'package:expect/expect.dart';
main() {
Expect.equals(0, 0.0.round());
Expect.equals(0, double.MIN_POSITIVE.round());
Expect.equals(0, (2.0 * double.MIN_POSITIVE).round());
Expect.equals(0, (1.18e-38).round());
Expect.equals(0, (1.18e-38 * 2).round());
Expect.equals(1, 0.5.round());
Expect.equals(1, 0.9999999999999999.round());
Expect.equals(1, 1.0.round());
Expect.equals(1, 1.000000000000001.round());
Expect.equals(
179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368,
double.MAX_FINITE.round());
Expect.equals(0, (-double.MIN_POSITIVE).round());
Expect.equals(0, (2.0 * -double.MIN_POSITIVE).round());
Expect.equals(0, (-1.18e-38).round());
Expect.equals(0, (-1.18e-38 * 2).round());
Expect.equals(-1, (-0.5).round());
Expect.equals(-1, (-0.9999999999999999).round());
Expect.equals(-1, (-1.0).round());
Expect.equals(-1, (-1.000000000000001).round());
Expect.equals(
-179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368,
(-double.MAX_FINITE).round());
Expect.isTrue(0.0.round() is int);
Expect.isTrue(double.MIN_POSITIVE.round() is int);
Expect.isTrue((2.0 * double.MIN_POSITIVE).round() is int);
Expect.isTrue((1.18e-38).round() is int);
Expect.isTrue((1.18e-38 * 2).round() is int);
Expect.isTrue(0.5.round() is int);
Expect.isTrue(0.9999999999999999.round() is int);
Expect.isTrue(1.0.round() is int);
Expect.isTrue(1.000000000000001.round() is int);
Expect.isTrue(double.MAX_FINITE.round() is int);
Expect.isTrue((-double.MIN_POSITIVE).round() is int);
Expect.isTrue((2.0 * -double.MIN_POSITIVE).round() is int);
Expect.isTrue((-1.18e-38).round() is int);
Expect.isTrue((-1.18e-38 * 2).round() is int);
Expect.isTrue((-0.5).round() is int);
Expect.isTrue((-0.9999999999999999).round() is int);
Expect.isTrue((-1.0).round() is int);
Expect.isTrue((-1.000000000000001).round() is int);
Expect.isTrue((-double.MAX_FINITE).round() is int);
}

View file

@ -1,13 +0,0 @@
// Copyright (c) 2013, 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.
import 'package:expect/expect.dart';
main() {
Expect.equals(0.0, 0.49999999999999994.roundToDouble());
Expect.equals(0.0, (-0.49999999999999994).roundToDouble());
Expect.isTrue(0.49999999999999994.roundToDouble() is double);
Expect.isTrue((-0.49999999999999994).roundToDouble().isNegative);
Expect.isTrue((-0.49999999999999994).roundToDouble() is double);
}

View file

@ -1,34 +0,0 @@
// Copyright (c) 2013, 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.
import 'package:expect/expect.dart';
main() {
// The following numbers are on the border of 52 bits.
// For example: 4503599627370499 + 0.5 => 4503599627370500.
Expect.equals(4503599627370496.0, 4503599627370496.0.roundToDouble());
Expect.equals(4503599627370497.0, 4503599627370497.0.roundToDouble());
Expect.equals(4503599627370498.0, 4503599627370498.0.roundToDouble());
Expect.equals(4503599627370499.0, 4503599627370499.0.roundToDouble());
Expect.equals(9007199254740991.0, 9007199254740991.0.roundToDouble());
Expect.equals(9007199254740992.0, 9007199254740992.0.roundToDouble());
Expect.equals(-4503599627370496.0, (-4503599627370496.0).roundToDouble());
Expect.equals(-4503599627370497.0, (-4503599627370497.0).roundToDouble());
Expect.equals(-4503599627370498.0, (-4503599627370498.0).roundToDouble());
Expect.equals(-4503599627370499.0, (-4503599627370499.0).roundToDouble());
Expect.equals(-9007199254740991.0, (-9007199254740991.0).roundToDouble());
Expect.equals(-9007199254740992.0, (-9007199254740992.0).roundToDouble());
Expect.isTrue(4503599627370496.0.roundToDouble() is double);
Expect.isTrue(4503599627370497.0.roundToDouble() is double);
Expect.isTrue(4503599627370498.0.roundToDouble() is double);
Expect.isTrue(4503599627370499.0.roundToDouble() is double);
Expect.isTrue(9007199254740991.0.roundToDouble() is double);
Expect.isTrue(9007199254740992.0.roundToDouble() is double);
Expect.isTrue((-4503599627370496.0).roundToDouble() is double);
Expect.isTrue((-4503599627370497.0).roundToDouble() is double);
Expect.isTrue((-4503599627370498.0).roundToDouble() is double);
Expect.isTrue((-4503599627370499.0).roundToDouble() is double);
Expect.isTrue((-9007199254740991.0).roundToDouble() is double);
Expect.isTrue((-9007199254740992.0).roundToDouble() is double);
}

View file

@ -1,62 +0,0 @@
// Copyright (c) 2013, 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.
import 'package:expect/expect.dart';
main() {
Expect.equals(0.0, 0.0.roundToDouble());
Expect.equals(0.0, double.MIN_POSITIVE.roundToDouble());
Expect.equals(0.0, (2.0 * double.MIN_POSITIVE).roundToDouble());
Expect.equals(0.0, (1.18e-38).roundToDouble());
Expect.equals(0.0, (1.18e-38 * 2).roundToDouble());
Expect.equals(1.0, 0.5.roundToDouble());
Expect.equals(1.0, 0.9999999999999999.roundToDouble());
Expect.equals(1.0, 1.0.roundToDouble());
Expect.equals(1.0, 1.000000000000001.roundToDouble());
Expect.equals(2.0, 1.5.roundToDouble());
Expect.equals(double.MAX_FINITE, double.MAX_FINITE.roundToDouble());
Expect.equals(0.0, (-double.MIN_POSITIVE).roundToDouble());
Expect.equals(0.0, (2.0 * -double.MIN_POSITIVE).roundToDouble());
Expect.equals(0.0, (-1.18e-38).roundToDouble());
Expect.equals(0.0, (-1.18e-38 * 2).roundToDouble());
Expect.equals(-1.0, (-0.5).roundToDouble());
Expect.equals(-1.0, (-0.9999999999999999).roundToDouble());
Expect.equals(-1.0, (-1.0).roundToDouble());
Expect.equals(-1.0, (-1.000000000000001).roundToDouble());
Expect.equals(-2.0, (-1.5).roundToDouble());
Expect.equals(-double.MAX_FINITE, (-double.MAX_FINITE).roundToDouble());
Expect.equals(double.INFINITY, double.INFINITY.roundToDouble());
Expect.equals(
double.NEGATIVE_INFINITY, double.NEGATIVE_INFINITY.roundToDouble());
Expect.isTrue(double.NAN.roundToDouble().isNaN);
Expect.isTrue(0.0.roundToDouble() is double);
Expect.isTrue(double.MIN_POSITIVE.roundToDouble() is double);
Expect.isTrue((2.0 * double.MIN_POSITIVE).roundToDouble() is double);
Expect.isTrue((1.18e-38).roundToDouble() is double);
Expect.isTrue((1.18e-38 * 2).roundToDouble() is double);
Expect.isTrue(0.5.roundToDouble() is double);
Expect.isTrue(0.9999999999999999.roundToDouble() is double);
Expect.isTrue(1.0.roundToDouble() is double);
Expect.isTrue(1.000000000000001.roundToDouble() is double);
Expect.isTrue(double.MAX_FINITE.roundToDouble() is double);
Expect.isTrue((-double.MIN_POSITIVE).roundToDouble().isNegative);
Expect.isTrue((2.0 * -double.MIN_POSITIVE).roundToDouble().isNegative);
Expect.isTrue((-1.18e-38).roundToDouble().isNegative);
Expect.isTrue((-1.18e-38 * 2).roundToDouble().isNegative);
Expect.isTrue((-double.MIN_POSITIVE).roundToDouble() is double);
Expect.isTrue((2.0 * -double.MIN_POSITIVE).roundToDouble() is double);
Expect.isTrue((-1.18e-38).roundToDouble() is double);
Expect.isTrue((-1.18e-38 * 2).roundToDouble() is double);
Expect.isTrue((-0.5).roundToDouble() is double);
Expect.isTrue((-0.9999999999999999).roundToDouble() is double);
Expect.isTrue((-1.0).roundToDouble() is double);
Expect.isTrue((-1.000000000000001).roundToDouble() is double);
Expect.isTrue((-double.MAX_FINITE).roundToDouble() is double);
}

View file

@ -1,12 +0,0 @@
// Copyright (c) 2013, 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.
import 'package:expect/expect.dart';
main() {
Expect.throws(() => double.INFINITY.truncate(), (e) => e is UnsupportedError);
Expect.throws(
() => double.NEGATIVE_INFINITY.truncate(), (e) => e is UnsupportedError);
Expect.throws(() => double.NAN.truncate(), (e) => e is UnsupportedError);
}

View file

@ -1,92 +0,0 @@
// Copyright (c) 2013, 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.
import 'package:expect/expect.dart';
main() {
Expect.equals(0, 0.0.truncate());
Expect.equals(0, double.MIN_POSITIVE.truncate());
Expect.equals(0, (2.0 * double.MIN_POSITIVE).truncate());
Expect.equals(0, (1.18e-38).truncate());
Expect.equals(0, (1.18e-38 * 2).truncate());
Expect.equals(0, 0.49999999999999994.truncate());
Expect.equals(0, 0.5.truncate());
Expect.equals(0, 0.9999999999999999.truncate());
Expect.equals(1, 1.0.truncate());
Expect.equals(1, 1.000000000000001.truncate());
// The following numbers are on the border of 52 bits.
// For example: 4503599627370499 + 0.5 => 4503599627370500.
Expect.equals(4503599627370496, 4503599627370496.0.truncate());
Expect.equals(4503599627370497, 4503599627370497.0.truncate());
Expect.equals(4503599627370498, 4503599627370498.0.truncate());
Expect.equals(4503599627370499, 4503599627370499.0.truncate());
Expect.equals(9007199254740991, 9007199254740991.0.truncate());
Expect.equals(9007199254740992, 9007199254740992.0.truncate());
Expect.equals(
179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368,
double.MAX_FINITE.truncate());
Expect.equals(0, (-double.MIN_POSITIVE).truncate());
Expect.equals(0, (2.0 * -double.MIN_POSITIVE).truncate());
Expect.equals(0, (-1.18e-38).truncate());
Expect.equals(0, (-1.18e-38 * 2).truncate());
Expect.equals(0, (-0.49999999999999994).truncate());
Expect.equals(0, (-0.5).truncate());
Expect.equals(0, (-0.9999999999999999).truncate());
Expect.equals(-1, (-1.0).truncate());
Expect.equals(-1, (-1.000000000000001).truncate());
Expect.equals(-4503599627370496, (-4503599627370496.0).truncate());
Expect.equals(-4503599627370497, (-4503599627370497.0).truncate());
Expect.equals(-4503599627370498, (-4503599627370498.0).truncate());
Expect.equals(-4503599627370499, (-4503599627370499.0).truncate());
Expect.equals(-9007199254740991, (-9007199254740991.0).truncate());
Expect.equals(-9007199254740992, (-9007199254740992.0).truncate());
Expect.equals(
-179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368,
(-double.MAX_FINITE).truncate());
Expect.isTrue(0.0.truncate() is int);
Expect.isTrue(double.MIN_POSITIVE.truncate() is int);
Expect.isTrue((2.0 * double.MIN_POSITIVE).truncate() is int);
Expect.isTrue((1.18e-38).truncate() is int);
Expect.isTrue((1.18e-38 * 2).truncate() is int);
Expect.isTrue(0.49999999999999994.truncate() is int);
Expect.isTrue(0.5.truncate() is int);
Expect.isTrue(0.9999999999999999.truncate() is int);
Expect.isTrue(1.0.truncate() is int);
Expect.isTrue(1.000000000000001.truncate() is int);
Expect.isTrue(4503599627370496.0.truncate() is int);
Expect.isTrue(4503599627370497.0.truncate() is int);
Expect.isTrue(4503599627370498.0.truncate() is int);
Expect.isTrue(4503599627370499.0.truncate() is int);
Expect.isTrue(9007199254740991.0.truncate() is int);
Expect.isTrue(9007199254740992.0.truncate() is int);
Expect.isTrue(double.MAX_FINITE.truncate() is int);
Expect.isTrue((-double.MIN_POSITIVE).truncateToDouble().isNegative);
Expect.isTrue((2.0 * -double.MIN_POSITIVE).truncateToDouble().isNegative);
Expect.isTrue((-1.18e-38).truncateToDouble().isNegative);
Expect.isTrue((-1.18e-38 * 2).truncateToDouble().isNegative);
Expect.isTrue((-0.49999999999999994).truncateToDouble().isNegative);
Expect.isTrue((-0.5).truncateToDouble().isNegative);
Expect.isTrue((-0.9999999999999999).truncateToDouble().isNegative);
Expect.isTrue((-double.MIN_POSITIVE).truncate() is int);
Expect.isTrue((2.0 * -double.MIN_POSITIVE).truncate() is int);
Expect.isTrue((-1.18e-38).truncate() is int);
Expect.isTrue((-1.18e-38 * 2).truncate() is int);
Expect.isTrue((-0.49999999999999994).truncate() is int);
Expect.isTrue((-0.5).truncate() is int);
Expect.isTrue((-0.9999999999999999).truncate() is int);
Expect.isTrue((-1.0).truncate() is int);
Expect.isTrue((-1.000000000000001).truncate() is int);
Expect.isTrue((-4503599627370496.0).truncate() is int);
Expect.isTrue((-4503599627370497.0).truncate() is int);
Expect.isTrue((-4503599627370498.0).truncate() is int);
Expect.isTrue((-4503599627370499.0).truncate() is int);
Expect.isTrue((-9007199254740991.0).truncate() is int);
Expect.isTrue((-9007199254740992.0).truncate() is int);
Expect.isTrue((-double.MAX_FINITE).truncate() is int);
}

View file

@ -1,85 +0,0 @@
// Copyright (c) 2013, 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.
import 'package:expect/expect.dart';
main() {
Expect.equals(0.0, 0.0.truncateToDouble());
Expect.equals(0.0, double.MIN_POSITIVE.truncateToDouble());
Expect.equals(0.0, (2.0 * double.MIN_POSITIVE).truncateToDouble());
Expect.equals(0.0, (1.18e-38).truncateToDouble());
Expect.equals(0.0, (1.18e-38 * 2).truncateToDouble());
Expect.equals(0.0, 0.49999999999999994.truncateToDouble());
Expect.equals(0.0, 0.5.truncateToDouble());
Expect.equals(0.0, 0.9999999999999999.truncateToDouble());
Expect.equals(1.0, 1.0.truncateToDouble());
Expect.equals(1.0, 1.000000000000001.truncateToDouble());
// The following numbers are on the border of 52 bits.
// For example: 4503599627370499 + 0.5 => 4503599627370500.
Expect.equals(4503599627370496.0, 4503599627370496.0.truncateToDouble());
Expect.equals(4503599627370497.0, 4503599627370497.0.truncateToDouble());
Expect.equals(4503599627370498.0, 4503599627370498.0.truncateToDouble());
Expect.equals(4503599627370499.0, 4503599627370499.0.truncateToDouble());
Expect.equals(9007199254740991.0, 9007199254740991.0.truncateToDouble());
Expect.equals(9007199254740992.0, 9007199254740992.0.truncateToDouble());
Expect.equals(double.MAX_FINITE, double.MAX_FINITE.truncateToDouble());
Expect.equals(0.0, (-double.MIN_POSITIVE).truncateToDouble());
Expect.equals(0.0, (2.0 * -double.MIN_POSITIVE).truncateToDouble());
Expect.equals(0.0, (-1.18e-38).truncateToDouble());
Expect.equals(0.0, (-1.18e-38 * 2).truncateToDouble());
Expect.equals(0.0, (-0.49999999999999994).truncateToDouble());
Expect.equals(0.0, (-0.5).truncateToDouble());
Expect.equals(0.0, (-0.9999999999999999).truncateToDouble());
Expect.equals(-1.0, (-1.0).truncateToDouble());
Expect.equals(-1.0, (-1.000000000000001).truncateToDouble());
Expect.equals(-4503599627370496.0, (-4503599627370496.0).truncateToDouble());
Expect.equals(-4503599627370497.0, (-4503599627370497.0).truncateToDouble());
Expect.equals(-4503599627370498.0, (-4503599627370498.0).truncateToDouble());
Expect.equals(-4503599627370499.0, (-4503599627370499.0).truncateToDouble());
Expect.equals(-9007199254740991.0, (-9007199254740991.0).truncateToDouble());
Expect.equals(-9007199254740992.0, (-9007199254740992.0).truncateToDouble());
Expect.equals(-double.MAX_FINITE, (-double.MAX_FINITE).truncateToDouble());
Expect.equals(double.INFINITY, double.INFINITY.truncateToDouble());
Expect.equals(
double.NEGATIVE_INFINITY, double.NEGATIVE_INFINITY.truncateToDouble());
Expect.isTrue(double.NAN.truncateToDouble().isNaN);
Expect.isTrue(0.0.truncateToDouble() is double);
Expect.isTrue(double.MIN_POSITIVE.truncateToDouble() is double);
Expect.isTrue((2.0 * double.MIN_POSITIVE).truncateToDouble() is double);
Expect.isTrue((1.18e-38).truncateToDouble() is double);
Expect.isTrue((1.18e-38 * 2).truncateToDouble() is double);
Expect.isTrue(0.49999999999999994.truncateToDouble() is double);
Expect.isTrue(0.5.truncateToDouble() is double);
Expect.isTrue(0.9999999999999999.truncateToDouble() is double);
Expect.isTrue(1.0.truncateToDouble() is double);
Expect.isTrue(1.000000000000001.truncateToDouble() is double);
Expect.isTrue(4503599627370496.0.truncateToDouble() is double);
Expect.isTrue(4503599627370497.0.truncateToDouble() is double);
Expect.isTrue(4503599627370498.0.truncateToDouble() is double);
Expect.isTrue(4503599627370499.0.truncateToDouble() is double);
Expect.isTrue(9007199254740991.0.truncateToDouble() is double);
Expect.isTrue(9007199254740992.0.truncateToDouble() is double);
Expect.isTrue(double.MAX_FINITE.truncateToDouble() is double);
Expect.isTrue((-double.MIN_POSITIVE).truncateToDouble() is double);
Expect.isTrue((2.0 * -double.MIN_POSITIVE).truncateToDouble() is double);
Expect.isTrue((-1.18e-38).truncateToDouble() is double);
Expect.isTrue((-1.18e-38 * 2).truncateToDouble() is double);
Expect.isTrue((-0.49999999999999994).truncateToDouble() is double);
Expect.isTrue((-0.5).truncateToDouble() is double);
Expect.isTrue((-0.9999999999999999).truncateToDouble() is double);
Expect.isTrue((-1.0).truncateToDouble() is double);
Expect.isTrue((-1.000000000000001).truncateToDouble() is double);
Expect.isTrue((-4503599627370496.0).truncateToDouble() is double);
Expect.isTrue((-4503599627370497.0).truncateToDouble() is double);
Expect.isTrue((-4503599627370498.0).truncateToDouble() is double);
Expect.isTrue((-4503599627370499.0).truncateToDouble() is double);
Expect.isTrue((-9007199254740991.0).truncateToDouble() is double);
Expect.isTrue((-9007199254740992.0).truncateToDouble() is double);
Expect.isTrue((-double.MAX_FINITE).truncateToDouble() is double);
}

View file

@ -1,27 +0,0 @@
// Copyright (c) 2015, 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.
import "package:expect/expect.dart";
main() {
// If the duration class multiplies "str" * microseconds-per-day (instead of
// (microseconds-per-day * "str") it will try to build up a huge string and
// terminate with an out-of-memory exception instead of an ArgumentError or
// TypeError.
// See dartbug.com/22309
String longString = "str" * 1000;
Expect.throws(() => new Duration(days: longString),
(e) => e is ArgumentError || e is TypeError || e is NoSuchMethodError);
Expect.throws(() => new Duration(hours: longString),
(e) => e is ArgumentError || e is TypeError || e is NoSuchMethodError);
Expect.throws(() => new Duration(minutes: longString),
(e) => e is ArgumentError || e is TypeError || e is NoSuchMethodError);
Expect.throws(() => new Duration(seconds: longString),
(e) => e is ArgumentError || e is TypeError || e is NoSuchMethodError);
Expect.throws(() => new Duration(milliseconds: longString),
(e) => e is ArgumentError || e is TypeError || e is NoSuchMethodError);
Expect.throws(() => new Duration(microseconds: longString),
(e) => e is ArgumentError || e is TypeError || e is NoSuchMethodError);
}

View file

@ -1,21 +0,0 @@
// Copyright (c) 2013, 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.
import "package:expect/expect.dart";
import 'dart:math';
main() {
Duration d, d1;
d1 = new Duration(microseconds: pow(2, 53));
d = d1 * 2;
Expect.equals(pow(2, 54), d.inMicroseconds);
d = d1 * 1.5;
Expect.equals(pow(2, 53).toDouble() * 1.5, d.inMicroseconds);
Expect.isTrue(d.inMicroseconds is int);
// Test that we lose precision when multiplying with a double.
d = new Duration(microseconds: pow(2, 53) + 1) * 1.0;
Expect.equals(0, d.inMicroseconds % 2);
}

View file

@ -1,19 +0,0 @@
// Copyright (c) 2013, 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.
import "package:expect/expect.dart";
main() {
Duration d, d1;
d1 = new Duration(milliseconds: 1);
d = d1 * 0.005;
Expect.equals(1000 * 0.005, d.inMicroseconds);
d = d1 * 0.0;
Expect.equals(0, d.inMicroseconds);
d = d1 * -0.005;
Expect.equals(1000 * -0.005, d.inMicroseconds);
d = d1 * 0.0015;
Expect.equals((1000 * 0.0015).round(), d.inMicroseconds);
}

View file

@ -1,293 +0,0 @@
// Copyright (c) 2013, 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.
import "package:expect/expect.dart";
main() {
Duration d;
d = new Duration(days: 1);
Expect.equals(86400000000, d.inMicroseconds);
Expect.equals(86400000, d.inMilliseconds);
Expect.equals(86400, d.inSeconds);
Expect.equals(1440, d.inMinutes);
Expect.equals(24, d.inHours);
Expect.equals(1, d.inDays);
d = const Duration(hours: 1);
Expect.equals(3600000000, d.inMicroseconds);
Expect.equals(3600000, d.inMilliseconds);
Expect.equals(3600, d.inSeconds);
Expect.equals(60, d.inMinutes);
Expect.equals(1, d.inHours);
Expect.equals(0, d.inDays);
d = new Duration(minutes: 1);
Expect.equals(60000000, d.inMicroseconds);
Expect.equals(60000, d.inMilliseconds);
Expect.equals(60, d.inSeconds);
Expect.equals(1, d.inMinutes);
Expect.equals(0, d.inHours);
Expect.equals(0, d.inDays);
d = const Duration(seconds: 1);
Expect.equals(1000000, d.inMicroseconds);
Expect.equals(1000, d.inMilliseconds);
Expect.equals(1, d.inSeconds);
Expect.equals(0, d.inMinutes);
Expect.equals(0, d.inHours);
Expect.equals(0, d.inDays);
d = new Duration(milliseconds: 1);
Expect.equals(1000, d.inMicroseconds);
Expect.equals(1, d.inMilliseconds);
Expect.equals(0, d.inSeconds);
Expect.equals(0, d.inMinutes);
Expect.equals(0, d.inHours);
Expect.equals(0, d.inDays);
d = new Duration(microseconds: 1);
Expect.equals(1, d.inMicroseconds);
Expect.equals(0, d.inMilliseconds);
Expect.equals(0, d.inSeconds);
Expect.equals(0, d.inMinutes);
Expect.equals(0, d.inHours);
Expect.equals(0, d.inDays);
d = const Duration(milliseconds: 1, microseconds: 999);
Expect.equals(1999, d.inMicroseconds);
Expect.equals(1, d.inMilliseconds);
d = const Duration(seconds: 1, milliseconds: 999);
Expect.equals(1999, d.inMilliseconds);
Expect.equals(1, d.inSeconds);
d = new Duration(minutes: 1, seconds: 59);
Expect.equals(119, d.inSeconds);
Expect.equals(1, d.inMinutes);
d = const Duration(hours: 1, minutes: 59);
Expect.equals(119, d.inMinutes);
Expect.equals(1, d.inHours);
d = new Duration(days: 1, hours: 23);
Expect.equals(47, d.inHours);
Expect.equals(1, d.inDays);
d = const Duration(
days: 0,
hours: 23,
minutes: 59,
seconds: 59,
milliseconds: 999,
microseconds: 999);
Expect.equals(0, d.inDays);
d = new Duration(days: -1);
Expect.equals(-86400000000, d.inMicroseconds);
Expect.equals(-86400000, d.inMilliseconds);
Expect.equals(-86400, d.inSeconds);
Expect.equals(-1440, d.inMinutes);
Expect.equals(-24, d.inHours);
Expect.equals(-1, d.inDays);
d = const Duration(hours: -1);
Expect.equals(-3600000000, d.inMicroseconds);
Expect.equals(-3600000, d.inMilliseconds);
Expect.equals(-3600, d.inSeconds);
Expect.equals(-60, d.inMinutes);
Expect.equals(-1, d.inHours);
Expect.equals(0, d.inDays);
d = new Duration(minutes: -1);
Expect.equals(-60000000, d.inMicroseconds);
Expect.equals(-60000, d.inMilliseconds);
Expect.equals(-60, d.inSeconds);
Expect.equals(-1, d.inMinutes);
Expect.equals(0, d.inHours);
Expect.equals(0, d.inDays);
d = const Duration(seconds: -1);
Expect.equals(-1000000, d.inMicroseconds);
Expect.equals(-1000, d.inMilliseconds);
Expect.equals(-1, d.inSeconds);
Expect.equals(0, d.inMinutes);
Expect.equals(0, d.inHours);
Expect.equals(0, d.inDays);
d = new Duration(milliseconds: -1);
Expect.equals(-1000, d.inMicroseconds);
Expect.equals(-1, d.inMilliseconds);
Expect.equals(0, d.inSeconds);
Expect.equals(0, d.inMinutes);
Expect.equals(0, d.inHours);
Expect.equals(0, d.inDays);
d = new Duration(microseconds: -1);
Expect.equals(-1, d.inMicroseconds);
Expect.equals(0, d.inMilliseconds);
Expect.equals(0, d.inSeconds);
Expect.equals(0, d.inMinutes);
Expect.equals(0, d.inHours);
Expect.equals(0, d.inDays);
d = const Duration(days: 1, hours: -24);
Expect.equals(0, d.inMicroseconds);
d = new Duration(hours: 1, minutes: -60);
Expect.equals(0, d.inMicroseconds);
d = const Duration(minutes: 1, seconds: -60);
Expect.equals(0, d.inMicroseconds);
d = new Duration(seconds: 1, milliseconds: -1000);
Expect.equals(0, d.inMicroseconds);
d = new Duration(milliseconds: 1, microseconds: -1000);
Expect.equals(0, d.inMicroseconds);
d = const Duration(hours: 25);
Expect.equals(1, d.inDays);
Expect.equals(25, d.inHours);
Expect.equals(1500, d.inMinutes);
Expect.equals(90000, d.inSeconds);
Expect.equals(90000000, d.inMilliseconds);
Expect.equals(90000000000, d.inMicroseconds);
d = new Duration(minutes: 61);
Expect.equals(0, d.inDays);
Expect.equals(1, d.inHours);
Expect.equals(61, d.inMinutes);
Expect.equals(3660, d.inSeconds);
Expect.equals(3660000, d.inMilliseconds);
Expect.equals(3660000000, d.inMicroseconds);
d = const Duration(seconds: 61);
Expect.equals(0, d.inDays);
Expect.equals(0, d.inHours);
Expect.equals(1, d.inMinutes);
Expect.equals(61, d.inSeconds);
Expect.equals(61000, d.inMilliseconds);
Expect.equals(61000000, d.inMicroseconds);
d = new Duration(milliseconds: 1001);
Expect.equals(0, d.inDays);
Expect.equals(0, d.inHours);
Expect.equals(0, d.inMinutes);
Expect.equals(1, d.inSeconds);
Expect.equals(1001, d.inMilliseconds);
Expect.equals(1001000, d.inMicroseconds);
d = new Duration(microseconds: 1001);
Expect.equals(0, d.inDays);
Expect.equals(0, d.inHours);
Expect.equals(0, d.inMinutes);
Expect.equals(0, d.inSeconds);
Expect.equals(1, d.inMilliseconds);
Expect.equals(1001, d.inMicroseconds);
var d1 = const Duration(milliseconds: 1000);
var d2 = const Duration(seconds: 1);
Expect.identical(d1, d2);
d1 = const Duration(microseconds: 1000);
d2 = const Duration(milliseconds: 1);
Expect.identical(d1, d2);
d1 = new Duration(hours: 1);
d2 = new Duration(hours: -1);
d = d1 + d2;
Expect.equals(0, d.inMicroseconds);
d = d1 - d2;
Expect.equals(3600000000 * 2, d.inMicroseconds);
d2 = new Duration(hours: 1);
d = d1 + d2;
Expect.equals(3600000000 * 2, d.inMicroseconds);
d = d1 - d2;
Expect.equals(0, d.inMicroseconds);
d = d1 * 2;
Expect.equals(3600000000 * 2, d.inMicroseconds);
d = d1 * -1;
Expect.equals(-3600000000, d.inMicroseconds);
d = d1 * 0;
Expect.equals(0, d.inMicroseconds);
d = d1 ~/ 2;
Expect.equals(1800000000, d.inMicroseconds);
d = d1 ~/ 3600000001;
Expect.equals(0, d.inMicroseconds);
d = d1 ~/ -3600000001;
Expect.equals(0, d.inMicroseconds);
d = d1 ~/ 3599999999;
Expect.equals(1, d.inMicroseconds);
d = d1 ~/ -3599999999;
Expect.equals(-1, d.inMicroseconds);
d = d1 ~/ -1;
Expect.equals(-3600000000, d.inMicroseconds);
d = d1 * 0;
Expect.equals(0, d.inMicroseconds);
Expect.throws(() => d1 ~/ 0, (e) => e is IntegerDivisionByZeroException);
d = new Duration(microseconds: 0);
Expect.isTrue(d < new Duration(microseconds: 1));
Expect.isTrue(d <= new Duration(microseconds: 1));
Expect.isTrue(d <= d);
Expect.isTrue(d > new Duration(microseconds: -1));
Expect.isTrue(d >= new Duration(microseconds: -1));
Expect.isTrue(d >= d);
d = const Duration(
days: 1,
hours: 3,
minutes: 17,
seconds: 42,
milliseconds: 823,
microseconds: 127);
Expect.equals("27:17:42.823127", d.toString());
d = const Duration(hours: 1999, minutes: 17, seconds: 42);
Expect.equals("1999:17:42.000000", d.toString());
d = const Duration(
days: -1,
hours: -3,
minutes: -17,
seconds: -42,
milliseconds: -823,
microseconds: -127);
Expect.equals("-27:17:42.823127", d.toString());
d = const Duration(hours: -1999, minutes: -17, seconds: -42);
Expect.equals("-1999:17:42.000000", d.toString());
// Edge conditions for toString of microseconds.
// Regression test for http://dartbug.com/15678
d = const Duration(microseconds: 1);
Expect.equals("0:00:00.000001", d.toString());
d = const Duration(microseconds: 9);
Expect.equals("0:00:00.000009", d.toString());
d = const Duration(microseconds: 10);
Expect.equals("0:00:00.000010", d.toString());
d = const Duration(microseconds: 99);
Expect.equals("0:00:00.000099", d.toString());
d = const Duration(microseconds: 100);
Expect.equals("0:00:00.000100", d.toString());
d = const Duration(microseconds: 999);
Expect.equals("0:00:00.000999", d.toString());
d = const Duration(microseconds: 1000);
Expect.equals("0:00:00.001000", d.toString());
d = const Duration(microseconds: 9999);
Expect.equals("0:00:00.009999", d.toString());
d = const Duration(microseconds: 10000);
Expect.equals("0:00:00.010000", d.toString());
d = const Duration(microseconds: 99999);
Expect.equals("0:00:00.099999", d.toString());
d = const Duration(microseconds: 100000);
Expect.equals("0:00:00.100000", d.toString());
d = const Duration(microseconds: 999999);
Expect.equals("0:00:00.999999", d.toString());
d = const Duration(microseconds: 1000000);
Expect.equals("0:00:01.000000", d.toString());
d1 = const Duration(hours: 1);
d2 = const Duration(hours: -1);
Expect.isFalse(d1.isNegative);
Expect.isTrue(d2.isNegative);
Expect.equals(d1, d1.abs());
Expect.equals(d1, d2.abs());
Expect.equals(d2, -d1);
Expect.equals(d1, -d2);
}

View file

@ -1,40 +0,0 @@
// Copyright (c) 2013, 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.
import "package:expect/expect.dart";
class A {
static Aa() => Ab();
static Ab() => Ac();
static Ac() => throw "abc";
}
class B {
static Ba() => Bb();
static Bb() => Bc();
static Bc() {
try {
A.Aa();
} catch (e) {
// This should produce a NoSuchMethodError.
var trace = e.stackTrace;
}
}
}
main() {
bool hasThrown = false;
try {
B.Ba();
} catch (e) {
hasThrown = true;
var trace = e.stackTrace.toString();
print(trace);
Expect.isTrue(trace.contains("Bc"));
Expect.isTrue(trace.contains("Bb"));
Expect.isTrue(trace.contains("Ba"));
Expect.isTrue(trace.contains("main"));
}
Expect.isTrue(hasThrown);
}