21 void CoroEitherTest::testSuccess ()
23 auto action = [] ->
Ty 25 auto n = co_await
Ty { 3 };
26 auto m = co_await
Ty { 5 };
29 QCOMPARE (action (), 15);
32 void CoroEitherTest::testFailure ()
34 auto action = [] ->
Ty 36 auto m = co_await
Ty { 3 };
37 auto n = co_await
Ty {
AsLeft,
'a' };
38 auto k = co_await
Ty {
AsLeft,
'b' };
41 QCOMPARE (action (), (
Ty {
AsLeft,
'a' }));
44 void CoroEitherTest::testException ()
46 auto action = [] ->
Ty 48 auto m = co_await
Ty { 3 };
49 auto n = co_await [] ->
Ty {
throw std::runtime_error {
"err" }; } ();
50 auto k = co_await
Ty {
AsLeft,
'a' };
53 QVERIFY_THROWS_EXCEPTION (std::runtime_error, action ());
56 void CoroEitherTest::testSuccessAllocating ()
58 using AllocTy = Either<QByteArray, QString>;
60 auto action = [] -> AllocTy
62 const auto& s1 = co_await AllocTy { QString {
"foo" } };
63 const auto& s2 = co_await AllocTy { QString {
"bar" } };
66 QCOMPARE (action (),
"foobar"_qs);