1 #include "../test.h" 2 #include "rxcpp/operators/rx-skip.hpp" 3 4 SCENARIO("skip, complete after", "[skip][operators]"){ 5 GIVEN("a source"){ 6 auto sc = rxsc::make_test(); 7 auto w = sc.create_worker(); 8 const rxsc::test::messages<int> on; 9 10 auto xs = sc.make_hot_observable({ 11 on.next(70, 6), 12 on.next(150, 4), 13 on.next(210, 9), 14 on.next(230, 13), 15 on.next(270, 7), 16 on.next(280, 1), 17 on.next(300, -1), 18 on.next(310, 3), 19 on.next(340, 8), 20 on.next(370, 11), 21 on.next(410, 15), 22 on.next(415, 16), 23 on.next(460, 72), 24 on.next(510, 76), 25 on.next(560, 32), 26 on.next(570, -100), 27 on.next(580, -3), 28 on.next(590, 5), 29 on.next(630, 10), 30 on.completed(690) 31 }); 32 33 WHEN("more values than generated are skipped"){ 34 35 auto res = w.start( __anond8feacec0102() 36 [xs]() { 37 return xs 38 .skip(20) 39 // forget type to workaround lambda deduction bug on msvc 2013 40 .as_dynamic(); 41 } 42 ); 43 44 THEN("the output only contains only complete message"){ 45 auto required = rxu::to_vector({ 46 on.completed(690) 47 }); 48 auto actual = res.get_observer().messages(); 49 REQUIRE(required == actual); 50 } 51 52 THEN("there was 1 subscription/unsubscription to the source"){ 53 auto required = rxu::to_vector({ 54 on.subscribe(200, 690) 55 }); 56 auto actual = xs.subscriptions(); 57 REQUIRE(required == actual); 58 } 59 } 60 } 61 } 62 63 SCENARIO("skip, complete same", "[skip][operators]"){ 64 GIVEN("a source"){ 65 auto sc = rxsc::make_test(); 66 auto w = sc.create_worker(); 67 const rxsc::test::messages<int> on; 68 69 auto xs = sc.make_hot_observable({ 70 on.next(70, 6), 71 on.next(150, 4), 72 on.next(210, 9), 73 on.next(230, 13), 74 on.next(270, 7), 75 on.next(280, 1), 76 on.next(300, -1), 77 on.next(310, 3), 78 on.next(340, 8), 79 on.next(370, 11), 80 on.next(410, 15), 81 on.next(415, 16), 82 on.next(460, 72), 83 on.next(510, 76), 84 on.next(560, 32), 85 on.next(570, -100), 86 on.next(580, -3), 87 on.next(590, 5), 88 on.next(630, 10), 89 on.completed(690) 90 }); 91 92 WHEN("exact number of values is skipped"){ 93 94 auto res = w.start( __anond8feacec0202() 95 [xs]() { 96 return xs 97 | rxo::skip(17) 98 // forget type to workaround lambda deduction bug on msvc 2013 99 | rxo::as_dynamic(); 100 } 101 ); 102 103 THEN("the output only contains only complete message"){ 104 auto required = rxu::to_vector({ 105 on.completed(690) 106 }); 107 auto actual = res.get_observer().messages(); 108 REQUIRE(required == actual); 109 } 110 111 THEN("there was 1 subscription/unsubscription to the source"){ 112 auto required = rxu::to_vector({ 113 on.subscribe(200, 690) 114 }); 115 auto actual = xs.subscriptions(); 116 REQUIRE(required == actual); 117 } 118 } 119 } 120 } 121 122 SCENARIO("skip, complete before", "[skip][operators]"){ 123 GIVEN("a source"){ 124 auto sc = rxsc::make_test(); 125 auto w = sc.create_worker(); 126 const rxsc::test::messages<int> on; 127 128 auto xs = sc.make_hot_observable({ 129 on.next(70, 6), 130 on.next(150, 4), 131 on.next(210, 9), 132 on.next(230, 13), 133 on.next(270, 7), 134 on.next(280, 1), 135 on.next(300, -1), 136 on.next(310, 3), 137 on.next(340, 8), 138 on.next(370, 11), 139 on.next(410, 15), 140 on.next(415, 16), 141 on.next(460, 72), 142 on.next(510, 76), 143 on.next(560, 32), 144 on.next(570, -100), 145 on.next(580, -3), 146 on.next(590, 5), 147 on.next(630, 10), 148 on.completed(690) 149 }); 150 151 WHEN("part of values is skipped"){ 152 153 auto res = w.start( __anond8feacec0302() 154 [xs]() { 155 return xs 156 .skip(10) 157 // forget type to workaround lambda deduction bug on msvc 2013 158 .as_dynamic(); 159 } 160 ); 161 162 THEN("the output only contains items sent while subscribed"){ 163 auto required = rxu::to_vector({ 164 on.next(460, 72), 165 on.next(510, 76), 166 on.next(560, 32), 167 on.next(570, -100), 168 on.next(580, -3), 169 on.next(590, 5), 170 on.next(630, 10), 171 on.completed(690) 172 }); 173 auto actual = res.get_observer().messages(); 174 REQUIRE(required == actual); 175 } 176 177 THEN("there was 1 subscription/unsubscription to the source"){ 178 auto required = rxu::to_vector({ 179 on.subscribe(200, 690) 180 }); 181 auto actual = xs.subscriptions(); 182 REQUIRE(required == actual); 183 } 184 } 185 } 186 } 187 188 SCENARIO("skip, complete zero", "[skip][operators]"){ 189 GIVEN("a source"){ 190 auto sc = rxsc::make_test(); 191 auto w = sc.create_worker(); 192 const rxsc::test::messages<int> on; 193 194 auto xs = sc.make_hot_observable({ 195 on.next(70, 6), 196 on.next(150, 4), 197 on.next(210, 9), 198 on.next(230, 13), 199 on.next(270, 7), 200 on.next(280, 1), 201 on.next(300, -1), 202 on.next(310, 3), 203 on.next(340, 8), 204 on.next(370, 11), 205 on.next(410, 15), 206 on.next(415, 16), 207 on.next(460, 72), 208 on.next(510, 76), 209 on.next(560, 32), 210 on.next(570, -100), 211 on.next(580, -3), 212 on.next(590, 5), 213 on.next(630, 10), 214 on.completed(690) 215 }); 216 217 WHEN("no values are skipped"){ 218 219 auto res = w.start( __anond8feacec0402() 220 [xs]() { 221 return xs 222 .skip(0) 223 // forget type to workaround lambda deduction bug on msvc 2013 224 .as_dynamic(); 225 } 226 ); 227 228 THEN("the output only contains items sent while subscribed"){ 229 auto required = rxu::to_vector({ 230 on.next(210, 9), 231 on.next(230, 13), 232 on.next(270, 7), 233 on.next(280, 1), 234 on.next(300, -1), 235 on.next(310, 3), 236 on.next(340, 8), 237 on.next(370, 11), 238 on.next(410, 15), 239 on.next(415, 16), 240 on.next(460, 72), 241 on.next(510, 76), 242 on.next(560, 32), 243 on.next(570, -100), 244 on.next(580, -3), 245 on.next(590, 5), 246 on.next(630, 10), 247 on.completed(690) 248 }); 249 auto actual = res.get_observer().messages(); 250 REQUIRE(required == actual); 251 } 252 253 THEN("there was 1 subscription/unsubscription to the source"){ 254 auto required = rxu::to_vector({ 255 on.subscribe(200, 690) 256 }); 257 auto actual = xs.subscriptions(); 258 REQUIRE(required == actual); 259 } 260 } 261 } 262 } 263 264 SCENARIO("skip, error after", "[skip][operators]"){ 265 GIVEN("a source"){ 266 auto sc = rxsc::make_test(); 267 auto w = sc.create_worker(); 268 const rxsc::test::messages<int> on; 269 270 std::runtime_error ex("skip on_error from source"); 271 272 auto xs = sc.make_hot_observable({ 273 on.next(70, 6), 274 on.next(150, 4), 275 on.next(210, 9), 276 on.next(230, 13), 277 on.next(270, 7), 278 on.next(280, 1), 279 on.next(300, -1), 280 on.next(310, 3), 281 on.next(340, 8), 282 on.next(370, 11), 283 on.next(410, 15), 284 on.next(415, 16), 285 on.next(460, 72), 286 on.next(510, 76), 287 on.next(560, 32), 288 on.next(570, -100), 289 on.next(580, -3), 290 on.next(590, 5), 291 on.next(630, 10), 292 on.error(690, ex) 293 }); 294 295 WHEN("more values than generated are skipped"){ 296 297 auto res = w.start( __anond8feacec0502() 298 [xs]() { 299 return xs 300 .skip(20) 301 // forget type to workaround lambda deduction bug on msvc 2013 302 .as_dynamic(); 303 } 304 ); 305 306 THEN("the output only contains only error message"){ 307 auto required = rxu::to_vector({ 308 on.error(690, ex) 309 }); 310 auto actual = res.get_observer().messages(); 311 REQUIRE(required == actual); 312 } 313 314 THEN("there was 1 subscription/unsubscription to the source"){ 315 auto required = rxu::to_vector({ 316 on.subscribe(200, 690) 317 }); 318 auto actual = xs.subscriptions(); 319 REQUIRE(required == actual); 320 } 321 } 322 } 323 } 324 325 SCENARIO("skip, error same", "[skip][operators]"){ 326 GIVEN("a source"){ 327 auto sc = rxsc::make_test(); 328 auto w = sc.create_worker(); 329 const rxsc::test::messages<int> on; 330 331 std::runtime_error ex("skip on_error from source"); 332 333 auto xs = sc.make_hot_observable({ 334 on.next(70, 6), 335 on.next(150, 4), 336 on.next(210, 9), 337 on.next(230, 13), 338 on.next(270, 7), 339 on.next(280, 1), 340 on.next(300, -1), 341 on.next(310, 3), 342 on.next(340, 8), 343 on.next(370, 11), 344 on.next(410, 15), 345 on.next(415, 16), 346 on.next(460, 72), 347 on.next(510, 76), 348 on.next(560, 32), 349 on.next(570, -100), 350 on.next(580, -3), 351 on.next(590, 5), 352 on.next(630, 10), 353 on.error(690, ex) 354 }); 355 356 WHEN("exact number of values is skipped"){ 357 358 auto res = w.start( __anond8feacec0602() 359 [xs]() { 360 return xs 361 .skip(17) 362 // forget type to workaround lambda deduction bug on msvc 2013 363 .as_dynamic(); 364 } 365 ); 366 367 THEN("the output only contains only error message"){ 368 auto required = rxu::to_vector({ 369 on.error(690, ex) 370 }); 371 auto actual = res.get_observer().messages(); 372 REQUIRE(required == actual); 373 } 374 375 THEN("there was 1 subscription/unsubscription to the source"){ 376 auto required = rxu::to_vector({ 377 on.subscribe(200, 690) 378 }); 379 auto actual = xs.subscriptions(); 380 REQUIRE(required == actual); 381 } 382 } 383 } 384 } 385 386 SCENARIO("skip, error before", "[skip][operators]"){ 387 GIVEN("a source"){ 388 auto sc = rxsc::make_test(); 389 auto w = sc.create_worker(); 390 const rxsc::test::messages<int> on; 391 392 std::runtime_error ex("skip on_error from source"); 393 394 auto xs = sc.make_hot_observable({ 395 on.next(70, 6), 396 on.next(150, 4), 397 on.next(210, 9), 398 on.next(230, 13), 399 on.next(270, 7), 400 on.next(280, 1), 401 on.next(300, -1), 402 on.next(310, 3), 403 on.next(340, 8), 404 on.next(370, 11), 405 on.next(410, 15), 406 on.next(415, 16), 407 on.next(460, 72), 408 on.next(510, 76), 409 on.next(560, 32), 410 on.next(570, -100), 411 on.next(580, -3), 412 on.next(590, 5), 413 on.next(630, 10), 414 on.error(690, ex) 415 }); 416 417 WHEN("part of values is skipped"){ 418 419 auto res = w.start( __anond8feacec0702() 420 [xs]() { 421 return xs 422 .skip(3) 423 // forget type to workaround lambda deduction bug on msvc 2013 424 .as_dynamic(); 425 } 426 ); 427 428 THEN("the output only contains items sent while subscribed"){ 429 auto required = rxu::to_vector({ 430 on.next(280, 1), 431 on.next(300, -1), 432 on.next(310, 3), 433 on.next(340, 8), 434 on.next(370, 11), 435 on.next(410, 15), 436 on.next(415, 16), 437 on.next(460, 72), 438 on.next(510, 76), 439 on.next(560, 32), 440 on.next(570, -100), 441 on.next(580, -3), 442 on.next(590, 5), 443 on.next(630, 10), 444 on.error(690, ex) 445 }); 446 auto actual = res.get_observer().messages(); 447 REQUIRE(required == actual); 448 } 449 450 THEN("there was 1 subscription/unsubscription to the source"){ 451 auto required = rxu::to_vector({ 452 on.subscribe(200, 690) 453 }); 454 auto actual = xs.subscriptions(); 455 REQUIRE(required == actual); 456 } 457 } 458 } 459 } 460 461 SCENARIO("skip, dispose before", "[skip][operators]"){ 462 GIVEN("a source"){ 463 auto sc = rxsc::make_test(); 464 auto w = sc.create_worker(); 465 const rxsc::test::messages<int> on; 466 467 auto xs = sc.make_hot_observable({ 468 on.next(70, 6), 469 on.next(150, 4), 470 on.next(210, 9), 471 on.next(230, 13), 472 on.next(270, 7), 473 on.next(280, 1), 474 on.next(300, -1), 475 on.next(310, 3), 476 on.next(340, 8), 477 on.next(370, 11), 478 on.next(410, 15), 479 on.next(415, 16), 480 on.next(460, 72), 481 on.next(510, 76), 482 on.next(560, 32), 483 on.next(570, -100), 484 on.next(580, -3), 485 on.next(590, 5), 486 on.next(630, 10) 487 }); 488 489 WHEN("all generated values are skipped"){ 490 491 auto res = w.start( __anond8feacec0802() 492 [xs]() { 493 return xs 494 .skip(3) 495 // forget type to workaround lambda deduction bug on msvc 2013 496 .as_dynamic(); 497 }, 498 250 499 ); 500 501 THEN("the output is empty"){ 502 auto required = std::vector<rxsc::test::messages<int>::recorded_type>(); 503 auto actual = res.get_observer().messages(); 504 REQUIRE(required == actual); 505 } 506 507 THEN("there was 1 subscription/unsubscription to the source"){ 508 auto required = rxu::to_vector({ 509 on.subscribe(200, 250) 510 }); 511 auto actual = xs.subscriptions(); 512 REQUIRE(required == actual); 513 } 514 } 515 } 516 } 517 518 SCENARIO("skip, dispose after", "[skip][operators]"){ 519 GIVEN("a source"){ 520 auto sc = rxsc::make_test(); 521 auto w = sc.create_worker(); 522 const rxsc::test::messages<int> on; 523 524 auto xs = sc.make_hot_observable({ 525 on.next(70, 6), 526 on.next(150, 4), 527 on.next(210, 9), 528 on.next(230, 13), 529 on.next(270, 7), 530 on.next(280, 1), 531 on.next(300, -1), 532 on.next(310, 3), 533 on.next(340, 8), 534 on.next(370, 11), 535 on.next(410, 15), 536 on.next(415, 16), 537 on.next(460, 72), 538 on.next(510, 76), 539 on.next(560, 32), 540 on.next(570, -100), 541 on.next(580, -3), 542 on.next(590, 5), 543 on.next(630, 10) 544 }); 545 546 WHEN("some generated values are skipped"){ 547 548 auto res = w.start( __anond8feacec0902() 549 [xs]() { 550 return xs 551 .skip(3) 552 // forget type to workaround lambda deduction bug on msvc 2013 553 .as_dynamic(); 554 }, 555 400 556 ); 557 558 THEN("the output contains items sent while subscribed"){ 559 auto required = rxu::to_vector({ 560 on.next(280, 1), 561 on.next(300, -1), 562 on.next(310, 3), 563 on.next(340, 8), 564 on.next(370, 11) 565 }); 566 auto actual = res.get_observer().messages(); 567 REQUIRE(required == actual); 568 } 569 570 THEN("there was 1 subscription/unsubscription to the source"){ 571 auto required = rxu::to_vector({ 572 on.subscribe(200, 400) 573 }); 574 auto actual = xs.subscriptions(); 575 REQUIRE(required == actual); 576 } 577 } 578 } 579 } 580 581 SCENARIO("skip, consecutive", "[skip][operators]"){ 582 GIVEN("a source"){ 583 auto sc = rxsc::make_test(); 584 auto w = sc.create_worker(); 585 const rxsc::test::messages<int> on; 586 587 auto xs = sc.make_hot_observable({ 588 on.next(70, 6), 589 on.next(150, 4), 590 on.next(210, 9), 591 on.next(230, 13), 592 on.next(270, 7), 593 on.next(280, 1), 594 on.next(300, -1), 595 on.next(310, 3), 596 on.next(340, 8), 597 on.next(370, 11), 598 on.completed(400) 599 }); 600 601 WHEN("3+2 values are skipped"){ 602 603 auto res = w.start( __anond8feacec0a02() 604 [xs]() { 605 return xs 606 .skip(3) 607 .skip(2) 608 // forget type to workaround lambda deduction bug on msvc 2013 609 .as_dynamic(); 610 } 611 ); 612 613 THEN("the output only contains items sent while subscribed"){ 614 auto required = rxu::to_vector({ 615 on.next(310, 3), 616 on.next(340, 8), 617 on.next(370, 11), 618 on.completed(400) 619 }); 620 auto actual = res.get_observer().messages(); 621 REQUIRE(required == actual); 622 } 623 624 THEN("there was 1 subscription/unsubscription to the source"){ 625 auto required = rxu::to_vector({ 626 on.subscribe(200, 400) 627 }); 628 auto actual = xs.subscriptions(); 629 REQUIRE(required == actual); 630 } 631 } 632 } 633 } 634