OLD | NEW |
(Empty) | |
| 1 dart_library.library('corelib/iterable_skip_test', null, /* Imports */[ |
| 2 'dart_sdk', |
| 3 'expect' |
| 4 ], function load__iterable_skip_test(exports, dart_sdk, expect) { |
| 5 'use strict'; |
| 6 const core = dart_sdk.core; |
| 7 const _interceptors = dart_sdk._interceptors; |
| 8 const dart = dart_sdk.dart; |
| 9 const dartx = dart_sdk.dartx; |
| 10 const expect$ = expect.expect; |
| 11 const iterable_skip_test = Object.create(null); |
| 12 let JSArrayOfint = () => (JSArrayOfint = dart.constFn(_interceptors.JSArray$(c
ore.int)))(); |
| 13 let JSArrayOfString = () => (JSArrayOfString = dart.constFn(_interceptors.JSAr
ray$(core.String)))(); |
| 14 let SetOfint = () => (SetOfint = dart.constFn(core.Set$(core.int)))(); |
| 15 let IterableOfint = () => (IterableOfint = dart.constFn(core.Iterable$(core.in
t)))(); |
| 16 let JSArrayOfIterable = () => (JSArrayOfIterable = dart.constFn(_interceptors.
JSArray$(core.Iterable)))(); |
| 17 let IterableAndintAndintTodynamic = () => (IterableAndintAndintTodynamic = dar
t.constFn(dart.definiteFunctionType(dart.dynamic, [core.Iterable, core.int, core
.int])))(); |
| 18 let VoidToIterable = () => (VoidToIterable = dart.constFn(dart.definiteFunctio
nType(core.Iterable, [])))(); |
| 19 let dynamicTobool = () => (dynamicTobool = dart.constFn(dart.definiteFunctionT
ype(core.bool, [dart.dynamic])))(); |
| 20 let VoidTodynamic = () => (VoidTodynamic = dart.constFn(dart.definiteFunctionT
ype(dart.dynamic, [])))(); |
| 21 let const$; |
| 22 iterable_skip_test.main = function() { |
| 23 let list1 = JSArrayOfint().of([1, 2, 3]); |
| 24 let list2 = const$ || (const$ = dart.constList([4, 5], core.int)); |
| 25 let list3 = JSArrayOfString().of([]); |
| 26 let set1 = SetOfint().new(); |
| 27 set1.add(11); |
| 28 set1.add(12); |
| 29 set1.add(13); |
| 30 let set2 = core.Set.new(); |
| 31 let skip0 = list1[dartx.skip](0); |
| 32 expect$.Expect.isTrue(!core.List.is(skip0)); |
| 33 let it = skip0[dartx.iterator]; |
| 34 expect$.Expect.isNull(it.current); |
| 35 expect$.Expect.isTrue(it.moveNext()); |
| 36 expect$.Expect.equals(1, it.current); |
| 37 expect$.Expect.isTrue(it.moveNext()); |
| 38 expect$.Expect.equals(2, it.current); |
| 39 expect$.Expect.isTrue(it.moveNext()); |
| 40 expect$.Expect.equals(3, it.current); |
| 41 expect$.Expect.isFalse(it.moveNext()); |
| 42 expect$.Expect.isNull(it.current); |
| 43 let skip1 = list1[dartx.skip](1); |
| 44 expect$.Expect.isTrue(!core.List.is(skip1)); |
| 45 expect$.Expect.isTrue(!core.List.is(skip1[dartx.skip](2)[dartx.skip](1))); |
| 46 it = skip1[dartx.iterator]; |
| 47 expect$.Expect.isNull(it.current); |
| 48 expect$.Expect.isTrue(it.moveNext()); |
| 49 expect$.Expect.equals(2, it.current); |
| 50 expect$.Expect.isTrue(it.moveNext()); |
| 51 expect$.Expect.equals(3, it.current); |
| 52 expect$.Expect.isFalse(it.moveNext()); |
| 53 expect$.Expect.isNull(it.current); |
| 54 let skip2 = list1[dartx.skip](2); |
| 55 expect$.Expect.isTrue(!core.List.is(skip2)); |
| 56 expect$.Expect.isTrue(!core.List.is(skip2[dartx.skip](2)[dartx.skip](1))); |
| 57 it = skip2[dartx.iterator]; |
| 58 expect$.Expect.isNull(it.current); |
| 59 expect$.Expect.isTrue(it.moveNext()); |
| 60 expect$.Expect.equals(3, it.current); |
| 61 expect$.Expect.isFalse(it.moveNext()); |
| 62 expect$.Expect.isNull(it.current); |
| 63 let skip3 = list1[dartx.skip](3); |
| 64 expect$.Expect.isTrue(!core.List.is(skip3)); |
| 65 expect$.Expect.isTrue(!core.List.is(skip3[dartx.skip](2)[dartx.skip](1))); |
| 66 it = skip3[dartx.iterator]; |
| 67 expect$.Expect.isNull(it.current); |
| 68 expect$.Expect.isFalse(it.moveNext()); |
| 69 expect$.Expect.isNull(it.current); |
| 70 let skip4 = list1[dartx.skip](4); |
| 71 expect$.Expect.isTrue(!core.List.is(skip4)); |
| 72 expect$.Expect.isTrue(!core.List.is(skip4[dartx.skip](2)[dartx.skip](1))); |
| 73 it = skip4[dartx.iterator]; |
| 74 expect$.Expect.isNull(it.current); |
| 75 expect$.Expect.isFalse(it.moveNext()); |
| 76 expect$.Expect.isNull(it.current); |
| 77 skip0 = list1[dartx.skip](0); |
| 78 skip1 = skip0[dartx.skip](1); |
| 79 skip2 = skip1[dartx.skip](1); |
| 80 skip3 = skip2[dartx.skip](1); |
| 81 skip4 = skip3[dartx.skip](1); |
| 82 it = skip0[dartx.iterator]; |
| 83 expect$.Expect.isNull(it.current); |
| 84 expect$.Expect.isTrue(it.moveNext()); |
| 85 expect$.Expect.equals(1, it.current); |
| 86 expect$.Expect.isTrue(it.moveNext()); |
| 87 expect$.Expect.equals(2, it.current); |
| 88 expect$.Expect.isTrue(it.moveNext()); |
| 89 expect$.Expect.equals(3, it.current); |
| 90 expect$.Expect.isFalse(it.moveNext()); |
| 91 expect$.Expect.isNull(it.current); |
| 92 it = skip1[dartx.iterator]; |
| 93 expect$.Expect.isNull(it.current); |
| 94 expect$.Expect.isTrue(it.moveNext()); |
| 95 expect$.Expect.equals(2, it.current); |
| 96 expect$.Expect.isTrue(it.moveNext()); |
| 97 expect$.Expect.equals(3, it.current); |
| 98 expect$.Expect.isFalse(it.moveNext()); |
| 99 expect$.Expect.isNull(it.current); |
| 100 it = skip2[dartx.iterator]; |
| 101 expect$.Expect.isNull(it.current); |
| 102 expect$.Expect.isTrue(it.moveNext()); |
| 103 expect$.Expect.equals(3, it.current); |
| 104 expect$.Expect.isFalse(it.moveNext()); |
| 105 expect$.Expect.isNull(it.current); |
| 106 it = skip3[dartx.iterator]; |
| 107 expect$.Expect.isNull(it.current); |
| 108 expect$.Expect.isFalse(it.moveNext()); |
| 109 expect$.Expect.isNull(it.current); |
| 110 it = skip4[dartx.iterator]; |
| 111 expect$.Expect.isNull(it.current); |
| 112 expect$.Expect.isFalse(it.moveNext()); |
| 113 expect$.Expect.isNull(it.current); |
| 114 skip0 = list2[dartx.skip](0); |
| 115 expect$.Expect.isTrue(!core.List.is(skip0)); |
| 116 expect$.Expect.isTrue(!core.List.is(skip0[dartx.skip](2)[dartx.skip](1))); |
| 117 it = skip0[dartx.iterator]; |
| 118 expect$.Expect.isNull(it.current); |
| 119 expect$.Expect.isTrue(it.moveNext()); |
| 120 expect$.Expect.equals(4, it.current); |
| 121 expect$.Expect.isTrue(it.moveNext()); |
| 122 expect$.Expect.equals(5, it.current); |
| 123 expect$.Expect.isFalse(it.moveNext()); |
| 124 expect$.Expect.isNull(it.current); |
| 125 skip1 = list2[dartx.skip](1); |
| 126 expect$.Expect.isTrue(!core.List.is(skip1)); |
| 127 expect$.Expect.isTrue(!core.List.is(skip1[dartx.skip](2)[dartx.skip](1))); |
| 128 it = skip1[dartx.iterator]; |
| 129 expect$.Expect.isNull(it.current); |
| 130 expect$.Expect.isTrue(it.moveNext()); |
| 131 expect$.Expect.equals(5, it.current); |
| 132 expect$.Expect.isFalse(it.moveNext()); |
| 133 expect$.Expect.isNull(it.current); |
| 134 skip2 = list2[dartx.skip](2); |
| 135 expect$.Expect.isTrue(!core.List.is(skip2)); |
| 136 expect$.Expect.isTrue(!core.List.is(skip2[dartx.skip](2)[dartx.skip](1))); |
| 137 it = skip2[dartx.iterator]; |
| 138 expect$.Expect.isNull(it.current); |
| 139 expect$.Expect.isFalse(it.moveNext()); |
| 140 expect$.Expect.isNull(it.current); |
| 141 skip3 = list2[dartx.skip](3); |
| 142 expect$.Expect.isTrue(!core.List.is(skip3)); |
| 143 expect$.Expect.isTrue(!core.List.is(skip3[dartx.skip](2)[dartx.skip](1))); |
| 144 it = skip3[dartx.iterator]; |
| 145 expect$.Expect.isNull(it.current); |
| 146 expect$.Expect.isFalse(it.moveNext()); |
| 147 expect$.Expect.isNull(it.current); |
| 148 let skip02 = list3[dartx.skip](0); |
| 149 expect$.Expect.isTrue(!core.List.is(skip02)); |
| 150 expect$.Expect.isTrue(!core.List.is(skip02[dartx.skip](2)[dartx.skip](1))); |
| 151 let it2 = skip02[dartx.iterator]; |
| 152 expect$.Expect.isNull(it2.current); |
| 153 expect$.Expect.isFalse(it2.moveNext()); |
| 154 expect$.Expect.isNull(it2.current); |
| 155 let skip12 = list3[dartx.skip](1); |
| 156 expect$.Expect.isTrue(!core.List.is(skip12)); |
| 157 expect$.Expect.isTrue(!core.List.is(skip12[dartx.skip](2)[dartx.skip](1))); |
| 158 it2 = skip12[dartx.iterator]; |
| 159 expect$.Expect.isNull(it2.current); |
| 160 expect$.Expect.isFalse(it2.moveNext()); |
| 161 expect$.Expect.isNull(it2.current); |
| 162 skip0 = set1.skip(0); |
| 163 let copied = skip0[dartx.toList](); |
| 164 expect$.Expect.equals(3, copied[dartx.length]); |
| 165 expect$.Expect.isTrue(set1.contains(copied[dartx.get](0))); |
| 166 expect$.Expect.isTrue(set1.contains(copied[dartx.get](1))); |
| 167 expect$.Expect.isTrue(set1.contains(copied[dartx.get](2))); |
| 168 expect$.Expect.isTrue(copied[dartx.get](0) != copied[dartx.get](1)); |
| 169 expect$.Expect.isTrue(copied[dartx.get](0) != copied[dartx.get](2)); |
| 170 expect$.Expect.isTrue(copied[dartx.get](1) != copied[dartx.get](2)); |
| 171 it = skip0[dartx.iterator]; |
| 172 expect$.Expect.isNull(it.current); |
| 173 expect$.Expect.isTrue(it.moveNext()); |
| 174 expect$.Expect.isNotNull(it.current); |
| 175 expect$.Expect.isTrue(it.moveNext()); |
| 176 expect$.Expect.isNotNull(it.current); |
| 177 expect$.Expect.isTrue(it.moveNext()); |
| 178 expect$.Expect.isNotNull(it.current); |
| 179 expect$.Expect.isFalse(it.moveNext()); |
| 180 expect$.Expect.isNull(it.current); |
| 181 skip1 = set1.skip(1); |
| 182 copied = skip1[dartx.toList](); |
| 183 expect$.Expect.equals(2, copied[dartx.length]); |
| 184 expect$.Expect.isTrue(set1.contains(copied[dartx.get](0))); |
| 185 expect$.Expect.isTrue(set1.contains(copied[dartx.get](1))); |
| 186 expect$.Expect.isTrue(copied[dartx.get](0) != copied[dartx.get](1)); |
| 187 it = skip1[dartx.iterator]; |
| 188 expect$.Expect.isNull(it.current); |
| 189 expect$.Expect.isTrue(it.moveNext()); |
| 190 expect$.Expect.isNotNull(it.current); |
| 191 expect$.Expect.isTrue(it.moveNext()); |
| 192 expect$.Expect.isNotNull(it.current); |
| 193 expect$.Expect.isFalse(it.moveNext()); |
| 194 expect$.Expect.isNull(it.current); |
| 195 skip2 = set1.skip(2); |
| 196 copied = skip2[dartx.toList](); |
| 197 expect$.Expect.equals(1, copied[dartx.length]); |
| 198 expect$.Expect.isTrue(set1.contains(copied[dartx.get](0))); |
| 199 it = skip2[dartx.iterator]; |
| 200 expect$.Expect.isNull(it.current); |
| 201 expect$.Expect.isTrue(it.moveNext()); |
| 202 expect$.Expect.isNotNull(it.current); |
| 203 expect$.Expect.isFalse(it.moveNext()); |
| 204 expect$.Expect.isNull(it.current); |
| 205 skip3 = set1.skip(3); |
| 206 it = skip3[dartx.iterator]; |
| 207 expect$.Expect.isNull(it.current); |
| 208 expect$.Expect.isFalse(it.moveNext()); |
| 209 expect$.Expect.isNull(it.current); |
| 210 skip4 = set1.skip(4); |
| 211 it = skip4[dartx.iterator]; |
| 212 expect$.Expect.isNull(it.current); |
| 213 expect$.Expect.isFalse(it.moveNext()); |
| 214 expect$.Expect.isNull(it.current); |
| 215 skip0 = IterableOfint()._check(set2.skip(0)); |
| 216 it = skip0[dartx.iterator]; |
| 217 expect$.Expect.isNull(it.current); |
| 218 expect$.Expect.isFalse(it.moveNext()); |
| 219 expect$.Expect.isNull(it.current); |
| 220 skip1 = IterableOfint()._check(set2.skip(1)); |
| 221 it = skip1[dartx.iterator]; |
| 222 expect$.Expect.isNull(it.current); |
| 223 expect$.Expect.isFalse(it.moveNext()); |
| 224 expect$.Expect.isNull(it.current); |
| 225 function testSkipTake(input, skip, take) { |
| 226 let expected = []; |
| 227 let iter = input[dartx.iterator]; |
| 228 for (let i = 0; i < dart.notNull(skip); i++) |
| 229 iter.moveNext(); |
| 230 for (let i = 0; i < dart.notNull(take); i++) { |
| 231 if (!dart.test(iter.moveNext())) break; |
| 232 expected[dartx.add](iter.current); |
| 233 } |
| 234 expect$.Expect.listEquals(expected, input[dartx.skip](skip)[dartx.take](ta
ke)[dartx.toList]()); |
| 235 } |
| 236 dart.fn(testSkipTake, IterableAndintAndintTodynamic()); |
| 237 let longList = JSArrayOfint().of([1, 4, 5, 3, 8, 11, 12, 6, 9, 10, 13, 7, 2,
14, 15]); |
| 238 let bigSet = longList[dartx.toSet](); |
| 239 for (let collection of JSArrayOfIterable().of([longList, longList[dartx.reve
rsed], bigSet])) { |
| 240 testSkipTake(collection, 0, 0); |
| 241 testSkipTake(collection, 0, 5); |
| 242 testSkipTake(collection, 0, 15); |
| 243 testSkipTake(collection, 0, 25); |
| 244 testSkipTake(collection, 5, 0); |
| 245 testSkipTake(collection, 5, 5); |
| 246 testSkipTake(collection, 5, 10); |
| 247 testSkipTake(collection, 5, 20); |
| 248 testSkipTake(collection, 15, 0); |
| 249 testSkipTake(collection, 15, 5); |
| 250 testSkipTake(collection, 20, 0); |
| 251 testSkipTake(collection, 20, 5); |
| 252 expect$.Expect.throws(dart.fn(() => longList[dartx.skip](-1), VoidToIterab
le()), dart.fn(e => core.RangeError.is(e), dynamicTobool())); |
| 253 } |
| 254 }; |
| 255 dart.fn(iterable_skip_test.main, VoidTodynamic()); |
| 256 // Exports: |
| 257 exports.iterable_skip_test = iterable_skip_test; |
| 258 }); |
OLD | NEW |