Migrate test block 10 to Dart 2.0.

Special bits in this block:

int_parse_radix_test: Converted to a check only on TypeError (since this is raised at runtime based on user data)
iterable_element_at_test.dart: Split into multitest with compile errors.
iterable_fold_test.dart: add4 and a couple of other cases here cause problems for some compilers, split out into multitests and annotated in
status file.

BUG=
R=bkonyi@google.com

Review-Url: https://codereview.chromium.org/2997533002 .
This commit is contained in:
Janice Collins 2017-08-09 08:47:42 -07:00
parent db092ff2fc
commit e6b3fb5b05
41 changed files with 194 additions and 1217 deletions

View file

@ -9,16 +9,12 @@
string_case_test/01: Fail # Bug 18061
[ $compiler == dart2js && ! $dart2js_with_kernel ]
int_parse_radix_test/01: Pass, Fail # JS implementations disagree on U+0085 being whitespace.
int_parse_radix_test/02: Fail # No bigints.
integer_to_radix_string_test: RuntimeError # issue 22045
[ $runtime == safari || $runtime == safarimobilesim ]
string_trimlr_test/02: RuntimeError # Uses Unicode 6.2.0 or earlier.
[ $compiler == dart2js && ! $dart2js_with_kernel ]
error_stack_trace1_test: RuntimeError # Issue 12399
integer_to_string_test/01: RuntimeError # Issue 1533
iterable_return_type_test/01: RuntimeError # Issue 20085
iterable_return_type_test/02: RuntimeError # Dart2js does not support Uint64*.
@ -30,9 +26,7 @@ regress_r21715_test: RuntimeError # Requires bigint support.
*: Fail, Pass # TODO(ahe): Triage these tests.
[ $compiler == dart2analyzer ]
int_parse_radix_bad_handler_test: fail
error_stack_trace_test: StaticWarning, OK # Test generates errors on purpose.
iterable_element_at_test: StaticWarning, OK # Test generates errors on purpose.
string_test: StaticWarning, OK # Test generates error on purpose.
duration2_test: StaticWarning, OK # Test generates error on purpose.
@ -55,10 +49,8 @@ http_resource_test: Skip, OK # VM specific test, uses dart:io.
[ $mode == debug ]
[ ($runtime == vm || $runtime == dart_precompiled) && $arch == simarmv5te ]
int_parse_radix_test/*: Pass, Slow
[ $compiler == precompiler ]
int_parse_radix_test: Pass, Timeout # --no_intrinsify
[ $compiler == precompiler || $compiler == app_jit ]
file_resource_test: Skip # Resolve URI not supported yet in product mode.
@ -108,21 +100,6 @@ for_in_test: Crash
growable_list_test: Crash
has_next_iterator_test: Crash
hash_map2_test: Crash
int_parse_radix_bad_handler_test: Crash
int_parse_radix_test/01: Crash
int_parse_radix_test/02: Crash
int_parse_radix_test/none: Crash
integer_to_radix_string_test: Crash
integer_to_string_test/01: RuntimeError
is_operator_basic_types_test: Crash
iterable_contains2_test: Crash
iterable_contains_test: Crash
iterable_element_at_test: Crash
iterable_empty_test: Crash
iterable_expand_test: Crash
iterable_first_test: Crash
iterable_first_where_test: Crash
iterable_fold_test: Crash
iterable_generate_test/01: Crash
iterable_generate_test/none: Crash
iterable_join_test: Crash

View file

@ -1,15 +0,0 @@
// Copyright (c) 2012, 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 main() {
// If handleError isn't an unary function, and it's called, it also throws
// (either TypeError in checked mode, or some failure in unchecked mode).
// These are compile time errors for strong mode.
Expect.throws(() => int.parse("9", radix: 8, onError: "not a function"));
Expect.throws(() => int.parse("9", radix: 8, onError: () => 42));
Expect.throws(() => int.parse("9", radix: 8, onError: (v1, v2) => 42));
}

View file

@ -1,42 +0,0 @@
// Copyright (c) 2012, 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() {
List<int> list1 = <int>[1, 2, 3];
List<int> list2 = const <int>[4, 5, 6];
List<String> list3 = <String>[];
Set<int> set1 = new Set<int>();
set1..add(11)..add(12)..add(13);
Set set2 = new Set();
Expect.equals(1, list1.elementAt(0));
Expect.equals(2, list1.elementAt(1));
Expect.equals(3, list1.elementAt(2));
Expect.throws(
() => list1.elementAt("2"), (e) => e is ArgumentError || e is TypeError);
Expect.throws(() => list1.elementAt(-1), (e) => e is ArgumentError);
Expect.throws(() => list1.elementAt(3), (e) => e is RangeError);
Expect.equals(4, list2.elementAt(0));
Expect.equals(5, list2.elementAt(1));
Expect.equals(6, list2.elementAt(2));
Expect.throws(
() => list2.elementAt("2"), (e) => e is ArgumentError || e is TypeError);
Expect.throws(() => list2.elementAt(-1), (e) => e is ArgumentError);
Expect.throws(() => list2.elementAt(3), (e) => e is RangeError);
Expect.isTrue(set1.contains(set1.elementAt(0)));
Expect.isTrue(set1.contains(set1.elementAt(1)));
Expect.isTrue(set1.contains(set1.elementAt(2)));
Expect.throws(() => set1.elementAt(-1), (e) => e is ArgumentError);
Expect.throws(() => set1.elementAt(3), (e) => e is RangeError);
Expect.throws(
() => set2.elementAt("2"), (e) => e is ArgumentError || e is TypeError);
Expect.throws(() => set2.elementAt(-1), (e) => e is ArgumentError);
Expect.throws(() => set2.elementAt(0), (e) => e is RangeError);
Expect.throws(() => set2.elementAt(1), (e) => e is RangeError);
}

View file

@ -1,71 +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() {
testEmpty(name, it, [depth = 2]) {
Expect.isTrue(it.isEmpty, name);
Expect.isFalse(it.isNotEmpty, name);
Expect.equals(0, it.length, name);
Expect.isFalse(it.contains(null), name);
Expect.isFalse(it.any((x) => true), name);
Expect.isTrue(it.every((x) => false), name);
Expect.throws(() => it.first, (e) => e is StateError, name);
Expect.throws(() => it.last, (e) => e is StateError, name);
Expect.throws(() => it.single, (e) => e is StateError, name);
Expect.throws(() => it.elementAt(0), (e) => e is RangeError, name);
Expect.throws(() => it.reduce((a, b) => a), (e) => e is StateError, name);
Expect.throws(
() => it.singleWhere((_) => true), (e) => e is StateError, name);
Expect.equals(42, it.fold(42, (a, b) => "not 42"), name);
Expect.equals(42, it.firstWhere((v) => true, orElse: () => 42), name);
Expect.equals(42, it.lastWhere((v) => true, orElse: () => 42), name);
Expect.equals("", it.join("separator"), name);
Expect.equals("()", it.toString(), name);
Expect.listEquals([], it.toList(), name);
Expect.listEquals([], it.toList(growable: false), name);
Expect.listEquals([], it.toList(growable: true), name);
Expect.equals(0, it.toSet().length, name);
// Doesn't throw:
it.forEach((v) => throw v);
for (var v in it) {
throw v;
}
// Check that returned iterables are also empty.
if (depth > 0) {
testEmpty("$name-map", it.map((x) => x), depth - 1);
testEmpty("$name-where", it.where((x) => true), depth - 1);
testEmpty("$name-expand", it.expand((x) => [x]), depth - 1);
testEmpty("$name-skip", it.skip(1), depth - 1);
testEmpty("$name-take", it.take(2), depth - 1);
testEmpty("$name-skipWhile", it.skipWhile((v) => false), depth - 1);
testEmpty("$name-takeWhile", it.takeWhile((v) => true), depth - 1);
}
}
testType(name, it, [depth = 2]) {
Expect.isTrue(it is Iterable<int>, name);
Expect.isFalse(it is Iterable<String>, name);
if (depth > 0) {
testType("$name-where", it.where((_) => true), depth - 1);
testType("$name-skip", it.skip(1), depth - 1);
testType("$name-take", it.take(1), depth - 1);
testType("$name-skipWhile", it.skipWhile((_) => false), depth - 1);
testType("$name-takeWhile", it.takeWhile((_) => true), depth - 1);
testType("$name-toList", it.toList(), depth - 1);
testType("$name-toList", it.toList(growable: false), depth - 1);
testType("$name-toList", it.toList(growable: true), depth - 1);
testType("$name-toSet", it.toSet(), depth - 1);
}
}
test(name, it) {
testEmpty(name, it);
testType(name, it);
}
test("const", const Iterable<int>.empty());
test("new", new Iterable<int>.empty());
}

View file

@ -19,6 +19,9 @@ string_base_vm_static_test: MissingCompileTimeError
string_replace_static_test: MissingCompileTimeError
string_static_test: MissingCompileTimeError
[ (!$checked && $runtime == vm) || $compiler == dart2js || $compiler == precompiler ]
int_parse_radix_test/badTypes: RuntimeError # wrong exception returned
[ !$strong && !$checked ]
core_runtime_types_static_test: MissingCompileTimeError
splay_tree_test/01: MissingCompileTimeError
@ -27,6 +30,9 @@ string_base_vm_static_test: MissingCompileTimeError
string_replace_static_test: MissingCompileTimeError
string_static_test: MissingCompileTimeError
[ $runtime == vm || $compiler == precompiler || $compiler == dart2js ]
int_parse_radix_bad_handler_test: MissingCompileTimeError
[ $compiler == dart2analyzer && !$strong ]
symbol_reserved_word_test/05: MissingCompileTimeError # Issue 30245
@ -65,6 +71,7 @@ apply3_test: SkipByDesign
dynamic_nosuchmethod_test: SkipByDesign
big_integer_huge_mul_vm_test: Pass, Timeout # --no_intrinsify
regexp/stack-overflow_test: RuntimeError, OK # Smaller limit with irregex interpreter
int_parse_radix_test: Pass, Timeout # --no_intrinsify
[ $compiler == dart2js && $runtime != none && !$checked ]
growable_list_test: RuntimeError # Concurrent modifications test always runs
@ -163,13 +170,17 @@ typed_data_with_limited_ints_test: Skip # dart2js and dartdevc don't know about
[ $compiler == dart2js && $runtime != none ]
nan_infinity_test/01: RuntimeError
integer_to_string_test/01: RuntimeError
iterable_to_set_test: RuntimeError # is-checks do not implement strong mode type system
int_parse_radix_test/01: RuntimeError
int_parse_radix_test/02: RuntimeError
[ $compiler == dart2js && $runtime == drt && $csp && $minified ]
core_runtime_types_test: Pass, Fail # Issue 27913
[ $compiler != dartdevc ]
error_stack_trace_test/static: MissingCompileTimeError
iterable_element_at_test/static: MissingCompileTimeError
[ $compiler == dartdevc && $runtime != none ]
error_stack_trace_test/nullThrown: RuntimeError # .stackTrace not present for exception caught from 'throw null;'
@ -182,6 +193,12 @@ json_map_test: RuntimeError # Issue 29921
core_runtime_types_test: RuntimeError # Issue 29921 - runtime cast failure
string_fromcharcodes_test: RuntimeError # Issue 29921 - runtime cast failure
uri_query_test: RuntimeError # Issue 29921 - runtime cast failure
int_parse_radix_test/01: RuntimeError # Issue 29921
int_parse_radix_test/02: RuntimeError # Issue 29921
integer_to_radix_string_test: RuntimeError # Issue 29921
integer_to_string_test/01: RuntimeError # Issue 29921
iterable_fold_test/01: CompileTimeError # type inference problem
iterable_fold_test/02: RuntimeError # different type inference problem
[ $runtime == flutter ]
apply3_test: CompileTimeError # mirrors not supported
@ -292,6 +309,7 @@ unicode_test: Fail
[ ($runtime == vm || $runtime == dart_precompiled) && $arch == simarmv5te ]
big_integer_parsed_mul_div_vm_test: Pass, SloW
int_parse_radix_test/*: Pass, Slow
[ $compiler == precompiler ]
big_integer_parsed_mul_div_vm_test: Pass, Timeout # --no_intrinsify
@ -315,6 +333,7 @@ symbol_reserved_word_test/10: MissingCompileTimeError # Issue 11669, 19972
[ $compiler == dart2js ]
hash_set_test/01: RuntimeError # Issue 11551
integer_to_radix_string_test: RuntimeError # Issue 29921
string_static_test: MissingCompileTimeError
[ ($compiler == none || $compiler == precompiler || $compiler == app_jit) && $runtime != drt ]
@ -669,6 +688,30 @@ uri_path_test: Crash
uri_query_test: Crash
uri_scheme_test: Crash
uri_test: Crash
iterable_skip_while_test: Crash
iterable_take_test: Crash
iterable_take_while_test: Crash
iterable_test: Crash
iterable_to_list_test/01: Crash
iterable_to_list_test/none: Crash
iterable_to_set_test: Crash
iterable_tostring_test: Crash
json_map_test: Crash
int_parse_radix_bad_handler_test: Crash
int_parse_radix_test/01: Crash
int_parse_radix_test/02: Crash
int_parse_radix_test/none: Crash
integer_to_string_test/01: Crash
integer_to_string_test/none: Crash
is_operator_basic_types_test: Crash
iterable_contains2_test: Crash
iterable_contains_test: Crash
iterable_element_at_test: Crash
iterable_empty_test: Crash
iterable_expand_test: Crash
iterable_first_test: Crash
iterable_first_where_test: Crash
iterable_fold_test: Crash
[ $compiler == dart2js && $dart2js_with_kernel && $host_checked ]
stopwatch_test: Crash
@ -946,6 +989,11 @@ uri_path_test: Crash
uri_query_test: Crash
uri_scheme_test: Crash
uri_test: Crash
int_round_test: Crash
int_round_to_double_test: Crash
int_to_int_test: Crash
int_truncate_test: Crash
int_truncate_to_double_test: Crash
[$arch == simdbc || $arch == simdbc64]
regexp/stack-overflow_test: RuntimeError, OK # Smaller limit with irregex interpreter
@ -972,3 +1020,16 @@ package_resource_test: RuntimeError # Issue 26842
[ $compiler == dart2js && ! $dart2js_with_kernel ]
list_unmodifiable_test: Pass, RuntimeError # Issue 28712
iterable_to_list_test/01: RuntimeError # Issue 26501
[ $compiler == dart2analyzer ]
int_parse_radix_bad_handler_test: MissingCompileTimeError
iterable_element_at_test/static: Pass
[ $compiler == dart2analyzer && $strong ]
int_parse_radix_bad_handler_test: Pass
[ $compiler == dart2analyzer && $strong && $checked ]
iterable_fold_test/01: CompileTimeError
[ $compiler == dart2analyzer && $checked && !$strong ]
iterable_fold_test/01: Pass

View file

@ -0,0 +1,12 @@
// 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.ceil(), (e) => e is UnsupportedError);
Expect.throws(
() => double.NEGATIVE_INFINITY.ceil(), (e) => e is UnsupportedError);
Expect.throws(() => double.NAN.ceil(), (e) => e is UnsupportedError);
}

View file

@ -0,0 +1,77 @@
// 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";
// Test that error constructors do what they are documented as doing.
main() {
Expect.equals("Invalid argument(s)", new ArgumentError().toString());
Expect.equals(
"Invalid argument(s): message", new ArgumentError("message").toString());
Expect.equals(
"Invalid argument: null", new ArgumentError.value(null).toString());
Expect.equals("Invalid argument: 42", new ArgumentError.value(42).toString());
Expect.equals(
"Invalid argument: \"bad\"", new ArgumentError.value("bad").toString());
Expect.equals("Invalid argument (foo): null",
new ArgumentError.value(null, "foo").toString());
Expect.equals("Invalid argument (foo): 42",
new ArgumentError.value(42, "foo").toString());
Expect.equals("Invalid argument (foo): message: 42",
new ArgumentError.value(42, "foo", "message").toString());
Expect.equals("Invalid argument: message: 42",
new ArgumentError.value(42, null, "message").toString());
Expect.equals("Invalid argument(s): Must not be null",
new ArgumentError.notNull().toString());
Expect.equals("Invalid argument(s) (foo): Must not be null",
new ArgumentError.notNull("foo").toString());
Expect.equals("RangeError", new RangeError(null).toString());
Expect.equals("RangeError: message", new RangeError("message").toString());
Expect.equals("RangeError: Value not in range: 42",
new RangeError.value(42).toString());
Expect.equals("RangeError (foo): Value not in range: 42",
new RangeError.value(42, "foo").toString());
Expect.equals("RangeError (foo): message: 42",
new RangeError.value(42, "foo", "message").toString());
Expect.equals("RangeError: message: 42",
new RangeError.value(42, null, "message").toString());
Expect.equals("RangeError: Invalid value: Not in range 2..9, inclusive: 42",
new RangeError.range(42, 2, 9).toString());
Expect.equals(
"RangeError (foo): Invalid value: Not in range 2..9, "
"inclusive: 42",
new RangeError.range(42, 2, 9, "foo").toString());
Expect.equals("RangeError (foo): message: Not in range 2..9, inclusive: 42",
new RangeError.range(42, 2, 9, "foo", "message").toString());
Expect.equals("RangeError: message: Not in range 2..9, inclusive: 42",
new RangeError.range(42, 2, 9, null, "message").toString());
Expect.equals(
"RangeError: Index out of range: "
"index should be less than 3: 42",
new RangeError.index(42, [1, 2, 3]).toString());
Expect.equals(
"RangeError (foo): Index out of range: "
"index should be less than 3: 42",
new RangeError.index(42, [1, 2, 3], "foo").toString());
Expect.equals(
"RangeError (foo): message: "
"index should be less than 3: 42",
new RangeError.index(42, [1, 2, 3], "foo", "message").toString());
Expect.equals(
"RangeError: message: "
"index should be less than 3: 42",
new RangeError.index(42, [1, 2, 3], null, "message").toString());
Expect.equals(
"RangeError (foo): message: "
"index should be less than 2: 42",
new RangeError.index(42, [1, 2, 3], "foo", "message", 2).toString());
Expect.equals(
"RangeError: Index out of range: "
"index must not be negative: -5",
new RangeError.index(-5, [1, 2, 3]).toString());
}

View file

@ -0,0 +1,12 @@
// Copyright (c) 2012, 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 main() {
// These are compile time errors for Dart 2.0.
Expect.throws(() => int.parse("9", radix: 8, /*@compile-error=unspecified*/ onError: "not a function"));
Expect.throws(() => int.parse("9", radix: 8, /*@compile-error=unspecified*/ onError: () => 42));
Expect.throws(() => int.parse("9", radix: 8, /*@compile-error=unspecified*/ onError: (v1, v2) => 42));
}

