OLD | NEW |
(Empty) | |
| 1 dart_library.library('language/async_star_test_04_multi', null, /* Imports */[ |
| 2 'dart_sdk', |
| 3 'unittest' |
| 4 ], function load__async_star_test_04_multi(exports, dart_sdk, unittest) { |
| 5 'use strict'; |
| 6 const core = dart_sdk.core; |
| 7 const _interceptors = dart_sdk._interceptors; |
| 8 const async = dart_sdk.async; |
| 9 const dart = dart_sdk.dart; |
| 10 const dartx = dart_sdk.dartx; |
| 11 const unittest$ = unittest.unittest; |
| 12 const src__matcher__expect = unittest.src__matcher__expect; |
| 13 const src__matcher__core_matchers = unittest.src__matcher__core_matchers; |
| 14 const src__matcher__numeric_matchers = unittest.src__matcher__numeric_matchers
; |
| 15 const async_star_test_04_multi = Object.create(null); |
| 16 let JSArrayOfint = () => (JSArrayOfint = dart.constFn(_interceptors.JSArray$(c
ore.int)))(); |
| 17 let JSArrayOfObject = () => (JSArrayOfObject = dart.constFn(_interceptors.JSAr
ray$(core.Object)))(); |
| 18 let FutureOfObject = () => (FutureOfObject = dart.constFn(async.Future$(core.O
bject)))(); |
| 19 let StreamOfObject = () => (StreamOfObject = dart.constFn(async.Stream$(core.O
bject)))(); |
| 20 let JSArrayOfString = () => (JSArrayOfString = dart.constFn(_interceptors.JSAr
ray$(core.String)))(); |
| 21 let VoidTodynamic = () => (VoidTodynamic = dart.constFn(dart.definiteFunctionT
ype(dart.dynamic, [])))(); |
| 22 let dynamicTodynamic = () => (dynamicTodynamic = dart.constFn(dart.definiteFun
ctionType(dart.dynamic, [dart.dynamic])))(); |
| 23 let dynamicTovoid = () => (dynamicTovoid = dart.constFn(dart.definiteFunctionT
ype(dart.void, [dart.dynamic])))(); |
| 24 let VoidToFuture = () => (VoidToFuture = dart.constFn(dart.definiteFunctionTyp
e(async.Future, [])))(); |
| 25 let VoidTovoid = () => (VoidTovoid = dart.constFn(dart.definiteFunctionType(da
rt.void, [])))(); |
| 26 let VoidToObject = () => (VoidToObject = dart.constFn(dart.definiteFunctionTyp
e(core.Object, [])))(); |
| 27 let VoidToFutureOfObject = () => (VoidToFutureOfObject = dart.constFn(dart.def
initeFunctionType(FutureOfObject(), [])))(); |
| 28 let VoidToStreamOfObject = () => (VoidToStreamOfObject = dart.constFn(dart.def
initeFunctionType(StreamOfObject(), [])))(); |
| 29 let dynamicToFuture = () => (dynamicToFuture = dart.constFn(dart.definiteFunct
ionType(async.Future, [dart.dynamic])))(); |
| 30 let VoidToint = () => (VoidToint = dart.constFn(dart.definiteFunctionType(core
.int, [])))(); |
| 31 let intTodynamic = () => (intTodynamic = dart.constFn(dart.definiteFunctionTyp
e(dart.dynamic, [core.int])))(); |
| 32 let dynamicAnddynamicTodynamic = () => (dynamicAnddynamicTodynamic = dart.cons
tFn(dart.definiteFunctionType(dart.dynamic, [dart.dynamic, dart.dynamic])))(); |
| 33 let dynamicAndEventSinkTovoid = () => (dynamicAndEventSinkTovoid = dart.constF
n(dart.definiteFunctionType(dart.void, [dart.dynamic, async.EventSink])))(); |
| 34 let ObjectAndStackTraceAndEventSinkTovoid = () => (ObjectAndStackTraceAndEvent
SinkTovoid = dart.constFn(dart.definiteFunctionType(dart.void, [core.Object, cor
e.StackTrace, async.EventSink])))(); |
| 35 let EventSinkTovoid = () => (EventSinkTovoid = dart.constFn(dart.definiteFunct
ionType(dart.void, [async.EventSink])))(); |
| 36 async_star_test_04_multi.main = function() { |
| 37 unittest$.group("basic", dart.fn(() => { |
| 38 unittest$.test("empty", dart.fn(() => { |
| 39 function f() { |
| 40 return dart.asyncStar(function*(stream) { |
| 41 }, dart.dynamic); |
| 42 } |
| 43 dart.fn(f, VoidTodynamic()); |
| 44 return dart.dsend(dart.dsend(f(), 'toList'), 'then', dart.fn(v => { |
| 45 src__matcher__expect.expect(v, src__matcher__core_matchers.equals([]))
; |
| 46 }, dynamicTodynamic())); |
| 47 }, VoidTodynamic())); |
| 48 unittest$.test("single", dart.fn(() => { |
| 49 function f() { |
| 50 return dart.asyncStar(function*(stream) { |
| 51 if (stream.add(42)) return; |
| 52 yield; |
| 53 }, dart.dynamic); |
| 54 } |
| 55 dart.fn(f, VoidTodynamic()); |
| 56 return dart.dsend(dart.dsend(f(), 'toList'), 'then', dart.fn(v => { |
| 57 src__matcher__expect.expect(v, src__matcher__core_matchers.equals(JSAr
rayOfint().of([42]))); |
| 58 }, dynamicTodynamic())); |
| 59 }, VoidTodynamic())); |
| 60 unittest$.test("call delays", dart.fn(() => { |
| 61 let list = []; |
| 62 function f() { |
| 63 return dart.asyncStar(function*(stream) { |
| 64 list[dartx.add](1); |
| 65 if (stream.add(2)) return; |
| 66 yield; |
| 67 }, dart.dynamic); |
| 68 } |
| 69 dart.fn(f, VoidTodynamic()); |
| 70 let res = dart.dsend(f(), 'forEach', dart.fn(x => list[dartx.add](x), dy
namicTovoid())); |
| 71 list[dartx.add](0); |
| 72 return dart.dsend(res, 'whenComplete', dart.fn(() => { |
| 73 src__matcher__expect.expect(list, src__matcher__core_matchers.equals(J
SArrayOfint().of([0, 1, 2]))); |
| 74 }, VoidTodynamic())); |
| 75 }, VoidTodynamic())); |
| 76 unittest$.test("throws", dart.fn(() => { |
| 77 function f() { |
| 78 return dart.asyncStar(function*(stream) { |
| 79 if (stream.add(1)) return; |
| 80 yield; |
| 81 dart.throw(2); |
| 82 }, dart.dynamic); |
| 83 } |
| 84 dart.fn(f, VoidTodynamic()); |
| 85 let completer = async.Completer.new(); |
| 86 let list = []; |
| 87 dart.dsend(f(), 'listen', dart.fn(x => list[dartx.add](x), dynamicTovoid
()), {onError: dart.fn(v => list[dartx.add](dart.str`${v}`), dynamicTovoid()), o
nDone: dart.bind(completer, 'complete')}); |
| 88 return completer.future.whenComplete(dart.fn(() => { |
| 89 src__matcher__expect.expect(list, src__matcher__core_matchers.equals(J
SArrayOfObject().of([1, "2"]))); |
| 90 }, VoidTodynamic())); |
| 91 }, VoidToFuture())); |
| 92 unittest$.test("multiple", dart.fn(() => { |
| 93 function f() { |
| 94 return dart.asyncStar(function*(stream) { |
| 95 for (let i = 0; i < 10; i++) { |
| 96 if (stream.add(i)) return; |
| 97 yield; |
| 98 } |
| 99 }, dart.dynamic); |
| 100 } |
| 101 dart.fn(f, VoidTodynamic()); |
| 102 return async_star_test_04_multi.expectList(f(), core.List.generate(10, a
sync_star_test_04_multi.id)); |
| 103 }, VoidTodynamic())); |
| 104 unittest$.test("allows await", dart.fn(() => { |
| 105 function f() { |
| 106 return dart.asyncStar(function*(stream) { |
| 107 let x = (yield async.Future.value(42)); |
| 108 if (stream.add(x)) return; |
| 109 yield; |
| 110 x = (yield async.Future.value(42)); |
| 111 }, dart.dynamic); |
| 112 } |
| 113 dart.fn(f, VoidTodynamic()); |
| 114 return async_star_test_04_multi.expectList(f(), JSArrayOfint().of([42]))
; |
| 115 }, VoidTodynamic())); |
| 116 unittest$.test("allows await in loop", dart.fn(() => { |
| 117 function f() { |
| 118 return dart.asyncStar(function*(stream) { |
| 119 for (let i = 0; i < 10; i++) { |
| 120 if (stream.add(yield i)) return; |
| 121 yield; |
| 122 } |
| 123 }, dart.dynamic); |
| 124 } |
| 125 dart.fn(f, VoidTodynamic()); |
| 126 return async_star_test_04_multi.expectList(f(), core.List.generate(10, a
sync_star_test_04_multi.id)); |
| 127 }, VoidTodynamic())); |
| 128 unittest$.test("allows yield*", dart.fn(() => { |
| 129 function f() { |
| 130 return dart.asyncStar(function*(stream) { |
| 131 if (stream.addStream(async.Stream.fromIterable(JSArrayOfint().of([1,
2, 3])))) return; |
| 132 yield; |
| 133 }, dart.dynamic); |
| 134 } |
| 135 dart.fn(f, VoidTodynamic()); |
| 136 return async_star_test_04_multi.expectList(f(), JSArrayOfint().of([1, 2,
3])); |
| 137 }, VoidTodynamic())); |
| 138 unittest$.test("allows yield* of async*", dart.fn(() => { |
| 139 function f(n) { |
| 140 return dart.asyncStar(function*(stream, n) { |
| 141 if (stream.add(n)) return; |
| 142 yield; |
| 143 if (dart.equals(n, 0)) return; |
| 144 if (stream.addStream(async.Stream._check(f(dart.dsend(n, '-', 1)))))
return; |
| 145 yield; |
| 146 if (stream.add(n)) return; |
| 147 yield; |
| 148 }, dart.dynamic, n); |
| 149 } |
| 150 dart.fn(f, dynamicTodynamic()); |
| 151 return async_star_test_04_multi.expectList(f(3), JSArrayOfint().of([3, 2
, 1, 0, 1, 2, 3])); |
| 152 }, VoidTodynamic())); |
| 153 unittest$.test("Cannot yield* non-stream", dart.fn(() => { |
| 154 function f(s) { |
| 155 return dart.asyncStar(function*(stream, s) { |
| 156 if (stream.addStream(async.Stream._check(s))) return; |
| 157 yield; |
| 158 }, dart.dynamic, s); |
| 159 } |
| 160 dart.fn(f, dynamicTodynamic()); |
| 161 return dart.dsend(dart.dload(dart.dsend(f(42), 'transform', async_star_t
est_04_multi.getErrors), 'single'), 'then', dart.fn(v => { |
| 162 src__matcher__expect.expect(core.Error.is(v), src__matcher__core_match
ers.isTrue); |
| 163 }, dynamicTodynamic())); |
| 164 }, VoidTodynamic())); |
| 165 unittest$.test("Cannot yield* non-stream", dart.fn(() => { |
| 166 function f(s) { |
| 167 return dart.asyncStar(function*(stream, s) { |
| 168 if (stream.addStream(async.Stream._check(s))) return; |
| 169 yield; |
| 170 }, dart.dynamic, s); |
| 171 } |
| 172 dart.fn(f, dynamicTodynamic()); |
| 173 return dart.dsend(dart.dload(dart.dsend(f(new async_star_test_04_multi.N
otAStream()), 'transform', async_star_test_04_multi.getErrors), 'single'), 'then
', dart.fn(v => { |
| 174 src__matcher__expect.expect(core.Error.is(v), src__matcher__core_match
ers.isTrue); |
| 175 }, dynamicTodynamic())); |
| 176 }, VoidTodynamic())); |
| 177 }, VoidTovoid())); |
| 178 unittest$.group("yield statement context", dart.fn(() => { |
| 179 unittest$.test("plain", dart.fn(() => { |
| 180 function f() { |
| 181 return dart.asyncStar(function*(stream) { |
| 182 if (stream.add(0)) return; |
| 183 yield; |
| 184 }, dart.dynamic); |
| 185 } |
| 186 dart.fn(f, VoidTodynamic()); |
| 187 return async_star_test_04_multi.expectList(f(), JSArrayOfint().of([0])); |
| 188 }, VoidTodynamic())); |
| 189 unittest$.test("if-then-else", dart.fn(() => { |
| 190 function f(b) { |
| 191 return dart.asyncStar(function*(stream, b) { |
| 192 if (dart.test(b)) { |
| 193 if (stream.add(0)) return; |
| 194 yield; |
| 195 } else { |
| 196 if (stream.add(1)) return; |
| 197 yield; |
| 198 } |
| 199 }, dart.dynamic, b); |
| 200 } |
| 201 dart.fn(f, dynamicTodynamic()); |
| 202 return dart.dsend(async_star_test_04_multi.expectList(f(true), JSArrayOf
int().of([0])), 'whenComplete', dart.fn(() => { |
| 203 async_star_test_04_multi.expectList(f(false), JSArrayOfint().of([1])); |
| 204 }, VoidTodynamic())); |
| 205 }, VoidTodynamic())); |
| 206 unittest$.test("block", dart.fn(() => { |
| 207 function f() { |
| 208 return dart.asyncStar(function*(stream) { |
| 209 if (stream.add(0)) return; |
| 210 yield; |
| 211 { |
| 212 if (stream.add(1)) return; |
| 213 yield; |
| 214 } |
| 215 if (stream.add(2)) return; |
| 216 yield; |
| 217 }, dart.dynamic); |
| 218 } |
| 219 dart.fn(f, VoidTodynamic()); |
| 220 return async_star_test_04_multi.expectList(f(), JSArrayOfint().of([0, 1,
2])); |
| 221 }, VoidTodynamic())); |
| 222 unittest$.test("labeled", dart.fn(() => { |
| 223 function f() { |
| 224 return dart.asyncStar(function*(stream) { |
| 225 label1: { |
| 226 if (stream.add(0)) return; |
| 227 yield; |
| 228 } |
| 229 }, dart.dynamic); |
| 230 } |
| 231 dart.fn(f, VoidTodynamic()); |
| 232 return async_star_test_04_multi.expectList(f(), JSArrayOfint().of([0])); |
| 233 }, VoidTodynamic())); |
| 234 unittest$.test("for-loop", dart.fn(() => { |
| 235 function f() { |
| 236 return dart.asyncStar(function*(stream) { |
| 237 for (let i = 0; i < 3; i++) { |
| 238 if (stream.add(i)) return; |
| 239 yield; |
| 240 } |
| 241 }, dart.dynamic); |
| 242 } |
| 243 dart.fn(f, VoidTodynamic()); |
| 244 return async_star_test_04_multi.expectList(f(), JSArrayOfint().of([0, 1,
2])); |
| 245 }, VoidTodynamic())); |
| 246 unittest$.test("for-in-loop", dart.fn(() => { |
| 247 function f() { |
| 248 return dart.asyncStar(function*(stream) { |
| 249 for (let i of JSArrayOfint().of([0, 1, 2])) { |
| 250 if (stream.add(i)) return; |
| 251 yield; |
| 252 } |
| 253 }, dart.dynamic); |
| 254 } |
| 255 dart.fn(f, VoidTodynamic()); |
| 256 return async_star_test_04_multi.expectList(f(), JSArrayOfint().of([0, 1,
2])); |
| 257 }, VoidTodynamic())); |
| 258 unittest$.test("await for-in-loop", dart.fn(() => { |
| 259 function f() { |
| 260 return dart.asyncStar(function*(stream) { |
| 261 let it = async.StreamIterator.new(async.Stream.fromIterable(JSArrayO
fint().of([0, 1, 2]))); |
| 262 try { |
| 263 while (yield it.moveNext()) { |
| 264 let i = it.current; |
| 265 if (stream.add(i)) return; |
| 266 yield; |
| 267 } |
| 268 } finally { |
| 269 yield it.cancel(); |
| 270 } |
| 271 }, dart.dynamic); |
| 272 } |
| 273 dart.fn(f, VoidTodynamic()); |
| 274 return async_star_test_04_multi.expectList(f(), JSArrayOfint().of([0, 1,
2])); |
| 275 }, VoidTodynamic())); |
| 276 unittest$.test("while-loop", dart.fn(() => { |
| 277 function f() { |
| 278 return dart.asyncStar(function*(stream) { |
| 279 let i = 0; |
| 280 while (i < 3) { |
| 281 if (stream.add(i++)) return; |
| 282 yield; |
| 283 } |
| 284 }, dart.dynamic); |
| 285 } |
| 286 dart.fn(f, VoidTodynamic()); |
| 287 return async_star_test_04_multi.expectList(f(), JSArrayOfint().of([0, 1,
2])); |
| 288 }, VoidTodynamic())); |
| 289 unittest$.test("do-while-loop", dart.fn(() => { |
| 290 function f() { |
| 291 return dart.asyncStar(function*(stream) { |
| 292 let i = 0; |
| 293 do { |
| 294 if (stream.add(i++)) return; |
| 295 yield; |
| 296 } while (i < 3); |
| 297 }, dart.dynamic); |
| 298 } |
| 299 dart.fn(f, VoidTodynamic()); |
| 300 return async_star_test_04_multi.expectList(f(), JSArrayOfint().of([0, 1,
2])); |
| 301 }, VoidTodynamic())); |
| 302 unittest$.test("try-catch-finally", dart.fn(() => { |
| 303 function f() { |
| 304 return dart.asyncStar(function*(stream) { |
| 305 try { |
| 306 if (stream.add(0)) return; |
| 307 yield; |
| 308 } catch (e) { |
| 309 if (stream.add(1)) return; |
| 310 yield; |
| 311 } |
| 312 finally { |
| 313 if (stream.add(2)) return; |
| 314 yield; |
| 315 } |
| 316 }, dart.dynamic); |
| 317 } |
| 318 dart.fn(f, VoidTodynamic()); |
| 319 return async_star_test_04_multi.expectList(f(), JSArrayOfint().of([0, 2]
)); |
| 320 }, VoidTodynamic())); |
| 321 unittest$.test("try-catch-finally 2", dart.fn(() => { |
| 322 function f() { |
| 323 return dart.asyncStar(function*(stream) { |
| 324 try { |
| 325 if (stream.add(dart.throw(0))) return; |
| 326 yield; |
| 327 } catch (e) { |
| 328 if (stream.add(1)) return; |
| 329 yield; |
| 330 } |
| 331 finally { |
| 332 if (stream.add(2)) return; |
| 333 yield; |
| 334 } |
| 335 }, dart.dynamic); |
| 336 } |
| 337 dart.fn(f, VoidTodynamic()); |
| 338 return async_star_test_04_multi.expectList(f(), JSArrayOfint().of([1, 2]
)); |
| 339 }, VoidTodynamic())); |
| 340 unittest$.test("dead-code return", dart.fn(() => { |
| 341 function f() { |
| 342 return dart.asyncStar(function*(stream) { |
| 343 return; |
| 344 if (stream.add(1)) return; |
| 345 yield; |
| 346 }, dart.dynamic); |
| 347 } |
| 348 dart.fn(f, VoidTodynamic()); |
| 349 return async_star_test_04_multi.expectList(f(), []); |
| 350 }, VoidTodynamic())); |
| 351 unittest$.test("dead-code throw", dart.fn(() => { |
| 352 function f() { |
| 353 return dart.asyncStar(function*(stream) { |
| 354 try { |
| 355 dart.throw(0); |
| 356 if (stream.add(1)) return; |
| 357 yield; |
| 358 } catch (_) { |
| 359 } |
| 360 |
| 361 }, dart.dynamic); |
| 362 } |
| 363 dart.fn(f, VoidTodynamic()); |
| 364 return async_star_test_04_multi.expectList(f(), []); |
| 365 }, VoidTodynamic())); |
| 366 unittest$.test("dead-code break", dart.fn(() => { |
| 367 function f() { |
| 368 return dart.asyncStar(function*(stream) { |
| 369 while (true) { |
| 370 break; |
| 371 if (stream.add(1)) return; |
| 372 yield; |
| 373 } |
| 374 }, dart.dynamic); |
| 375 } |
| 376 dart.fn(f, VoidTodynamic()); |
| 377 return async_star_test_04_multi.expectList(f(), []); |
| 378 }, VoidTodynamic())); |
| 379 unittest$.test("dead-code break 2", dart.fn(() => { |
| 380 function f() { |
| 381 return dart.asyncStar(function*(stream) { |
| 382 label: { |
| 383 break label; |
| 384 if (stream.add(1)) return; |
| 385 yield; |
| 386 } |
| 387 }, dart.dynamic); |
| 388 } |
| 389 dart.fn(f, VoidTodynamic()); |
| 390 return async_star_test_04_multi.expectList(f(), []); |
| 391 }, VoidTodynamic())); |
| 392 unittest$.test("dead-code continue", dart.fn(() => { |
| 393 function f() { |
| 394 return dart.asyncStar(function*(stream) { |
| 395 do { |
| 396 continue; |
| 397 if (stream.add(1)) return; |
| 398 yield; |
| 399 } while (false); |
| 400 }, dart.dynamic); |
| 401 } |
| 402 dart.fn(f, VoidTodynamic()); |
| 403 return async_star_test_04_multi.expectList(f(), []); |
| 404 }, VoidTodynamic())); |
| 405 }, VoidTovoid())); |
| 406 unittest$.group("yield expressions", dart.fn(() => { |
| 407 unittest$.test("local variable", dart.fn(() => { |
| 408 function f() { |
| 409 return dart.asyncStar(function*(stream) { |
| 410 let x = 42; |
| 411 if (stream.add(x)) return; |
| 412 yield; |
| 413 }, dart.dynamic); |
| 414 } |
| 415 dart.fn(f, VoidTodynamic()); |
| 416 return async_star_test_04_multi.expectList(f(), JSArrayOfint().of([42]))
; |
| 417 }, VoidTodynamic())); |
| 418 unittest$.test("constant variable", dart.fn(() => { |
| 419 function f() { |
| 420 return dart.asyncStar(function*(stream) { |
| 421 let x = 42; |
| 422 if (stream.add(x)) return; |
| 423 yield; |
| 424 }, dart.dynamic); |
| 425 } |
| 426 dart.fn(f, VoidTodynamic()); |
| 427 return async_star_test_04_multi.expectList(f(), JSArrayOfint().of([42]))
; |
| 428 }, VoidTodynamic())); |
| 429 unittest$.test("function call", dart.fn(() => { |
| 430 function g() { |
| 431 return 42; |
| 432 } |
| 433 dart.fn(g, VoidTodynamic()); |
| 434 function f() { |
| 435 return dart.asyncStar(function*(stream) { |
| 436 if (stream.add(g())) return; |
| 437 yield; |
| 438 }, dart.dynamic); |
| 439 } |
| 440 dart.fn(f, VoidTodynamic()); |
| 441 return async_star_test_04_multi.expectList(f(), JSArrayOfint().of([42]))
; |
| 442 }, VoidTodynamic())); |
| 443 unittest$.test("unary operator", dart.fn(() => { |
| 444 function f() { |
| 445 return dart.asyncStar(function*(stream) { |
| 446 let x = -42; |
| 447 if (stream.add(-x)) return; |
| 448 yield; |
| 449 }, dart.dynamic); |
| 450 } |
| 451 dart.fn(f, VoidTodynamic()); |
| 452 return async_star_test_04_multi.expectList(f(), JSArrayOfint().of([42]))
; |
| 453 }, VoidTodynamic())); |
| 454 unittest$.test("binary operator", dart.fn(() => { |
| 455 function f() { |
| 456 return dart.asyncStar(function*(stream) { |
| 457 let x = 21; |
| 458 if (stream.add(x + x)) return; |
| 459 yield; |
| 460 }, dart.dynamic); |
| 461 } |
| 462 dart.fn(f, VoidTodynamic()); |
| 463 return async_star_test_04_multi.expectList(f(), JSArrayOfint().of([42]))
; |
| 464 }, VoidTodynamic())); |
| 465 unittest$.test("ternary operator", dart.fn(() => { |
| 466 function f() { |
| 467 return dart.asyncStar(function*(stream) { |
| 468 let x = 21; |
| 469 if (stream.add(x == 21 ? x + x : x)) return; |
| 470 yield; |
| 471 }, dart.dynamic); |
| 472 } |
| 473 dart.fn(f, VoidTodynamic()); |
| 474 return async_star_test_04_multi.expectList(f(), JSArrayOfint().of([42]))
; |
| 475 }, VoidTodynamic())); |
| 476 unittest$.test("suffix post-increment", dart.fn(() => { |
| 477 function f() { |
| 478 return dart.asyncStar(function*(stream) { |
| 479 let x = 42; |
| 480 if (stream.add(x++)) return; |
| 481 yield; |
| 482 }, dart.dynamic); |
| 483 } |
| 484 dart.fn(f, VoidTodynamic()); |
| 485 return async_star_test_04_multi.expectList(f(), JSArrayOfint().of([42]))
; |
| 486 }, VoidTodynamic())); |
| 487 unittest$.test("suffix pre-increment", dart.fn(() => { |
| 488 function f() { |
| 489 return dart.asyncStar(function*(stream) { |
| 490 let x = 41; |
| 491 if (stream.add(++x)) return; |
| 492 yield; |
| 493 }, dart.dynamic); |
| 494 } |
| 495 dart.fn(f, VoidTodynamic()); |
| 496 return async_star_test_04_multi.expectList(f(), JSArrayOfint().of([42]))
; |
| 497 }, VoidTodynamic())); |
| 498 unittest$.test("assignment", dart.fn(() => { |
| 499 function f() { |
| 500 return dart.asyncStar(function*(stream) { |
| 501 let x = 37; |
| 502 if (stream.add(x = 42)) return; |
| 503 yield; |
| 504 }, dart.dynamic); |
| 505 } |
| 506 dart.fn(f, VoidTodynamic()); |
| 507 return async_star_test_04_multi.expectList(f(), JSArrayOfint().of([42]))
; |
| 508 }, VoidTodynamic())); |
| 509 unittest$.test("assignment op", dart.fn(() => { |
| 510 function f() { |
| 511 return dart.asyncStar(function*(stream) { |
| 512 let x = 41; |
| 513 if (stream.add((x = x + 1))) return; |
| 514 yield; |
| 515 }, dart.dynamic); |
| 516 } |
| 517 dart.fn(f, VoidTodynamic()); |
| 518 return async_star_test_04_multi.expectList(f(), JSArrayOfint().of([42]))
; |
| 519 }, VoidTodynamic())); |
| 520 unittest$.test("await", dart.fn(() => { |
| 521 function f() { |
| 522 return dart.asyncStar(function*(stream) { |
| 523 if (stream.add(yield async.Future.value(42))) return; |
| 524 yield; |
| 525 }, dart.dynamic); |
| 526 } |
| 527 dart.fn(f, VoidTodynamic()); |
| 528 return async_star_test_04_multi.expectList(f(), JSArrayOfint().of([42]))
; |
| 529 }, VoidTodynamic())); |
| 530 unittest$.test("index operator", dart.fn(() => { |
| 531 function f() { |
| 532 return dart.asyncStar(function*(stream) { |
| 533 let x = JSArrayOfint().of([42]); |
| 534 if (stream.add(x[dartx.get](0))) return; |
| 535 yield; |
| 536 }, dart.dynamic); |
| 537 } |
| 538 dart.fn(f, VoidTodynamic()); |
| 539 return async_star_test_04_multi.expectList(f(), JSArrayOfint().of([42]))
; |
| 540 }, VoidTodynamic())); |
| 541 unittest$.test("function expression block", dart.fn(() => { |
| 542 let o = new core.Object(); |
| 543 function f() { |
| 544 return dart.asyncStar(function*(stream) { |
| 545 if (stream.add(dart.fn(() => o, VoidToObject()))) return; |
| 546 yield; |
| 547 }, dart.dynamic); |
| 548 } |
| 549 dart.fn(f, VoidTodynamic()); |
| 550 return dart.dsend(dart.dload(f(), 'first'), 'then', dart.fn(v => { |
| 551 src__matcher__expect.expect(dart.dcall(v), src__matcher__core_matchers
.same(o)); |
| 552 }, dynamicTodynamic())); |
| 553 }, VoidTodynamic())); |
| 554 unittest$.test("function expression arrow", dart.fn(() => { |
| 555 let o = new core.Object(); |
| 556 function f() { |
| 557 return dart.asyncStar(function*(stream) { |
| 558 if (stream.add(dart.fn(() => o, VoidToObject()))) return; |
| 559 yield; |
| 560 }, dart.dynamic); |
| 561 } |
| 562 dart.fn(f, VoidTodynamic()); |
| 563 return dart.dsend(dart.dload(f(), 'first'), 'then', dart.fn(v => { |
| 564 src__matcher__expect.expect(dart.dcall(v), src__matcher__core_matchers
.same(o)); |
| 565 }, dynamicTodynamic())); |
| 566 }, VoidTodynamic())); |
| 567 unittest$.test("function expression block async", dart.fn(() => { |
| 568 let o = new core.Object(); |
| 569 function f() { |
| 570 return dart.asyncStar(function*(stream) { |
| 571 if (stream.add(dart.fn(() => dart.async(function*() { |
| 572 return o; |
| 573 }, core.Object), VoidToFutureOfObject()))) return; |
| 574 yield; |
| 575 }, dart.dynamic); |
| 576 } |
| 577 dart.fn(f, VoidTodynamic()); |
| 578 return dart.dsend(dart.dsend(dart.dload(f(), 'first'), 'then', dart.fn(v
=> dart.dcall(v), dynamicTodynamic())), 'then', dart.fn(v => { |
| 579 src__matcher__expect.expect(v, src__matcher__core_matchers.same(o)); |
| 580 }, dynamicTodynamic())); |
| 581 }, VoidTodynamic())); |
| 582 unittest$.test("function expression arrow async", dart.fn(() => { |
| 583 let o = new core.Object(); |
| 584 function f() { |
| 585 return dart.asyncStar(function*(stream) { |
| 586 if (stream.add(dart.fn(() => dart.async(function*() { |
| 587 return o; |
| 588 }, core.Object), VoidToFutureOfObject()))) return; |
| 589 yield; |
| 590 }, dart.dynamic); |
| 591 } |
| 592 dart.fn(f, VoidTodynamic()); |
| 593 return dart.dsend(dart.dsend(dart.dload(f(), 'first'), 'then', dart.fn(v
=> dart.dcall(v), dynamicTodynamic())), 'then', dart.fn(v => { |
| 594 src__matcher__expect.expect(v, src__matcher__core_matchers.same(o)); |
| 595 }, dynamicTodynamic())); |
| 596 }, VoidTodynamic())); |
| 597 unittest$.test("function expression block async*", dart.fn(() => { |
| 598 let o = new core.Object(); |
| 599 function f() { |
| 600 return dart.asyncStar(function*(stream) { |
| 601 if (stream.add(dart.fn(() => dart.asyncStar(function*(stream) { |
| 602 if (stream.add(o)) return; |
| 603 yield; |
| 604 }, core.Object), VoidToStreamOfObject()))) return; |
| 605 yield; |
| 606 }, dart.dynamic); |
| 607 } |
| 608 dart.fn(f, VoidTodynamic()); |
| 609 return dart.dsend(dart.dsend(dart.dload(f(), 'first'), 'then', dart.fn(v
=> dart.dload(dart.dcall(v), 'first'), dynamicTodynamic())), 'then', dart.fn(v
=> { |
| 610 src__matcher__expect.expect(v, src__matcher__core_matchers.same(o)); |
| 611 }, dynamicTodynamic())); |
| 612 }, VoidTodynamic())); |
| 613 }, VoidTovoid())); |
| 614 unittest$.group("loops", dart.fn(() => { |
| 615 unittest$.test("simple yield", dart.fn(() => { |
| 616 function f() { |
| 617 return dart.asyncStar(function*(stream) { |
| 618 for (let i = 0; i < 3; i++) { |
| 619 if (stream.add(i)) return; |
| 620 yield; |
| 621 } |
| 622 }, dart.dynamic); |
| 623 } |
| 624 dart.fn(f, VoidTodynamic()); |
| 625 return async_star_test_04_multi.expectList(f(), JSArrayOfint().of([0, 1,
2])); |
| 626 }, VoidTodynamic())); |
| 627 unittest$.test("yield in double loop", dart.fn(() => { |
| 628 function f() { |
| 629 return dart.asyncStar(function*(stream) { |
| 630 for (let i = 0; i < 3; i++) { |
| 631 for (let j = 0; j < 2; j++) { |
| 632 if (stream.add(i * 2 + j)) return; |
| 633 yield; |
| 634 } |
| 635 } |
| 636 }, dart.dynamic); |
| 637 } |
| 638 dart.fn(f, VoidTodynamic()); |
| 639 return async_star_test_04_multi.expectList(f(), JSArrayOfint().of([0, 1,
2, 3, 4, 5])); |
| 640 }, VoidTodynamic())); |
| 641 unittest$.test("yield in try body", dart.fn(() => { |
| 642 let list = []; |
| 643 function f() { |
| 644 return dart.asyncStar(function*(stream) { |
| 645 for (let i = 0; i < 3; i++) { |
| 646 try { |
| 647 if (stream.add(i)) return; |
| 648 yield; |
| 649 } finally { |
| 650 list[dartx.add](dart.str`${i}`); |
| 651 } |
| 652 } |
| 653 }, dart.dynamic); |
| 654 } |
| 655 dart.fn(f, VoidTodynamic()); |
| 656 return dart.dsend(async_star_test_04_multi.expectList(f(), JSArrayOfint(
).of([0, 1, 2])), 'whenComplete', dart.fn(() => { |
| 657 src__matcher__expect.expect(list, src__matcher__core_matchers.equals(J
SArrayOfString().of(["0", "1", "2"]))); |
| 658 }, VoidTodynamic())); |
| 659 }, VoidTodynamic())); |
| 660 unittest$.test("yield in catch", dart.fn(() => { |
| 661 let list = []; |
| 662 function f() { |
| 663 return dart.asyncStar(function*(stream) { |
| 664 for (let i = 0; i < 3; i++) { |
| 665 try { |
| 666 dart.throw(i); |
| 667 } catch (e) { |
| 668 if (stream.add(e)) return; |
| 669 yield; |
| 670 } |
| 671 finally { |
| 672 list[dartx.add](dart.str`${i}`); |
| 673 } |
| 674 } |
| 675 }, dart.dynamic); |
| 676 } |
| 677 dart.fn(f, VoidTodynamic()); |
| 678 return dart.dsend(async_star_test_04_multi.expectList(f(), JSArrayOfint(
).of([0, 1, 2])), 'whenComplete', dart.fn(() => { |
| 679 src__matcher__expect.expect(list, src__matcher__core_matchers.equals(J
SArrayOfString().of(["0", "1", "2"]))); |
| 680 }, VoidTodynamic())); |
| 681 }, VoidTodynamic())); |
| 682 unittest$.test("yield in finally", dart.fn(() => { |
| 683 let list = []; |
| 684 function f() { |
| 685 return dart.asyncStar(function*(stream) { |
| 686 for (let i = 0; i < 3; i++) { |
| 687 try { |
| 688 dart.throw(i); |
| 689 } finally { |
| 690 if (stream.add(i)) return; |
| 691 yield; |
| 692 list[dartx.add](dart.str`${i}`); |
| 693 continue; |
| 694 } |
| 695 } |
| 696 }, dart.dynamic); |
| 697 } |
| 698 dart.fn(f, VoidTodynamic()); |
| 699 return dart.dsend(async_star_test_04_multi.expectList(f(), JSArrayOfint(
).of([0, 1, 2])), 'whenComplete', dart.fn(() => { |
| 700 src__matcher__expect.expect(list, src__matcher__core_matchers.equals(J
SArrayOfString().of(["0", "1", "2"]))); |
| 701 }, VoidTodynamic())); |
| 702 }, VoidTodynamic())); |
| 703 unittest$.test("keep yielding after cancel", dart.fn(() => { |
| 704 function f() { |
| 705 return dart.asyncStar(function*(stream) { |
| 706 for (let i = 0; i < 10; i++) { |
| 707 try { |
| 708 if (stream.add(i)) return; |
| 709 yield; |
| 710 } finally { |
| 711 continue; |
| 712 } |
| 713 } |
| 714 }, dart.dynamic); |
| 715 } |
| 716 dart.fn(f, VoidTodynamic()); |
| 717 return async_star_test_04_multi.expectList(dart.dsend(f(), 'take', 3), J
SArrayOfint().of([0, 1, 2])); |
| 718 }, VoidTodynamic())); |
| 719 }, VoidTovoid())); |
| 720 unittest$.group("canceling", dart.fn(() => { |
| 721 unittest$.test("cancels at yield", dart.fn(() => { |
| 722 let exits = async.Completer.new(); |
| 723 let list = []; |
| 724 function f() { |
| 725 return dart.asyncStar(function*(stream) { |
| 726 try { |
| 727 list[dartx.add](0); |
| 728 if (stream.add(list[dartx.add](1))) return; |
| 729 yield; |
| 730 list[dartx.add](2); |
| 731 } finally { |
| 732 exits.complete(3); |
| 733 } |
| 734 }, dart.dynamic); |
| 735 } |
| 736 dart.fn(f, VoidTodynamic()); |
| 737 let subscription = dart.dsend(f(), 'listen', dart.fn(v => { |
| 738 src__matcher__expect.fail(dart.str`Received event ${v}`); |
| 739 }, dynamicTodynamic()), {onDone: dart.fn(() => { |
| 740 src__matcher__expect.fail("Received done"); |
| 741 }, VoidTodynamic())}); |
| 742 dart.dsend(subscription, 'cancel'); |
| 743 return exits.future.then(dart.dynamic)(dart.fn(v => { |
| 744 src__matcher__expect.expect(v, src__matcher__core_matchers.equals(3)); |
| 745 src__matcher__expect.expect(list, src__matcher__core_matchers.equals(J
SArrayOfint().of([0, 1]))); |
| 746 }, dynamicTodynamic())); |
| 747 }, VoidToFuture())); |
| 748 unittest$.test("does cancel eventually", dart.fn(() => { |
| 749 let exits = async.Completer.new(); |
| 750 let list = []; |
| 751 function f() { |
| 752 return dart.asyncStar(function*(stream) { |
| 753 let i = 0; |
| 754 try { |
| 755 while (true) { |
| 756 if (stream.add(i++)) return; |
| 757 yield; |
| 758 } |
| 759 } finally { |
| 760 list[dartx.add]("a"); |
| 761 exits.complete(i); |
| 762 } |
| 763 }, dart.dynamic); |
| 764 } |
| 765 dart.fn(f, VoidTodynamic()); |
| 766 return dart.dsend(dart.dsend(async_star_test_04_multi.expectList(dart.ds
end(f(), 'take', 5), JSArrayOfint().of([0, 1, 2, 3, 4])), 'then', dart.fn(_ => e
xits.future, dynamicToFuture())), 'then', dart.fn(v => { |
| 767 src__matcher__expect.expect(v, src__matcher__numeric_matchers.greaterT
han(4)); |
| 768 src__matcher__expect.expect(list, JSArrayOfString().of(["a"])); |
| 769 }, dynamicTodynamic())); |
| 770 }, VoidTodynamic())); |
| 771 unittest$.group("at index", dart.fn(() => { |
| 772 function f() { |
| 773 return dart.asyncStar(function*(stream) { |
| 774 try { |
| 775 if (stream.add(yield async.Future.microtask(dart.fn(() => 1, VoidT
oint())))) return; |
| 776 yield; |
| 777 } finally { |
| 778 try { |
| 779 if (stream.add(yield async.Future.microtask(dart.fn(() => 2, Voi
dToint())))) return; |
| 780 yield; |
| 781 } finally { |
| 782 if (stream.add(yield async.Future.microtask(dart.fn(() => 3, Voi
dToint())))) return; |
| 783 yield; |
| 784 } |
| 785 } |
| 786 }, dart.dynamic); |
| 787 } |
| 788 dart.fn(f, VoidTodynamic()); |
| 789 unittest$.test("- all, sanity check", dart.fn(() => async_star_test_04_m
ulti.expectList(f(), JSArrayOfint().of([1, 2, 3])), VoidTodynamic())); |
| 790 unittest$.test("after end", dart.fn(() => async_star_test_04_multi.expec
tList(dart.dsend(f(), 'take', 4), JSArrayOfint().of([1, 2, 3])), VoidTodynamic()
)); |
| 791 unittest$.test("at end", dart.fn(() => async_star_test_04_multi.expectLi
st(dart.dsend(f(), 'take', 3), JSArrayOfint().of([1, 2, 3])), VoidTodynamic())); |
| 792 unittest$.test("before end", dart.fn(() => async_star_test_04_multi.expe
ctList(dart.dsend(f(), 'take', 2), JSArrayOfint().of([1, 2])), VoidTodynamic()))
; |
| 793 unittest$.test("early", dart.fn(() => async_star_test_04_multi.expectLis
t(dart.dsend(f(), 'take', 1), JSArrayOfint().of([1])), VoidTodynamic())); |
| 794 unittest$.test("at start", dart.fn(() => async_star_test_04_multi.expect
List(dart.dsend(f(), 'take', 0), []), VoidTodynamic())); |
| 795 }, VoidTovoid())); |
| 796 }, VoidTovoid())); |
| 797 unittest$.group("pausing", dart.fn(() => { |
| 798 unittest$.test("pauses execution at yield for at least a microtask", dart.
fn(() => { |
| 799 let list = []; |
| 800 function f() { |
| 801 return dart.asyncStar(function*(stream) { |
| 802 list[dartx.add](1); |
| 803 if (stream.add(2)) return; |
| 804 yield; |
| 805 list[dartx.add](3); |
| 806 if (stream.add(4)) return; |
| 807 yield; |
| 808 list[dartx.add](5); |
| 809 }, dart.dynamic); |
| 810 } |
| 811 dart.fn(f, VoidTodynamic()); |
| 812 let done = async.Completer.new(); |
| 813 let sub = dart.dsend(f(), 'listen', dart.fn(v => { |
| 814 if (dart.equals(v, 2)) { |
| 815 src__matcher__expect.expect(list, src__matcher__core_matchers.equals
(JSArrayOfint().of([1]))); |
| 816 } else if (dart.equals(v, 4)) { |
| 817 src__matcher__expect.expect(list, src__matcher__core_matchers.equals
(JSArrayOfint().of([1, 3]))); |
| 818 } else { |
| 819 src__matcher__expect.fail(dart.str`Unexpected value ${v}`); |
| 820 } |
| 821 }, dynamicTodynamic()), {onDone: dart.fn(() => { |
| 822 src__matcher__expect.expect(list, src__matcher__core_matchers.equals
(JSArrayOfint().of([1, 3, 5]))); |
| 823 done.complete(); |
| 824 }, VoidTodynamic())}); |
| 825 return done.future; |
| 826 }, VoidToFuture())); |
| 827 unittest$.test("pause stops execution at yield", dart.fn(() => { |
| 828 let list = []; |
| 829 function f() { |
| 830 return dart.asyncStar(function*(stream) { |
| 831 list[dartx.add](1); |
| 832 if (stream.add(2)) return; |
| 833 yield; |
| 834 list[dartx.add](3); |
| 835 if (stream.add(4)) return; |
| 836 yield; |
| 837 list[dartx.add](5); |
| 838 }, dart.dynamic); |
| 839 } |
| 840 dart.fn(f, VoidTodynamic()); |
| 841 let done = async.Completer.new(); |
| 842 let sub = null; |
| 843 sub = dart.dsend(f(), 'listen', dart.fn(v => { |
| 844 if (dart.equals(v, 2)) { |
| 845 src__matcher__expect.expect(list, src__matcher__core_matchers.equals
(JSArrayOfint().of([1]))); |
| 846 dart.dsend(sub, 'pause'); |
| 847 async.Timer.new(async_star_test_04_multi.MS['*'](300), dart.fn(() =>
{ |
| 848 src__matcher__expect.expect(list[dartx.length], src__matcher__nume
ric_matchers.lessThan(3)); |
| 849 dart.dsend(sub, 'resume'); |
| 850 }, VoidTovoid())); |
| 851 } else if (dart.equals(v, 4)) { |
| 852 src__matcher__expect.expect(list, src__matcher__core_matchers.equals
(JSArrayOfint().of([1, 3]))); |
| 853 } else { |
| 854 src__matcher__expect.fail(dart.str`Unexpected value ${v}`); |
| 855 } |
| 856 }, dynamicTodynamic()), {onDone: dart.fn(() => { |
| 857 src__matcher__expect.expect(list, src__matcher__core_matchers.equals
(JSArrayOfint().of([1, 3, 5]))); |
| 858 done.complete(); |
| 859 }, VoidTodynamic())}); |
| 860 return done.future; |
| 861 }, VoidToFuture())); |
| 862 unittest$.test("pause stops execution at yield 2", dart.fn(() => { |
| 863 let list = []; |
| 864 function f() { |
| 865 return dart.asyncStar(function*(stream) { |
| 866 let i = 0; |
| 867 while (true) { |
| 868 if (stream.add(i)) return; |
| 869 yield; |
| 870 list[dartx.add](i); |
| 871 i++; |
| 872 } |
| 873 }, dart.dynamic); |
| 874 } |
| 875 dart.fn(f, VoidTodynamic()); |
| 876 let expected = 0; |
| 877 let done = async.Completer.new(); |
| 878 let sub = null; |
| 879 sub = dart.dsend(f(), 'listen', dart.fn(v => { |
| 880 src__matcher__expect.expect(v, src__matcher__core_matchers.equals(expe
cted++)); |
| 881 if (dart.equals(dart.dsend(v, '%', 5), 0)) { |
| 882 dart.dsend(sub, 'pause', async.Future.delayed(async_star_test_04_mul
ti.MS['*'](300))); |
| 883 } else if (dart.equals(v, 17)) { |
| 884 dart.dsend(sub, 'cancel'); |
| 885 done.complete(); |
| 886 } |
| 887 }, dynamicTodynamic()), {onDone: dart.fn(() => { |
| 888 src__matcher__expect.fail("Unexpected done!"); |
| 889 }, VoidTodynamic())}); |
| 890 return done.future.whenComplete(dart.fn(() => { |
| 891 src__matcher__expect.expect(list[dartx.length] == 18 || list[dartx.len
gth] == 19, src__matcher__core_matchers.isTrue); |
| 892 }, VoidTodynamic())); |
| 893 }, VoidToFuture())); |
| 894 }, VoidTovoid())); |
| 895 unittest$.group("await for", dart.fn(() => { |
| 896 function mkStream(n) { |
| 897 return dart.asyncStar(function*(stream, n) { |
| 898 for (let i = 0; i < dart.notNull(n); i++) { |
| 899 if (stream.add(i)) return; |
| 900 yield; |
| 901 } |
| 902 }, dart.dynamic, n); |
| 903 } |
| 904 dart.fn(mkStream, intTodynamic()); |
| 905 unittest$.test("simple stream", dart.fn(() => { |
| 906 function f(s) { |
| 907 return dart.async(function*(s) { |
| 908 let r = 0; |
| 909 let it = async.StreamIterator.new(async.Stream._check(s)); |
| 910 try { |
| 911 while (yield it.moveNext()) { |
| 912 let v = it.current; |
| 913 r = dart.notNull(r) + dart.notNull(core.int._check(v)); |
| 914 } |
| 915 } finally { |
| 916 yield it.cancel(); |
| 917 } |
| 918 return r; |
| 919 }, dart.dynamic, s); |
| 920 } |
| 921 dart.fn(f, dynamicTodynamic()); |
| 922 return dart.dsend(f(mkStream(5)), 'then', dart.fn(v => { |
| 923 src__matcher__expect.expect(v, src__matcher__core_matchers.equals(10))
; |
| 924 }, dynamicTodynamic())); |
| 925 }, VoidTodynamic())); |
| 926 unittest$.test("simple stream, await", dart.fn(() => { |
| 927 function f(s) { |
| 928 return dart.async(function*(s) { |
| 929 let r = 0; |
| 930 let it = async.StreamIterator.new(async.Stream._check(s)); |
| 931 try { |
| 932 while (yield it.moveNext()) { |
| 933 let v = it.current; |
| 934 r = dart.notNull(r) + dart.notNull(core.int._check(yield async.F
uture.microtask(dart.fn(() => v, VoidTodynamic())))); |
| 935 } |
| 936 } finally { |
| 937 yield it.cancel(); |
| 938 } |
| 939 return r; |
| 940 }, dart.dynamic, s); |
| 941 } |
| 942 dart.fn(f, dynamicTodynamic()); |
| 943 return dart.dsend(f(mkStream(5)), 'then', dart.fn(v => { |
| 944 src__matcher__expect.expect(v, src__matcher__core_matchers.equals(10))
; |
| 945 }, dynamicTodynamic())); |
| 946 }, VoidTodynamic())); |
| 947 unittest$.test("simple stream reyield", dart.fn(() => { |
| 948 function f(s) { |
| 949 return dart.asyncStar(function*(stream, s) { |
| 950 let r = 0; |
| 951 let it = async.StreamIterator.new(async.Stream._check(s)); |
| 952 try { |
| 953 while (yield it.moveNext()) { |
| 954 let v = it.current; |
| 955 if (stream.add((r = dart.notNull(r) + dart.notNull(core.int._che
ck(v))))) return; |
| 956 yield; |
| 957 } |
| 958 } finally { |
| 959 yield it.cancel(); |
| 960 } |
| 961 }, dart.dynamic, s); |
| 962 } |
| 963 dart.fn(f, dynamicTodynamic()); |
| 964 return async_star_test_04_multi.expectList(f(mkStream(5)), JSArrayOfint(
).of([0, 1, 3, 6, 10])); |
| 965 }, VoidTodynamic())); |
| 966 unittest$.test("simple stream, await, reyield", dart.fn(() => { |
| 967 function f(s) { |
| 968 return dart.asyncStar(function*(stream, s) { |
| 969 let r = 0; |
| 970 let it = async.StreamIterator.new(async.Stream._check(s)); |
| 971 try { |
| 972 while (yield it.moveNext()) { |
| 973 let v = it.current; |
| 974 if (stream.add((r = dart.notNull(r) + dart.notNull(core.int._che
ck(yield async.Future.microtask(dart.fn(() => v, VoidTodynamic()))))))) return; |
| 975 yield; |
| 976 } |
| 977 } finally { |
| 978 yield it.cancel(); |
| 979 } |
| 980 }, dart.dynamic, s); |
| 981 } |
| 982 dart.fn(f, dynamicTodynamic()); |
| 983 return async_star_test_04_multi.expectList(f(mkStream(5)), JSArrayOfint(
).of([0, 1, 3, 6, 10])); |
| 984 }, VoidTodynamic())); |
| 985 unittest$.test("simple stream - take, reyield", dart.fn(() => { |
| 986 function f(s) { |
| 987 return dart.asyncStar(function*(stream, s) { |
| 988 let r = 0; |
| 989 let it = async.StreamIterator.new(async.Stream._check(dart.dsend(s,
'take', 5))); |
| 990 try { |
| 991 while (yield it.moveNext()) { |
| 992 let v = it.current; |
| 993 if (stream.add((r = dart.notNull(r) + dart.notNull(core.int._che
ck(v))))) return; |
| 994 yield; |
| 995 } |
| 996 } finally { |
| 997 yield it.cancel(); |
| 998 } |
| 999 }, dart.dynamic, s); |
| 1000 } |
| 1001 dart.fn(f, dynamicTodynamic()); |
| 1002 return async_star_test_04_multi.expectList(f(mkStream(10)), JSArrayOfint
().of([0, 1, 3, 6, 10])); |
| 1003 }, VoidTodynamic())); |
| 1004 unittest$.test("nested", dart.fn(() => { |
| 1005 function f() { |
| 1006 return dart.async(function*() { |
| 1007 let r = 0; |
| 1008 let it = async.StreamIterator.new(async.Stream._check(mkStream(5))); |
| 1009 try { |
| 1010 while (yield it.moveNext()) { |
| 1011 let i = it.current; |
| 1012 let it$ = async.StreamIterator.new(async.Stream._check(mkStream(
3))); |
| 1013 try { |
| 1014 while (yield it$.moveNext()) { |
| 1015 let j = it$.current; |
| 1016 r = dart.notNull(r) + dart.notNull(core.int._check(dart.dsen
d(i, '*', j))); |
| 1017 } |
| 1018 } finally { |
| 1019 yield it$.cancel(); |
| 1020 } |
| 1021 } |
| 1022 } finally { |
| 1023 yield it.cancel(); |
| 1024 } |
| 1025 return r; |
| 1026 }, dart.dynamic); |
| 1027 } |
| 1028 dart.fn(f, VoidTodynamic()); |
| 1029 return dart.dsend(f(), 'then', dart.fn(v => { |
| 1030 src__matcher__expect.expect(v, src__matcher__core_matchers.equals((1 +
2 + 3 + 4) * (1 + 2))); |
| 1031 }, dynamicTodynamic())); |
| 1032 }, VoidTodynamic())); |
| 1033 unittest$.test("nested, await", dart.fn(() => { |
| 1034 function f() { |
| 1035 return dart.async(function*() { |
| 1036 let r = 0; |
| 1037 let it = async.StreamIterator.new(async.Stream._check(mkStream(5))); |
| 1038 try { |
| 1039 while (yield it.moveNext()) { |
| 1040 let i = it.current; |
| 1041 let it$ = async.StreamIterator.new(async.Stream._check(mkStream(
3))); |
| 1042 try { |
| 1043 while (yield it$.moveNext()) { |
| 1044 let j = it$.current; |
| 1045 r = dart.notNull(r) + dart.notNull(core.int._check(yield asy
nc.Future.microtask(dart.fn(() => dart.dsend(i, '*', j), VoidTodynamic())))); |
| 1046 } |
| 1047 } finally { |
| 1048 yield it$.cancel(); |
| 1049 } |
| 1050 } |
| 1051 } finally { |
| 1052 yield it.cancel(); |
| 1053 } |
| 1054 return r; |
| 1055 }, dart.dynamic); |
| 1056 } |
| 1057 dart.fn(f, VoidTodynamic()); |
| 1058 return dart.dsend(f(), 'then', dart.fn(v => { |
| 1059 src__matcher__expect.expect(v, src__matcher__core_matchers.equals((1 +
2 + 3 + 4) * (1 + 2))); |
| 1060 }, dynamicTodynamic())); |
| 1061 }, VoidTodynamic())); |
| 1062 unittest$.test("nested, await * 2", dart.fn(() => { |
| 1063 function f() { |
| 1064 return dart.async(function*() { |
| 1065 let r = 0; |
| 1066 let it = async.StreamIterator.new(async.Stream._check(mkStream(5))); |
| 1067 try { |
| 1068 while (yield it.moveNext()) { |
| 1069 let i = it.current; |
| 1070 let ai = (yield async.Future.microtask(dart.fn(() => i, VoidTody
namic()))); |
| 1071 let it$ = async.StreamIterator.new(async.Stream._check(mkStream(
3))); |
| 1072 try { |
| 1073 while (yield it$.moveNext()) { |
| 1074 let j = it$.current; |
| 1075 r = dart.notNull(r) + dart.notNull(core.int._check(yield asy
nc.Future.microtask(dart.fn(() => dart.dsend(ai, '*', j), VoidTodynamic())))); |
| 1076 } |
| 1077 } finally { |
| 1078 yield it$.cancel(); |
| 1079 } |
| 1080 } |
| 1081 } finally { |
| 1082 yield it.cancel(); |
| 1083 } |
| 1084 return r; |
| 1085 }, dart.dynamic); |
| 1086 } |
| 1087 dart.fn(f, VoidTodynamic()); |
| 1088 return dart.dsend(f(), 'then', dart.fn(v => { |
| 1089 src__matcher__expect.expect(v, src__matcher__core_matchers.equals((1 +
2 + 3 + 4) * (1 + 2))); |
| 1090 }, dynamicTodynamic())); |
| 1091 }, VoidTodynamic())); |
| 1092 }, VoidTovoid())); |
| 1093 }; |
| 1094 dart.fn(async_star_test_04_multi.main, VoidTodynamic()); |
| 1095 async_star_test_04_multi.id = function(x) { |
| 1096 try { |
| 1097 if (x != null) dart.throw(x); |
| 1098 } catch (e) { |
| 1099 return e; |
| 1100 } |
| 1101 |
| 1102 return null; |
| 1103 }; |
| 1104 dart.fn(async_star_test_04_multi.id, dynamicTodynamic()); |
| 1105 async_star_test_04_multi.expectList = function(stream, list) { |
| 1106 return dart.dsend(dart.dsend(stream, 'toList'), 'then', dart.fn(v => { |
| 1107 src__matcher__expect.expect(v, src__matcher__core_matchers.equals(list)); |
| 1108 }, dynamicTodynamic())); |
| 1109 }; |
| 1110 dart.fn(async_star_test_04_multi.expectList, dynamicAnddynamicTodynamic()); |
| 1111 async_star_test_04_multi.MS = dart.const(new core.Duration({milliseconds: 1}))
; |
| 1112 dart.defineLazy(async_star_test_04_multi, { |
| 1113 get getErrors() { |
| 1114 return async.StreamTransformer.fromHandlers({handleData: dart.fn((data, si
nk) => { |
| 1115 src__matcher__expect.fail("Unexpected value"); |
| 1116 }, dynamicAndEventSinkTovoid()), handleError: dart.fn((e, s, sink) => { |
| 1117 sink.add(e); |
| 1118 }, ObjectAndStackTraceAndEventSinkTovoid()), handleDone: dart.fn(sink =>
{ |
| 1119 sink.close(); |
| 1120 }, EventSinkTovoid())}); |
| 1121 }, |
| 1122 set getErrors(_) {} |
| 1123 }); |
| 1124 async_star_test_04_multi.NotAStream = class NotAStream extends core.Object { |
| 1125 listen(oData, opts) { |
| 1126 let onError = opts && 'onError' in opts ? opts.onError : null; |
| 1127 let onDone = opts && 'onDone' in opts ? opts.onDone : null; |
| 1128 let cancelOnError = opts && 'cancelOnError' in opts ? opts.cancelOnError :
null; |
| 1129 src__matcher__expect.fail("Not implementing Stream."); |
| 1130 } |
| 1131 }; |
| 1132 dart.setSignature(async_star_test_04_multi.NotAStream, { |
| 1133 methods: () => ({listen: dart.definiteFunctionType(dart.dynamic, [dart.dynam
ic], {onError: dart.dynamic, onDone: dart.dynamic, cancelOnError: dart.dynamic})
}) |
| 1134 }); |
| 1135 const _completer = Symbol('_completer'); |
| 1136 async_star_test_04_multi.Sync = class Sync extends core.Object { |
| 1137 new() { |
| 1138 this[_completer] = null; |
| 1139 } |
| 1140 wait(v) { |
| 1141 if (v === void 0) v = null; |
| 1142 if (this[_completer] != null) this[_completer].complete(v); |
| 1143 this[_completer] = async.Completer.new(); |
| 1144 return this[_completer].future; |
| 1145 } |
| 1146 release(v) { |
| 1147 if (v === void 0) v = null; |
| 1148 if (this[_completer] != null) { |
| 1149 this[_completer].complete(v); |
| 1150 this[_completer] = null; |
| 1151 } |
| 1152 } |
| 1153 }; |
| 1154 dart.setSignature(async_star_test_04_multi.Sync, { |
| 1155 methods: () => ({ |
| 1156 wait: dart.definiteFunctionType(async.Future, [], [dart.dynamic]), |
| 1157 release: dart.definiteFunctionType(dart.void, [], [dart.dynamic]) |
| 1158 }) |
| 1159 }); |
| 1160 // Exports: |
| 1161 exports.async_star_test_04_multi = async_star_test_04_multi; |
| 1162 }); |
OLD | NEW |