• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include "../test.h"
2 #include <rxcpp/operators/rx-ignore_elements.hpp>
3 
4 SCENARIO("ignore_elements - never", "[ignore_elements][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(150, 1)
12         });
13 
14         WHEN("ignore_elements is applied"){
15 
16             auto res = w.start(
__anon5a84b6110102() 17                 [xs]() {
18                     return xs | rxo::ignore_elements();
19                 }
20             );
21 
22             THEN("the output is empty"){
23                 auto required = std::vector<rxsc::test::messages<int>::recorded_type>();
24                 auto actual = res.get_observer().messages();
25                 REQUIRE(required == actual);
26             }
27 
28             THEN("there was 1 subscription/unsubscription to the source"){
29                 auto required = rxu::to_vector({
30                     on.subscribe(200, 1000)
31                 });
32                 auto actual = xs.subscriptions();
33                 REQUIRE(required == actual);
34             }
35         }
36     }
37 }
38 
39 SCENARIO("ignore_elements - empty", "[ignore_elements][operators]"){
40     GIVEN("a source"){
41         auto sc = rxsc::make_test();
42         auto w = sc.create_worker();
43         const rxsc::test::messages<int> on;
44 
45         auto xs = sc.make_hot_observable({
46             on.next(150, 1),
47             on.completed(250)
48         });
49 
50         WHEN("ignore_elements is applied"){
51 
52             auto res = w.start(
__anon5a84b6110202() 53                 [xs]() {
54                     return xs.ignore_elements();
55                 }
56             );
57 
58             THEN("the output contains the completion message"){
59                 auto required = rxu::to_vector({
60                     on.completed(250)
61                 });
62                 auto actual = res.get_observer().messages();
63                 REQUIRE(required == actual);
64             }
65 
66             THEN("there was 1 subscription/unsubscription to the source"){
67                 auto required = rxu::to_vector({
68                     on.subscribe(200, 250)
69                 });
70                 auto actual = xs.subscriptions();
71                 REQUIRE(required == actual);
72             }
73 
74         }
75     }
76 }
77 
78 SCENARIO("ignore_elements - throw", "[ignore_elements][operators]"){
79     GIVEN("a source"){
80         auto sc = rxsc::make_test();
81         auto w = sc.create_worker();
82         const rxsc::test::messages<int> on;
83 
84         std::runtime_error ex("ignore_elements on_error from source");
85 
86         auto xs = sc.make_hot_observable({
87             on.next(150, 1),
88             on.error(250, ex)
89         });
90 
91         WHEN("ignore_elements is applied"){
92 
93             auto res = w.start(
__anon5a84b6110302() 94                 [xs]() {
95                     return xs.ignore_elements();
96                 }
97             );
98 
99             THEN("the output contains an error"){
100                 auto required = rxu::to_vector({
101                     on.error(250, ex)
102                 });
103                 auto actual = res.get_observer().messages();
104                 REQUIRE(required == actual);
105             }
106 
107             THEN("there was 1 subscription/unsubscription to the source"){
108                 auto required = rxu::to_vector({
109                     on.subscribe(200, 250)
110                 });
111                 auto actual = xs.subscriptions();
112                 REQUIRE(required == actual);
113             }
114 
115         }
116     }
117 }
118 
119 SCENARIO("ignore_elements - items", "[ignore_elements][operators]"){
120     GIVEN("a source"){
121         auto sc = rxsc::make_test();
122         auto w = sc.create_worker();
123         const rxsc::test::messages<int> on;
124 
125         auto xs = sc.make_hot_observable({
126             on.next(150, 1),
127             on.next(210, 2),
128             on.next(220, 3),
129             on.next(230, 4),
130             on.next(240, 5),
131             on.completed(250)
132         });
133 
134         WHEN("ignore_elements is applied"){
135 
136             auto res = w.start(
__anon5a84b6110402() 137                 [xs]() {
138                     return xs.ignore_elements();
139                 }
140             );
141 
142             THEN("the output contains the completion message"){
143                 auto required = rxu::to_vector({
144                     on.completed(250)
145                 });
146                 auto actual = res.get_observer().messages();
147                 REQUIRE(required == actual);
148             }
149 
150             THEN("there was 1 subscription/unsubscription to the source"){
151                 auto required = rxu::to_vector({
152                     on.subscribe(200, 250)
153                 });
154                 auto actual = xs.subscriptions();
155                 REQUIRE(required == actual);
156             }
157 
158         }
159     }
160 }
161