View file

@ -7,7 +7,7 @@ import "dart:math" show pow;
void main() {
const String oneByteWhiteSpace = "\x09\x0a\x0b\x0c\x0d\x20"
"\x85" // //# 01: ok
"\x85" //# 01: ok
"\xa0";
const String whiteSpace = "$oneByteWhiteSpace\u1680"
"\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a"
@ -114,15 +114,8 @@ void main() {
}
testBadTypes(var source, var radix) {
if (!typeAssertionsEnabled) {
// No promises on what error is thrown if the type doesn't match.
// Likely either ArgumentError or NoSuchMethodError.
Expect.throws(() => int.parse(source, radix: radix, onError: (s) => 0));
return;
}
// With type assertions enabled we can be more precise.
Expect.throws(() => int.parse(source, radix: radix, onError: (s) => 0),
(e) => e is TypeError || e is CastError);
Expect.throws(() => int.parse(source, radix: radix, onError: (s) => 0), //# badTypes: ok
(e) => e is TypeError); //# badTypes: ok
}
testBadTypes(9, 10);

View file

@ -15,16 +15,14 @@ main() {
Expect.equals(1, list1.elementAt(0));
Expect.equals(2, list1.elementAt(1));
Expect.equals(3, list1.elementAt(2));
Expect.throws(
() => list1.elementAt("2"), (e) => e is ArgumentError || e is TypeError);
list1.elementAt("2"); //# static: compile-time error
Expect.throws(() => list1.elementAt(-1), (e) => e is ArgumentError);
Expect.throws(() => list1.elementAt(3), (e) => e is RangeError);
Expect.equals(4, list2.elementAt(0));
Expect.equals(5, list2.elementAt(1));
Expect.equals(6, list2.elementAt(2));
Expect.throws(
() => list2.elementAt("2"), (e) => e is ArgumentError || e is TypeError);
list2.elementAt("2"); //# static: compile-time error
Expect.throws(() => list2.elementAt(-1), (e) => e is ArgumentError);
Expect.throws(() => list2.elementAt(3), (e) => e is RangeError);
@ -34,8 +32,7 @@ main() {
Expect.throws(() => set1.elementAt(-1), (e) => e is ArgumentError);
Expect.throws(() => set1.elementAt(3), (e) => e is RangeError);
Expect.throws(
() => set2.elementAt("2"), (e) => e is ArgumentError || e is TypeError);
set2.elementAt("2"); //# static: compile-time error
Expect.throws(() => set2.elementAt(-1), (e) => e is ArgumentError);
Expect.throws(() => set2.elementAt(0), (e) => e is RangeError);
Expect.throws(() => set2.elementAt(1), (e) => e is RangeError);

View file

@ -19,10 +19,10 @@ class MyList extends ListBase {
operator []=(index, val) => list[index] = val;
}
id(x) => x;
id (x) => x;
main() {
for (var iterable in [
for (dynamic iterable in [
const [1, 2, 3],
[1, 2, 3],
new List(3)
@ -35,10 +35,10 @@ main() {
new List.generate(3, (x) => x + 1),
[0, 1, 2, 3].where((x) => x > 0),
[0, 1, 2].map((x) => x + 1),
[
[1, 2],
[3]
].expand(id),
[ //# 01: ok
[1, 2], //# 01: ok
[3] //# 01: ok
].expand(id), //# 01: ok
[3, 2, 1].reversed,
[0, 1, 2, 3].skip(1),
[1, 2, 3, 4].take(3),
@ -93,7 +93,7 @@ main() {
new List.generate(0, (x) => x + 1),
[0, 1, 2, 3].where((x) => false),
[].map((x) => x + 1),
[[], []].expand(id),
[[], []].expand(id), //# 01: ok
[].reversed,
[0, 1, 2, 3].skip(4),
[1, 2, 3, 4].take(0),
@ -113,7 +113,7 @@ main() {
}
// Singleton iterables are calling reduce function.
for (var iterable in [
for (dynamic iterable in [
const [1],
[1],
new List(1)..[0] = 1,
@ -123,18 +123,18 @@ main() {
new List.generate(1, (x) => x + 1),
[0, 1, 2, 3].where((x) => x == 1),
[0].map((x) => x + 1),
[
[],
[1]
].expand(id),
[ //# 01: ok
[], //# 01: ok
[1] //# 01: ok
].expand(id), //# 01: ok
[1].reversed,
[0, 1].skip(1),
[1, 2, 3, 4].take(1),
new Uint8List(1)..[0] = 1,
(new HashMap()..[1] = 0).keys,
(new HashMap()..[0] = 1).values,
(new HashMap()..[0] = 1).values, //# 02: ok
(new SplayTreeMap()..[1] = 0).keys,
(new SplayTreeMap()..[0] = 1).values,
(new SplayTreeMap()..[0] = 1).values, //# 02: ok
new HashSet()..add(1),
new LinkedHashSet()..add(1),
new SplayTreeSet()..add(1),
@ -164,19 +164,19 @@ main() {
map[4] = 4;
}
testModification([1, 2, 3], add4, id);
testModification(new HashSet()..add(1)..add(2)..add(3), add4, id);
testModification(new LinkedHashSet()..add(1)..add(2)..add(3), add4, id);
testModification(new SplayTreeSet()..add(1)..add(2)..add(3), add4, id);
testModification(new MyList([1, 2, 3]), add4, id);
testModification([1, 2, 3], add4, id); //# 02: ok
testModification(new HashSet()..add(1)..add(2)..add(3), add4, id); //# 02: ok
testModification(new LinkedHashSet()..add(1)..add(2)..add(3), add4, id); //# 02: ok
testModification(new SplayTreeSet()..add(1)..add(2)..add(3), add4, id); //# 02: ok
testModification(new MyList([1, 2, 3]), add4, id); //# 02: ok
testModification([0, 1, 2, 3], add4, (x) => x.where((x) => x > 0));
testModification([0, 1, 2], add4, (x) => x.map((x) => x + 1));
testModification([
[1, 2],
[3]
], add4, (x) => x.expand((x) => x));
testModification([3, 2, 1], add4, (x) => x.reversed);
testModification([0, 1, 2, 3], add4, (x) => x.where((x) => x > 0)); //# 02: ok
testModification([0, 1, 2], add4, (x) => x.map((x) => x + 1)); //# 02: ok
testModification([ //# 02: ok
[1, 2], //# 02: ok
[3] //# 02: ok
], add4, (x) => x.expand((x) => x)); //# 02: ok
testModification([3, 2, 1], add4, (x) => x.reversed); //# 02: ok
testModification({1: 1, 2: 2, 3: 3}, put4, (x) => x.keys);
testModification({1: 1, 2: 2, 3: 3}, put4, (x) => x.values);
var hashMap = new HashMap()

View file

@ -11,9 +11,6 @@
duration2_test: Skip
error_stack_trace_test: Skip
http_resource_test: Skip
iterable_contains2_test: Skip
iterable_element_at_test: Skip
iterable_fold_test: Skip
iterable_mapping_test: Skip
iterable_reduce_test: Skip
linked_hash_map_from_iterable_test: Skip
@ -23,14 +20,9 @@ string_replace_test: Skip
[ $compiler == dartdevc && $runtime != none ]
hash_set_test/01: RuntimeError # Issue 29921
int_parse_radix_test/01: RuntimeError # Issue 29921
int_parse_radix_test/02: RuntimeError # Issue 29921
integer_to_radix_string_test: RuntimeError # Issue 29921
integer_to_string_test/01: RuntimeError # Issue 29921
iterable_return_type_test/02: RuntimeError # Issue 29921
regress_r21715_test: RuntimeError # Issue 29921
string_operations_with_null_test: RuntimeError # Issue 29921
from_environment_const_type_test/01: RuntimeError # Issue 29921
from_environment_const_type_test/05: RuntimeError # Issue 29921
from_environment_const_type_test/10: RuntimeError # Issue 29921

View file

@ -1,149 +0,0 @@
// Copyright (c) 2012, 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" show pow;
void main() {
bool checkedMode = false;
assert((checkedMode = true));
const String oneByteWhiteSpace = "\x09\x0a\x0b\x0c\x0d\x20"
"\x85" //# 01: ok
"\xa0";
const String whiteSpace = "$oneByteWhiteSpace\u1680"
"\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a"
"\u2028\u2029\u202f\u205f\u3000\ufeff";
var digits = "0123456789abcdefghijklmnopqrstuvwxyz";
var zeros = "0" * 64;
for (int i = 0; i < whiteSpace.length; i++) {
var ws = whiteSpace[i];
Expect.equals(0, int.parse("${ws}0${ws}", radix: 2));
}
void testParse(int result, String radixString, int radix) {
var m = "$radixString/$radix->$result";
Expect.equals(
result, int.parse(radixString.toLowerCase(), radix: radix), m);
Expect.equals(
result, int.parse(radixString.toUpperCase(), radix: radix), m);
Expect.equals(result, int.parse(" $radixString", radix: radix), m);
Expect.equals(result, int.parse("$radixString ", radix: radix), m);
Expect.equals(result, int.parse(" $radixString ", radix: radix), m);
Expect.equals(result, int.parse("+$radixString", radix: radix), m);
Expect.equals(result, int.parse(" +$radixString", radix: radix), m);
Expect.equals(result, int.parse("+$radixString ", radix: radix), m);
Expect.equals(result, int.parse(" +$radixString ", radix: radix), m);
Expect.equals(-result, int.parse("-$radixString", radix: radix), m);
Expect.equals(-result, int.parse(" -$radixString", radix: radix), m);
Expect.equals(-result, int.parse("-$radixString ", radix: radix), m);
Expect.equals(-result, int.parse(" -$radixString ", radix: radix), m);
Expect.equals(
result,
int.parse("$oneByteWhiteSpace$radixString$oneByteWhiteSpace",
radix: radix),
m);
Expect.equals(
-result,
int.parse("$oneByteWhiteSpace-$radixString$oneByteWhiteSpace",
radix: radix),
m);
Expect.equals(result,
int.parse("$whiteSpace$radixString$whiteSpace", radix: radix), m);
Expect.equals(-result,
int.parse("$whiteSpace-$radixString$whiteSpace", radix: radix), m);
Expect.equals(result, int.parse("$zeros$radixString", radix: radix), m);
Expect.equals(result, int.parse("+$zeros$radixString", radix: radix), m);
Expect.equals(-result, int.parse("-$zeros$radixString", radix: radix), m);
}
for (int r = 2; r <= 36; r++) {
for (int i = 0; i <= r * r; i++) {
String radixString = i.toRadixString(r);
testParse(i, radixString, r);
}
}
for (int i = 2; i <= 36; i++) { // //# 02: ok
// Test with bignums. // //# 02: continued
var digit = digits[i - 1]; // //# 02: continued
testParse(pow(i, 64) - 1, digit * 64, i); // //# 02: continued
testParse(0, zeros, i); // //# 02: continued
} // //# 02: continued
// Allow both upper- and lower-case letters.
Expect.equals(0xABCD, int.parse("ABCD", radix: 16));
Expect.equals(0xABCD, int.parse("abcd", radix: 16));
Expect.equals(15628859, int.parse("09azAZ", radix: 36));
// Big number.
Expect.equals(0x12345678123456781234567812345678, // //# 02: continued
int.parse("0x1234567812345678" // //# 02: continued
"1234567812345678")); // //# 02: continued
// Allow whitespace before and after the number.
Expect.equals(1, int.parse(" 1", radix: 2));
Expect.equals(1, int.parse("1 ", radix: 2));
Expect.equals(1, int.parse(" 1 ", radix: 2));
Expect.equals(1, int.parse("\n1", radix: 2));
Expect.equals(1, int.parse("1\n", radix: 2));
Expect.equals(1, int.parse("\n1\n", radix: 2));
Expect.equals(1, int.parse("+1", radix: 2));
void testFails(String source, int radix) {
Expect.throws(() {
throw int.parse(source, radix: radix, onError: (s) {
throw "FAIL";
});
}, isFail, "$source/$radix");
Expect.equals(-999, int.parse(source, radix: radix, onError: (s) => -999));
}
for (int i = 2; i < 36; i++) {
var char = i.toRadixString(36);
testFails(char.toLowerCase(), i);
testFails(char.toUpperCase(), i);
}
testFails("", 2);
testFails("+ 1", 2); // No space between sign and digits.
testFails("- 1", 2); // No space between sign and digits.
testFails("0x", null);
for (int i = 2; i <= 33; i++) {
// No 0x specially allowed.
// At radix 34 and above, "x" is a valid digit.
testFails("0x10", i);
}
testBadTypes(var source, var radix) {
if (!checkedMode) {
// No promises on what error is thrown if the type doesn't match.
// Likely either ArgumentError or NoSuchMethodError.
Expect.throws(() => int.parse(source, radix: radix, onError: (s) => 0));
return;
}
// In checked mode, it's always a TypeError.
Expect.throws(() => int.parse(source, radix: radix, onError: (s) => 0),
(e) => e is TypeError || e is CastError);
}
testBadTypes(9, 10);
testBadTypes(true, 10);
testBadTypes("0", true);
testBadTypes("0", "10");
testBadArguments(String source, int radix) {
// If the types match, it should be an ArgumentError of some sort.
Expect.throws(() => int.parse(source, radix: radix, onError: (s) => 0),
(e) => e is ArgumentError);
}
testBadArguments("0", -1);
testBadArguments("0", 0);
testBadArguments("0", 1);
testBadArguments("0", 37);
// See also int_parse_radix_bad_handler_test.dart
}
bool isFail(e) => e == "FAIL";

View file

@ -1,39 +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.round());
Expect.equals(1, 1.round());
Expect.equals(0x1234, 0x1234.round());
Expect.equals(0x12345678, 0x12345678.round());
Expect.equals(0x123456789AB, 0x123456789AB.round());
Expect.equals(0x123456789ABCDEF, 0x123456789ABCDEF.round());
Expect.equals(0x123456789ABCDEF0123456789ABCDEF0123456789ABCDEF,
0x123456789ABCDEF0123456789ABCDEF0123456789ABCDEF.round());
Expect.equals(-1, -1.round());
Expect.equals(-0x1234, -0x1234.round());
Expect.equals(-0x12345678, -0x12345678.round());
Expect.equals(-0x123456789AB, -0x123456789AB.round());
Expect.equals(-0x123456789ABCDEF, -0x123456789ABCDEF.round());
Expect.equals(-0x123456789ABCDEF0123456789ABCDEF0123456789ABCDEF,
-0x123456789ABCDEF0123456789ABCDEF0123456789ABCDEF.round());
Expect.isTrue(0.round() is int);
Expect.isTrue(1.round() is int);
Expect.isTrue(0x1234.round() is int);
Expect.isTrue(0x12345678.round() is int);
Expect.isTrue(0x123456789AB.round() is int);
Expect.isTrue(0x123456789ABCDEF.round() is int);
Expect
.isTrue(0x123456789ABCDEF0123456789ABCDEF0123456789ABCDEF.round() is int);
Expect.isTrue(-1.round() is int);
Expect.isTrue(-0x1234.round() is int);
Expect.isTrue(-0x12345678.round() is int);
Expect.isTrue(-0x123456789AB.round() is int);
Expect.isTrue(-0x123456789ABCDEF.round() is int);
Expect.isTrue(
-0x123456789ABCDEF0123456789ABCDEF0123456789ABCDEF.round() is int);
}

View file

@ -1,39 +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.roundToDouble());
Expect.equals(1.0, 1.roundToDouble());
Expect.equals(0x1234, 0x1234.roundToDouble());
Expect.equals(0x12345678, 0x12345678.roundToDouble());
Expect.equals(0x123456789AB, 0x123456789AB.roundToDouble());
Expect.equals(81985529216486900.0, 0x123456789ABCDEF.roundToDouble());
Expect.equals(2.7898229935051914e+55,
0x123456789ABCDEF0123456789ABCDEF0123456789ABCDEF.roundToDouble());
Expect.equals(-1.0, -1.roundToDouble());
Expect.equals(-0x1234, -0x1234.roundToDouble());
Expect.equals(-0x12345678, -0x12345678.roundToDouble());
Expect.equals(-0x123456789AB, -0x123456789AB.roundToDouble());
Expect.equals(-81985529216486900.0, -0x123456789ABCDEF.roundToDouble());
Expect.equals(-2.7898229935051914e+55,
-0x123456789ABCDEF0123456789ABCDEF0123456789ABCDEF.roundToDouble());
Expect.isTrue(0.roundToDouble() is double);
Expect.isTrue(1.roundToDouble() is double);
Expect.isTrue(0x1234.roundToDouble() is double);
Expect.isTrue(0x12345678.roundToDouble() is double);
Expect.isTrue(0x123456789AB.roundToDouble() is double);
Expect.isTrue(0x123456789ABCDEF.roundToDouble() is double);
Expect.isTrue(0x123456789ABCDEF0123456789ABCDEF0123456789ABCDEF
.roundToDouble() is double);
Expect.isTrue(-1.roundToDouble() is double);
Expect.isTrue(-0x1234.roundToDouble() is double);
Expect.isTrue(-0x12345678.roundToDouble() is double);
Expect.isTrue(-0x123456789AB.roundToDouble() is double);
Expect.isTrue(-0x123456789ABCDEF.roundToDouble() is double);
Expect.isTrue(-0x123456789ABCDEF0123456789ABCDEF0123456789ABCDEF
.roundToDouble() is double);
}

View file

@ -1,39 +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.toInt());
Expect.equals(1, 1.toInt());
Expect.equals(0x1234, 0x1234.toInt());
Expect.equals(0x12345678, 0x12345678.toInt());
Expect.equals(0x123456789AB, 0x123456789AB.toInt());
Expect.equals(0x123456789ABCDEF, 0x123456789ABCDEF.toInt());
Expect.equals(0x123456789ABCDEF0123456789ABCDEF0123456789ABCDEF,
0x123456789ABCDEF0123456789ABCDEF0123456789ABCDEF.toInt());
Expect.equals(-1, -1.toInt());
Expect.equals(-0x1234, -0x1234.toInt());
Expect.equals(-0x12345678, -0x12345678.toInt());
Expect.equals(-0x123456789AB, -0x123456789AB.toInt());
Expect.equals(-0x123456789ABCDEF, -0x123456789ABCDEF.toInt());
Expect.equals(-0x123456789ABCDEF0123456789ABCDEF0123456789ABCDEF,
-0x123456789ABCDEF0123456789ABCDEF0123456789ABCDEF.toInt());
Expect.isTrue(0.toInt() is int);
Expect.isTrue(1.toInt() is int);
Expect.isTrue(0x1234.toInt() is int);
Expect.isTrue(0x12345678.toInt() is int);
Expect.isTrue(0x123456789AB.toInt() is int);
Expect.isTrue(0x123456789ABCDEF.toInt() is int);
Expect
.isTrue(0x123456789ABCDEF0123456789ABCDEF0123456789ABCDEF.toInt() is int);
Expect.isTrue(-1.toInt() is int);
Expect.isTrue(-0x1234.toInt() is int);
Expect.isTrue(-0x12345678.toInt() is int);
Expect.isTrue(-0x123456789AB.toInt() is int);
Expect.isTrue(-0x123456789ABCDEF.toInt() is int);
Expect.isTrue(
-0x123456789ABCDEF0123456789ABCDEF0123456789ABCDEF.toInt() is int);
}

View file

@ -1,39 +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.truncate());
Expect.equals(1, 1.truncate());
Expect.equals(0x1234, 0x1234.truncate());
Expect.equals(0x12345678, 0x12345678.truncate());
Expect.equals(0x123456789AB, 0x123456789AB.truncate());
Expect.equals(0x123456789ABCDEF, 0x123456789ABCDEF.truncate());
Expect.equals(0x123456789ABCDEF0123456789ABCDEF0123456789ABCDEF,
0x123456789ABCDEF0123456789ABCDEF0123456789ABCDEF.truncate());
Expect.equals(-1, -1.truncate());
Expect.equals(-0x1234, -0x1234.truncate());
Expect.equals(-0x12345678, -0x12345678.truncate());
Expect.equals(-0x123456789AB, -0x123456789AB.truncate());
Expect.equals(-0x123456789ABCDEF, -0x123456789ABCDEF.truncate());
Expect.equals(-0x123456789ABCDEF0123456789ABCDEF0123456789ABCDEF,
-0x123456789ABCDEF0123456789ABCDEF0123456789ABCDEF.truncate());
Expect.isTrue(0.truncate() is int);
Expect.isTrue(1.truncate() is int);
Expect.isTrue(0x1234.truncate() is int);
Expect.isTrue(0x12345678.truncate() is int);
Expect.isTrue(0x123456789AB.truncate() is int);
Expect.isTrue(0x123456789ABCDEF.truncate() is int);
Expect.isTrue(
0x123456789ABCDEF0123456789ABCDEF0123456789ABCDEF.truncate() is int);
Expect.isTrue(-1.truncate() is int);
Expect.isTrue(-0x1234.truncate() is int);
Expect.isTrue(-0x12345678.truncate() is int);
Expect.isTrue(-0x123456789AB.truncate() is int);
Expect.isTrue(-0x123456789ABCDEF.truncate() is int);
Expect.isTrue(
-0x123456789ABCDEF0123456789ABCDEF0123456789ABCDEF.truncate() is int);
}

View file

@ -1,39 +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.truncateToDouble());
Expect.equals(1.0, 1.truncateToDouble());
Expect.equals(0x1234, 0x1234.truncateToDouble());
Expect.equals(0x12345678, 0x12345678.truncateToDouble());
Expect.equals(0x123456789AB, 0x123456789AB.truncateToDouble());
Expect.equals(81985529216486900.0, 0x123456789ABCDEF.truncateToDouble());
Expect.equals(2.7898229935051914e+55,
0x123456789ABCDEF0123456789ABCDEF0123456789ABCDEF.truncateToDouble());
Expect.equals(-1.0, -1.truncateToDouble());
Expect.equals(-0x1234, -0x1234.truncateToDouble());
Expect.equals(-0x12345678, -0x12345678.truncateToDouble());
Expect.equals(-0x123456789AB, -0x123456789AB.truncateToDouble());
Expect.equals(-81985529216486900.0, -0x123456789ABCDEF.truncateToDouble());
Expect.equals(-2.7898229935051914e+55,
-0x123456789ABCDEF0123456789ABCDEF0123456789ABCDEF.truncateToDouble());
Expect.isTrue(0.truncateToDouble() is double);
Expect.isTrue(1.truncateToDouble() is double);
Expect.isTrue(0x1234.truncateToDouble() is double);
Expect.isTrue(0x12345678.truncateToDouble() is double);
Expect.isTrue(0x123456789AB.truncateToDouble() is double);
Expect.isTrue(0x123456789ABCDEF.truncateToDouble() is double);
Expect.isTrue(0x123456789ABCDEF0123456789ABCDEF0123456789ABCDEF
.truncateToDouble() is double);
Expect.isTrue(-1.truncateToDouble() is double);
Expect.isTrue(-0x1234.truncateToDouble() is double);
Expect.isTrue(-0x12345678.truncateToDouble() is double);
Expect.isTrue(-0x123456789AB.truncateToDouble() is double);
Expect.isTrue(-0x123456789ABCDEF.truncateToDouble() is double);
Expect.isTrue(-0x123456789ABCDEF0123456789ABCDEF0123456789ABCDEF
.truncateToDouble() is double);
}

View file

@ -1,95 +0,0 @@
// Copyright (c) 2012, 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() {
// Test that we accept radix 2 to 36 and that we use lower-case
// letters.
var expected = [
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'a',
'b',
'c',
'd',
'e',
'f',
'g',
'h',
'i',
'j',
'k',
'l',
'm',
'n',
'o',
'p',
'q',
'r',
's',
't',
'u',
'v',
'w',
'x',
'y',
'z'
];
for (var radix = 2; radix <= 36; radix++) {
for (var i = 0; i < radix; i++) {
Expect.equals(expected[i], i.toRadixString(radix));
}
}
var illegalRadices = [-1, 0, 1, 37];
for (var radix in illegalRadices) {
try {
42.toRadixString(radix);
Expect.fail("Exception expected");
} on ArgumentError catch (e) {
// Nothing to do.
}
}
// Try large numbers (regression test for issue 15316).
var bignums = [
0x80000000,
0x100000000,
0x10000000000000,
0x10000000000001, // 53 significant bits.
0x20000000000000,
0x20000000000002,
0x1000000000000000,
0x1000000000000100,
0x2000000000000000,
0x2000000000000200,
0x8000000000000000,
0x8000000000000800,
0x10000000000000000,
0x10000000000001000,
0x100000000000010000,
0x1000000000000100000,
0x10000000000001000000,
0x100000000000010000000,
0x1000000000000100000000,
0x10000000000001000000000,
];
for (var bignum in bignums) {
for (int radix = 2; radix <= 36; radix++) {
String digits = bignum.toRadixString(radix);
int result = int.parse(digits, radix: radix);
Expect.equals(
bignum, result, "${bignum.toRadixString(16)} -> $digits/$radix");
}
}
}

View file

@ -1,89 +0,0 @@
// Copyright (c) 2012, 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() {
/// Test that converting [value] to a string gives [expect].
/// Also test that `-value` gives `"-"+expect`.
test(int value, String expect) {
Expect.equals(expect, value.toString());
Expect.equals(expect, "$value");
Expect.equals(expect, (new StringBuffer()..write(value)).toString());
if (value == 0) return;
expect = "-$expect";
value = -value;
Expect.equals(expect, value.toString());
Expect.equals(expect, "$value");
Expect.equals(expect, (new StringBuffer()..write(value)).toString());
}
// Very simple tests.
test(0, "0");
test(1, "1");
test(2, "2");
test(5, "5");
// Binary special cases.
// ~2^30.
test(0x3fffffff, "1073741823");
test(0x40000000, "1073741824");
test(0x40000001, "1073741825");
// ~2^31.
test(0x7fffffff, "2147483647");
test(0x80000000, "2147483648");
test(0x80000001, "2147483649");
// ~2^32.
test(0xffffffff, "4294967295");
test(0x100000000, "4294967296");
test(0x100000001, "4294967297");
// ~2^51.
test(0x7ffffffffffff, "2251799813685247");
test(0x8000000000000, "2251799813685248");
test(0x8000000000001, "2251799813685249");
// ~2^52.
test(0xfffffffffffff, "4503599627370495");
test(0x10000000000000, "4503599627370496");
test(0x10000000000001, "4503599627370497");
// ~2^53.
test(0x1fffffffffffff, "9007199254740991");
test(0x20000000000000, "9007199254740992");
test(0x20000000000001, "9007199254740993"); // //# 01: ok
// ~2^62.
test(0x3fffffffffffffff, "4611686018427387903"); // //# 01: continued
test(0x4000000000000000, "4611686018427387904"); // //# 01: continued
test(0x4000000000000001, "4611686018427387905"); // //# 01: continued
// ~2^63.
test(0x7fffffffffffffff, "9223372036854775807"); // //# 01: continued
test(0x8000000000000000, "9223372036854775808"); // //# 01: continued
test(0x8000000000000001, "9223372036854775809"); // //# 01: continued
// ~2^64.
test(0xffffffffffffffff, "18446744073709551615"); // //# 01: continued
test(0x10000000000000000, "18446744073709551616"); // //# 01: continued
test(0x10000000000000001, "18446744073709551617"); // //# 01: continued
// Big bignum.
test(123456789012345678901234567890, // //# 01: continued
"123456789012345678901234567890"); // //# 01: continued
// Decimal special cases.
int number = 10;
// Numbers 99..99, 100...00, and 100..01 up to 23 digits.
for (int i = 1; i < 15; i++) {
// Works in dart2js up to 10^15.
test(number - 1, "9" * i);
test(number, "1" + "0" * i);
test(number + 1, "1" + "0" * (i - 1) + "1");
number *= 10;
}
// Fails to represent exactly in dart2js.
for (int i = 15; i < 22; i++) { // //# 01: continued
test(number - 1, "9" * i); // //# 01: continued
test(number, "1" + "0" * i); // //# 01: continued
test(number + 1, "1" + "0" * (i - 1) + "1"); // //# 01: continued
number *= 10; // //# 01: continued
} // //# 01: continued
}

View file

@ -1,61 +0,0 @@
// Copyright (c) 2012, 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.
// Dart test program for the "is" type test operator.
import "package:expect/expect.dart";
check(args) {
var list = args[0];
var string = args[1];
var nullObject = args[2];
Expect.isTrue(list is Object);
Expect.isTrue(list is List);
Expect.isTrue(list is Iterable);
Expect.isFalse(list is Comparable);
Expect.isFalse(list is Pattern);
Expect.isFalse(list is String);
Expect.isFalse(list is! List);
Expect.isFalse(list is! Iterable);
Expect.isTrue(list is! Comparable);
Expect.isTrue(list is! Pattern);
Expect.isTrue(list is! String);
Expect.isTrue(string is Object);
Expect.isFalse(string is List);
Expect.isFalse(string is Iterable);
Expect.isTrue(string is Comparable);
Expect.isTrue(string is Pattern);
Expect.isTrue(string is String);
Expect.isTrue(string is! List);
Expect.isTrue(string is! Iterable);
Expect.isFalse(string is! Comparable);
Expect.isFalse(string is! Pattern);
Expect.isFalse(string is! String);
Expect.isTrue(nullObject is Object);
Expect.isFalse(nullObject is List);
Expect.isFalse(nullObject is Iterable);
Expect.isFalse(nullObject is Comparable);
Expect.isFalse(nullObject is Pattern);
Expect.isFalse(nullObject is String);
Expect.isTrue(nullObject is! List);
Expect.isTrue(nullObject is! Iterable);
Expect.isTrue(nullObject is! Comparable);
Expect.isTrue(nullObject is! Pattern);
Expect.isTrue(nullObject is! String);
}
main() {
// Try to make it hard for an optimizing compiler to inline the
// tests.
check([[], 'string', null]);
// Try to make it even harder.
var string = new String.fromCharCodes([new DateTime.now().year % 100 + 1]);
check([string.codeUnits, string, null]);
}

View file

@ -1,38 +0,0 @@
// Copyright (c) 2012, 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";
// Tests for the contains methods on lists.
class A {
const A();
}
class B extends A {
const B();
}
main() {
var list = <B>[new B()];
var set = new Set<B>();
set.add(new B());
var iterable1 = list.map((x) => x);
var iterable2 = list.take(1);
var list2 = const <B>[const B()];
var iterable3 = list2.map((x) => x);
var iterable4 = list2.take(1);
var iterables = [
list,
set,
iterable1,
iterable2,
list2,
iterable3,
iterable4
];
for (var iterable in iterables) {
Expect.isFalse(iterable.contains(new A()));
}
}

View file

@ -1,48 +0,0 @@
// Copyright (c) 2012, 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";
// Tests for the contains methods on lists.
test(list, notInList) {
testList(list) {
for (int i = 0; i < list.length; i++) {
var elem = list[i];
Expect.isTrue(list.contains(list[i]), "$list.contains($elem)");
}
Expect.isFalse(list.contains(notInList), "!$list.contains($notInList)");
}
List fixedList = new List(list.length);
List growList = new List();
for (int i = 0; i < list.length; i++) {
fixedList[i] = list[i];
growList.add(list[i]);
}
testList(list);
testList(fixedList);
testList(growList);
}
class C {
const C();
}
class Niet {
bool operator ==(other) => false;
}
main() {
test(const <String>["a", "b", "c", null], "d");
test(const <int>[1, 2, 3, null], 0);
test(const <bool>[true, false], null);
test(const <C>[const C(), const C(), null], new C());
test(<C>[new C(), new C(), new C(), null], new C());
test(const <double>[0.0, 1.0, 5e-324, 1e+308, double.INFINITY], 2.0);
Expect.isTrue(const <double>[-0.0].contains(0.0));
Expect.isFalse(const <double>[double.NAN].contains(double.NAN));
var niet = new Niet();
Expect.isFalse([niet].contains(niet));
}

View file

@ -1,74 +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:collection';
class MyList extends ListBase {
List list;
MyList(this.list);
get length => list.length;
set length(val) {
list.length = val;
}
operator [](index) => list[index];
operator []=(index, val) => list[index] = val;
String toString() => "[" + join(", ") + "]";
}
main() {
test(expectation, iterable) {
Expect.listEquals(expectation, iterable.toList());
}
// Function not called on empty iterable.
test(
[],
[].expand((x) {
throw "not called";
}));
// Creating the iterable doesn't call the function.
[1].expand((x) {
throw "not called";
});
test([1], [1].expand((x) => [x]));
test([1, 2, 3], [1, 2, 3].expand((x) => [x]));
test([], [1].expand((x) => []));
test([], [1, 2, 3].expand((x) => []));
test([2], [1, 2, 3].expand((x) => x == 2 ? [2] : []));
test([1, 1, 2, 2, 3, 3], [1, 2, 3].expand((x) => [x, x]));
test([1, 1, 2], [1, 2, 3].expand((x) => [x, x, x].skip(x)));
test([1], new MyList([1]).expand((x) => [x]));
test([1, 2, 3], new MyList([1, 2, 3]).expand((x) => [x]));
test([], new MyList([1]).expand((x) => []));
test([], new MyList([1, 2, 3]).expand((x) => []));
test([2], new MyList([1, 2, 3]).expand((x) => x == 2 ? [2] : []));
test([1, 1, 2, 2, 3, 3], new MyList([1, 2, 3]).expand((x) => [x, x]));
test([1, 1, 2], new MyList([1, 2, 3]).expand((x) => [x, x, x].skip(x)));
// if function throws, iteration is stopped.
Iterable iterable = [1, 2, 3].expand((x) {
if (x == 2) throw "FAIL";
return [x, x];
});
Iterator it = iterable.iterator;
Expect.isTrue(it.moveNext());
Expect.equals(1, it.current);
Expect.isTrue(it.moveNext());
Expect.equals(1, it.current);
Expect.throws(it.moveNext, (e) => e == "FAIL");
// After throwing, iteration is ended.
Expect.equals(null, it.current);
Expect.isFalse(it.moveNext());
}

View file

@ -1,22 +0,0 @@
// Copyright (c) 2012, 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() {
List<int> list1 = <int>[1, 2, 3];
List<int> list2 = const <int>[4, 5];
List<String> list3 = <String>[];
Set<int> set1 = new Set<int>();
set1..add(11)..add(12)..add(13);
Set set2 = new Set();
Expect.equals(1, list1.first);
Expect.equals(4, list2.first);
Expect.throws(() => list3.first, (e) => e is StateError);
Expect.isTrue(set1.contains(set1.first));
Expect.throws(() => set2.first, (e) => e is StateError);
}

View file

@ -1,43 +0,0 @@
// Copyright (c) 2012, 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() {
List<int> list1 = <int>[1, 2, 3];
List<int> list2 = const <int>[4, 5];
List<String> list3 = <String>[];
Set<int> set1 = new Set<int>();
set1..add(11)..add(12)..add(13);
Set set2 = new Set();
Expect.equals(2, list1.firstWhere((x) => x.isEven));
Expect.equals(1, list1.firstWhere((x) => x.isOdd));
Expect.throws(() => list1.firstWhere((x) => x > 3), (e) => e is StateError);
Expect.equals(null, list1.firstWhere((x) => x > 3, orElse: () => null));
Expect.equals(499, list1.firstWhere((x) => x > 3, orElse: () => 499));
Expect.equals(4, list2.firstWhere((x) => x.isEven));
Expect.equals(5, list2.firstWhere((x) => x.isOdd));
Expect.throws(() => list2.firstWhere((x) => x == 0), (e) => e is StateError);
Expect.equals(null, list2.firstWhere((x) => false, orElse: () => null));
Expect.equals(499, list2.firstWhere((x) => false, orElse: () => 499));
Expect.throws(() => list3.firstWhere((x) => x == 0), (e) => e is StateError);
Expect.throws(() => list3.firstWhere((x) => true), (e) => e is StateError);
Expect.equals(null, list3.firstWhere((x) => true, orElse: () => null));
Expect.equals("str", list3.firstWhere((x) => false, orElse: () => "str"));
Expect.equals(12, set1.firstWhere((x) => x.isEven));
var odd = set1.firstWhere((x) => x.isOdd);
Expect.isTrue(odd == 11 || odd == 13);
Expect.throws(() => set1.firstWhere((x) => false), (e) => e is StateError);
Expect.equals(null, set1.firstWhere((x) => false, orElse: () => null));
Expect.equals(499, set1.firstWhere((x) => false, orElse: () => 499));
Expect.throws(() => set2.firstWhere((x) => false), (e) => e is StateError);
Expect.throws(() => set2.firstWhere((x) => true), (e) => e is StateError);
Expect.equals(null, set2.firstWhere((x) => true, orElse: () => null));
Expect.equals(499, set2.firstWhere((x) => false, orElse: () => 499));
}

View file

@ -1,202 +0,0 @@
// Copyright (c) 2014, 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:collection';
import 'dart:typed_data';
class MyList extends ListBase {
List list;
MyList(this.list);
get length => list.length;
set length(val) {
list.length = val;
}
operator [](index) => list[index];
operator []=(index, val) => list[index] = val;
}
id(x) => x;
main() {
for (var iterable in [
const [1, 2, 3],
[1, 2, 3],
new List(3)
..[0] = 1
..[1] = 2
..[2] = 3,
{1: 1, 2: 2, 3: 3}.keys,
{1: 1, 2: 2, 3: 3}.values,
new Iterable.generate(3, (x) => x + 1),
new List.generate(3, (x) => x + 1),
[0, 1, 2, 3].where((x) => x > 0),
[0, 1, 2].map((x) => x + 1),
[
[1, 2],
[3]
].expand(id),
[3, 2, 1].reversed,
[0, 1, 2, 3].skip(1),
[1, 2, 3, 4].take(3),
new Uint8List(3)
..[0] = 1
..[1] = 2
..[2] = 3,
(new HashMap()
..[1] = 1
..[2] = 2
..[3] = 3)
.keys,
(new HashMap()
..[1] = 1
..[2] = 2
..[3] = 3)
.values,
(new SplayTreeMap()
..[1] = 0
..[2] = 0
..[3] = 0)
.keys,
(new SplayTreeMap()
..[0] = 1
..[1] = 2
..[2] = 3)
.values,
new HashSet()..add(1)..add(2)..add(3),
new LinkedHashSet()..add(1)..add(2)..add(3),
new SplayTreeSet()..add(1)..add(2)..add(3),
"\x01\x02\x03".codeUnits,
"\x01\x02\x03".runes,
new MyList([1, 2, 3]),
]) {
int callCount = 0;
var result = iterable.fold(0, (x, y) {
callCount++;
return x + y;
});
Expect.equals(6, result, "${iterable.runtimeType}");
Expect.equals(3, callCount);
}
// Empty iterables are allowed.
for (var iterable in [
const [],
[],
new List(0),
{}.keys,
{}.values,
new Iterable.generate(0, (x) => x + 1),
new List.generate(0, (x) => x + 1),
[0, 1, 2, 3].where((x) => false),
[].map((x) => x + 1),
[[], []].expand(id),
[].reversed,
[0, 1, 2, 3].skip(4),
[1, 2, 3, 4].take(0),
new Uint8List(0),
(new HashMap()).keys,
(new HashMap()).values,
(new SplayTreeMap()).keys,
(new SplayTreeMap()).values,
new HashSet(),
new LinkedHashSet(),
new SplayTreeSet(),
"".codeUnits,
"".runes,
new MyList([]),
]) {
Expect.equals(42, iterable.fold(42, (x, y) => throw "Unreachable"));
}
// Singleton iterables are calling reduce function.
for (var iterable in [
const [1],
[1],
new List(1)..[0] = 1,
{1: 1}.keys,
{1: 1}.values,
new Iterable.generate(1, (x) => x + 1),
new List.generate(1, (x) => x + 1),
[0, 1, 2, 3].where((x) => x == 1),
[0].map((x) => x + 1),
[
[],
[1]
].expand(id),
[1].reversed,
[0, 1].skip(1),
[1, 2, 3, 4].take(1),
new Uint8List(1)..[0] = 1,
(new HashMap()..[1] = 0).keys,
(new HashMap()..[0] = 1).values,
(new SplayTreeMap()..[1] = 0).keys,
(new SplayTreeMap()..[0] = 1).values,
new HashSet()..add(1),
new LinkedHashSet()..add(1),
new SplayTreeSet()..add(1),
"\x01".codeUnits,
"\x01".runes,
new MyList([1]),
]) {
Expect.equals(43, iterable.fold(42, (x, y) => x + y));
}
// Concurrent modifications not allowed.
testModification(base, modify, transform) {
var iterable = transform(base);
Expect.throws(() {
iterable.fold(0, (x, y) {
modify(base);
return x + y;
});
}, (e) => e is ConcurrentModificationError);
}
void add4(collection) {
collection.add(4);
}
void put4(map) {
map[4] = 4;
}
testModification([1, 2, 3], add4, id);
testModification(new HashSet()..add(1)..add(2)..add(3), add4, id);
testModification(new LinkedHashSet()..add(1)..add(2)..add(3), add4, id);
testModification(new SplayTreeSet()..add(1)..add(2)..add(3), add4, id);
testModification(new MyList([1, 2, 3]), add4, id);
testModification([0, 1, 2, 3], add4, (x) => x.where((x) => x > 0));
testModification([0, 1, 2], add4, (x) => x.map((x) => x + 1));
testModification([
[1, 2],
[3]
], add4, (x) => x.expand((x) => x));
testModification([3, 2, 1], add4, (x) => x.reversed);
testModification({1: 1, 2: 2, 3: 3}, put4, (x) => x.keys);
testModification({1: 1, 2: 2, 3: 3}, put4, (x) => x.values);
var hashMap = new HashMap()
..[1] = 1
..[2] = 2
..[3] = 3;
testModification(hashMap, put4, (x) => x.keys);
hashMap = new HashMap()
..[1] = 1
..[2] = 2
..[3] = 3;
testModification(hashMap, put4, (x) => x.values);
var splayMap = new SplayTreeMap()
..[1] = 1
..[2] = 2
..[3] = 3;
testModification(splayMap, put4, (x) => x.keys);
splayMap = new SplayTreeMap()
..[1] = 1
..[2] = 2
..[3] = 3;
testModification(splayMap, put4, (x) => x.values);
}