summaryrefslogtreecommitdiff
path: root/Rx/v2/test
diff options
context:
space:
mode:
authorelelel <elel@3wh.net>2017-02-21 03:10:05 +0000
committerKirk Shoop <kirk.shoop@microsoft.com>2017-02-20 19:10:05 -0800
commit7811809ebb9d4226420ad51d11a922704b56b7a9 (patch)
tree869a20e9ef51449bd9ba07253baf64ab98c35185 /Rx/v2/test
parent35a805ef522b061d0a89f524e99134d6360f05ca (diff)
downloadRxCpp-7811809ebb9d4226420ad51d11a922704b56b7a9.tar.gz
Rewrite repeat operator to handle 0 case correctly and not rely on magic numbers (#356)
* Sketch interface for finite/inifinite variants * CRTP deriving finite/infinite from base * Fully rewrite repeat implementation * Fix description and comments in repeat * Test repeat(0) case * Make 0 handling with completion when the input sequence complete * Return immidiately empty sequence instead on first on_completed * Return immidiately empty sequence instead on first on_completed * Update param description for repeat 0 case * repeat(0): never call on.next(), but call on.completed() * Test: no subscriptions are made when repeat(0)
Diffstat (limited to 'Rx/v2/test')
-rw-r--r--Rx/v2/test/operators/repeat.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/Rx/v2/test/operators/repeat.cpp b/Rx/v2/test/operators/repeat.cpp
index 80c3c87..0aa9598 100644
--- a/Rx/v2/test/operators/repeat.cpp
+++ b/Rx/v2/test/operators/repeat.cpp
@@ -56,6 +56,47 @@ SCENARIO("repeat, basic test", "[repeat][operators]"){
}
}
+SCENARIO("repeat, 0 times case", "[repeat][operators]"){
+ GIVEN("cold observable of 3 ints."){
+ auto sc = rxsc::make_test();
+ auto w = sc.create_worker();
+ const rxsc::test::messages<int> on;
+
+ auto xs = sc.make_cold_observable({
+ on.next(100, 1),
+ on.next(150, 2),
+ on.next(200, 3),
+ on.completed(250)
+ });
+
+ WHEN("repeat zero times is launched"){
+
+ auto res = w.start(
+ [&]() {
+ return xs
+ | rxo::repeat(0)
+ // forget type to workaround lambda deduction bug on msvc 2013
+ | rxo::as_dynamic();
+ }
+ );
+
+ THEN("the output should be empty"){
+ auto required = rxu::to_vector({
+ on.completed(200)
+ });
+ auto actual = res.get_observer().messages();
+ REQUIRE(required == actual);
+ }
+
+ THEN("no subscriptions in repeat(0) variant that skips on.next()"){
+ auto required = std::vector<rxcpp::notifications::subscription>();
+ auto actual = xs.subscriptions();
+ REQUIRE(required == actual);
+ }
+ }
+ }
+}
+
SCENARIO("repeat, infinite observable test", "[repeat][operators]"){
GIVEN("cold observable of 3 ints that never completes."){
auto sc = rxsc::make_test();