| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 // Dart test program for testing arrays. | 4 // Dart test program for testing arrays. |
| 5 | 5 |
| 6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
| 7 | 7 |
| 8 class A { } |
| 9 class B { } |
| 10 |
| 8 class ListTest { | 11 class ListTest { |
| 9 static void TestIterator() { | 12 static void TestIterator() { |
| 10 List<int> a = new List<int>(10); | 13 List<int> a = new List<int>(10); |
| 11 int count = 0; | 14 int count = 0; |
| 12 | 15 |
| 13 // Basic iteration over ObjectList. | 16 // Basic iteration over ObjectList. |
| 14 for (int elem in a) { | 17 for (int elem in a) { |
| 15 Expect.equals(null, elem); | 18 Expect.equals(null, elem); |
| 16 count++; | 19 count++; |
| 17 } | 20 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 35 Expect.equals(15, sum); | 38 Expect.equals(15, sum); |
| 36 | 39 |
| 37 // Iterate over List. | 40 // Iterate over List. |
| 38 int sum2 = 0; | 41 int sum2 = 0; |
| 39 for (int elem in fa) { | 42 for (int elem in fa) { |
| 40 sum2 += elem; | 43 sum2 += elem; |
| 41 } | 44 } |
| 42 Expect.equals(sum, sum2); | 45 Expect.equals(sum, sum2); |
| 43 } | 46 } |
| 44 | 47 |
| 48 static void testSublistTypeArguments() { |
| 49 final list1 = new List<A>(0).sublist(0); |
| 50 Expect.isTrue(list1 is List<A>); |
| 51 Expect.isTrue(list1 is! List<B>); |
| 52 |
| 53 final list2 = new List<A>(0).toList(growable: false); |
| 54 Expect.isTrue(list2 is List<A>); |
| 55 Expect.isTrue(list2 is! List<B>); |
| 56 } |
| 57 |
| 45 static void testMain() { | 58 static void testMain() { |
| 46 int len = 10; | 59 int len = 10; |
| 47 List a = new List(len); | 60 List a = new List(len); |
| 48 Expect.equals(true, a is List); | 61 Expect.equals(true, a is List); |
| 49 Expect.equals(len, a.length); | 62 Expect.equals(len, a.length); |
| 50 a.forEach((element) { Expect.equals(null, element); }); | 63 a.forEach((element) { Expect.equals(null, element); }); |
| 51 a[1] = 1; | 64 a[1] = 1; |
| 52 Expect.equals(1, a[1]); | 65 Expect.equals(1, a[1]); |
| 53 Expect.throws(() => a[len], (e) => e is RangeError); | 66 Expect.throws(() => a[len], (e) => e is RangeError); |
| 54 | 67 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 List list = new List(); | 121 List list = new List(); |
| 109 // We cannot write just 'list.removeLast' due to issue 3769. | 122 // We cannot write just 'list.removeLast' due to issue 3769. |
| 110 Expect.throws(() => list.removeLast(), | 123 Expect.throws(() => list.removeLast(), |
| 111 (e) => e is RangeError); | 124 (e) => e is RangeError); |
| 112 Expect.equals(0, list.length); | 125 Expect.equals(0, list.length); |
| 113 } | 126 } |
| 114 } | 127 } |
| 115 | 128 |
| 116 main() { | 129 main() { |
| 117 ListTest.testMain(); | 130 ListTest.testMain(); |
| 131 ListTest.testSublistTypeArguments(); |
| 118 } | 132 } |
| OLD | NEW |