2020
2121#include < catch2/catch_all.hpp>
2222
23- TEST_CASE ( " just_from is a sender " , " [just_from] " )
23+ namespace
2424{
25- SECTION (" potentially throwing" )
25+ constinit int global_int = 0 ;
26+
27+ TEST_CASE (" just_from is a sender" , " [just_from]" )
2628 {
27- auto s = exec::just_from ([](auto sink) { return sink (42 ); });
28- using S = decltype (s);
29- STATIC_REQUIRE (ex::sender<S>);
30- STATIC_REQUIRE (ex::sender_in<S>);
31- ::check_val_types<ex::__mset<pack<int >>>(s);
32- ::check_err_types<ex::__mset<std::exception_ptr>>(s);
33- ::check_sends_stopped<false >(s);
29+ SECTION (" potentially throwing" )
30+ {
31+ auto s = exec::just_from ([](auto sink) { return sink (42 ); });
32+ using S = decltype (s);
33+ STATIC_REQUIRE (ex::sender<S>);
34+ STATIC_REQUIRE (ex::sender_in<S>);
35+ ::check_val_types<ex::__mset<pack<int >>>(s);
36+ ::check_err_types<ex::__mset<std::exception_ptr>>(s);
37+ ::check_sends_stopped<false >(s);
38+ }
39+
40+ SECTION (" not potentially throwing" )
41+ {
42+ auto s = exec::just_from ([](auto sink) noexcept { return sink (42 ); });
43+ using S = decltype (s);
44+ STATIC_REQUIRE (ex::sender<S>);
45+ STATIC_REQUIRE (ex::sender_in<S>);
46+ ::check_val_types<ex::__mset<pack<int >>>(s);
47+ ::check_err_types<ex::__mset<>>(s);
48+ ::check_sends_stopped<false >(s);
49+ }
3450 }
3551
36- SECTION ( " not potentially throwing " )
52+ TEST_CASE ( " just_from basically works " , " [just_from] " )
3753 {
38- auto s = exec::just_from ([](auto sink) noexcept { return sink (42 ); });
39- using S = decltype (s);
40- STATIC_REQUIRE (ex::sender<S>);
41- STATIC_REQUIRE (ex::sender_in<S>);
42- ::check_val_types<ex::__mset<pack<int >>>(s);
54+ auto s = exec::just_from ([](auto sink) noexcept { return sink (42 , 43 , 44 ); });
55+ ::check_val_types<ex::__mset<pack<int , int , int >>>(s);
4356 ::check_err_types<ex::__mset<>>(s);
4457 ::check_sends_stopped<false >(s);
45- }
46- }
47-
48- TEST_CASE (" just_from basically works" , " [just_from]" )
49- {
50- auto s = exec::just_from ([](auto sink) noexcept { return sink (42 , 43 , 44 ); });
51- ::check_val_types<ex::__mset<pack<int , int , int >>>(s);
52- ::check_err_types<ex::__mset<>>(s);
53- ::check_sends_stopped<false >(s);
5458
55- auto [a, b, c] = ex::sync_wait (s).value ();
56- CHECK (a == 42 );
57- CHECK (b == 43 );
58- CHECK (c == 44 );
59- }
59+ auto [a, b, c] = ex::sync_wait (s).value ();
60+ CHECK (a == 42 );
61+ CHECK (b == 43 );
62+ CHECK (c == 44 );
63+ }
6064
61- TEST_CASE (" just_from with multiple completions" , " [just_from]" )
62- {
63- auto fn = [](auto sink) noexcept
65+ TEST_CASE (" just_from with multiple completions" , " [just_from]" )
6466 {
65- if (sizeof (sink) == ~0ul )
66- {
67- std::puts (" sink(42)" );
68- sink (42 );
69- }
70- else
67+ auto fn = [](auto sink) noexcept
7168 {
72- std::puts (" sink(43, 44)" );
73- sink (43 , 44 );
74- }
75- return ex::completion_signatures<ex::set_value_t (int ), ex::set_value_t (int , int )>{};
76- };
77- auto s = exec::just_from (fn);
78- ::check_val_types<ex::__mset<pack<int >, pack<int , int >>>(s);
79- ::check_err_types<ex::__mset<>>(s);
80- ::check_sends_stopped<false >(s);
81-
82- auto var = ex::sync_wait_with_variant (s).value ();
83- std::visit (
84- []<class Tupl >(Tupl tupl)
85- {
86- constexpr auto N = std::tuple_size_v<Tupl>;
87- CHECK (N == 2 );
88- if constexpr (N == 2 )
69+ if (sizeof (sink) == ~0ul )
8970 {
90- CHECK_TUPLE (tupl == std::tuple{43 , 44 });
71+ std::puts (" sink(42)" );
72+ sink (42 );
9173 }
92- },
93- var);
94- }
74+ else
75+ {
76+ std::puts (" sink(43, 44)" );
77+ sink (43 , 44 );
78+ }
79+ return ex::completion_signatures<ex::set_value_t (int ), ex::set_value_t (int , int )>{};
80+ };
81+ auto s = exec::just_from (fn);
82+ ::check_val_types<ex::__mset<pack<int >, pack<int , int >>>(s);
83+ ::check_err_types<ex::__mset<>>(s);
84+ ::check_sends_stopped<false >(s);
85+
86+ auto var = ex::sync_wait_with_variant (s).value ();
87+ std::visit (
88+ []<class Tupl >(Tupl tupl)
89+ {
90+ constexpr auto N = std::tuple_size_v<Tupl>;
91+ CHECK (N == 2 );
92+ if constexpr (N == 2 )
93+ {
94+ CHECK_TUPLE (tupl == std::tuple{43 , 44 });
95+ }
96+ },
97+ var);
98+ }
99+
100+ TEST_CASE (" just_from can send references" , " [just_from]" )
101+ {
102+ global_int = 42 ;
103+ auto s = exec::just_from ([](auto sink) noexcept { return sink (global_int); })
104+ | ex::then (
105+ [](int & i) noexcept
106+ {
107+ CHECK (&i == &global_int);
108+ return std::ref (i);
109+ });
110+ ::check_val_types<ex::__mset<pack<std::reference_wrapper<int >>>>(s);
111+ auto [iref] = ex::sync_wait (s).value ();
112+ CHECK (&iref.get () == &global_int);
113+ }
114+ } // anonymous namespace
0 commit comments