mirror of
https://github.com/dart-lang/sdk
synced 2024-09-18 21:11:19 +00:00
328c30324c
This was a hairy test block, please review carefully. Special circumstances: file_resource_test.dart: deleted, depends on Resource class which was moved outside the SDK from_environment_const_type_undefined_test.dart, from_environment_const_type_test: change to expect compile-time errors for all error cases. Hacked up status files to enable non-strong/checked/non-checked modes to work in all cases. format_exception_test.dart: corelib is newer, has updated tests growable_list_test.dart: corelib is newer, with updated comments. Stripped runtime checking of checked mode. Also, this doesn't work, but should, with dartdevc, so added to exclusion list hash_map2_test.dart: corelib_strong version seems to be newer, has VM option comments BUG= R=rnystrom@google.com Review-Url: https://codereview.chromium.org/2989643002 .
97 lines
2 KiB
Dart
97 lines
2 KiB
Dart
// Copyright (c) 2011, 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 ForInTest {
|
|
static testMain() {
|
|
testSimple();
|
|
testBreak();
|
|
testContinue();
|
|
testClosure();
|
|
}
|
|
|
|
static Set<int> getSmallSet() {
|
|
Set<int> set = new Set<int>();
|
|
set.add(1);
|
|
set.add(2);
|
|
set.add(4);
|
|
return set;
|
|
}
|
|
|
|
static void testSimple() {
|
|
Set<int> set = getSmallSet();
|
|
int count = 0;
|
|
for (final i in set) {
|
|
count += i;
|
|
}
|
|
Expect.equals(7, count);
|
|
|
|
count = 0;
|
|
for (var i in set) {
|
|
count += i;
|
|
}
|
|
Expect.equals(7, count);
|
|
|
|
count = 0;
|
|
for (int i in set) {
|
|
count += i;
|
|
}
|
|
Expect.equals(7, count);
|
|
|
|
count = 0;
|
|
for (final int i in set) {
|
|
count += i;
|
|
}
|
|
Expect.equals(7, count);
|
|
|
|
count = 0;
|
|
int i = 0;
|
|
Expect.equals(false, set.contains(i)); // Used to test [i] after loop.
|
|
for (i in set) {
|
|
count += i;
|
|
}
|
|
Expect.equals(7, count);
|
|
Expect.equals(true, set.contains(i));
|
|
// The default implementation of [Set] preserves order.
|
|
Expect.equals(4, i);
|
|
}
|
|
|
|
static void testBreak() {
|
|
Set<int> set = getSmallSet();
|
|
int count = 0;
|
|
for (final i in set) {
|
|
if (i == 4) break;
|
|
count += i;
|
|
}
|
|
Expect.equals(true, count < 4);
|
|
}
|
|
|
|
static void testContinue() {
|
|
Set<int> set = getSmallSet();
|
|
int count = 0;
|
|
for (final i in set) {
|
|
if (i < 4) continue;
|
|
count += i;
|
|
}
|
|
Expect.equals(4, count);
|
|
}
|
|
|
|
static void testClosure() {
|
|
Set<int> set = getSmallSet();
|
|
List<Function> closures = new List(set.length);
|
|
int index = 0;
|
|
for (var i in set) {
|
|
closures[index++] = () => i;
|
|
}
|
|
|
|
Expect.equals(index, set.length);
|
|
Expect.equals(7, closures[0]() + closures[1]() + closures[2]());
|
|
}
|
|
}
|
|
|
|
main() {
|
|
ForInTest.testMain();
|
|
}
|