File tree Expand file tree Collapse file tree 2 files changed +27
-3
lines changed Expand file tree Collapse file tree 2 files changed +27
-3
lines changed Original file line number Diff line number Diff line change @@ -143,17 +143,21 @@ class Result {
143
143
}
144
144
145
145
template <typename F>
146
- void NotOKThen (F&& f) {
146
+ R& NotOKThen (F&& f) {
147
147
if (IsOK ()) {
148
148
return ;
149
149
}
150
150
151
151
f (*this );
152
+
153
+ return static_cast <R&>(*this );
152
154
}
153
155
154
156
template <typename F>
155
- void AlwaysThen (F&& f) {
157
+ R& AlwaysThen (F&& f) {
156
158
f (*this );
159
+
160
+ return static_cast <R&>(*this );
157
161
}
158
162
159
163
void PushHistory (const std::string& file_name, int32_t line) {
Original file line number Diff line number Diff line change @@ -384,7 +384,7 @@ TEST_F(ResultTest, smart_pointer_with_nullptr) {
384
384
}
385
385
}
386
386
387
- TEST_F (ResultTest, NotOKThen ) {
387
+ TEST_F (ResultTest, NotOKThenAndAlwaysThen ) {
388
388
int flag = 0 ;
389
389
390
390
std::invoke ([]() -> CustomResult {
@@ -418,6 +418,26 @@ TEST_F(ResultTest, NotOKThen) {
418
418
});
419
419
420
420
EXPECT_EQ (flag, 3 );
421
+
422
+ {
423
+ int n_flag = 0 ;
424
+ int a_flag = 0 ;
425
+
426
+ std::invoke ([]() -> CustomResult {
427
+ return CustomResult::Builder (CustomResult::ErrorCode::OtherError).Build ();
428
+ })
429
+ .NotOKThen ([&n_flag](auto && res) {
430
+ EXPECT_FALSE (res.IsOK ());
431
+ n_flag = 1 ;
432
+ })
433
+ .AlwaysThen ([&a_flag](auto && res) {
434
+ EXPECT_FALSE (res.IsOK ());
435
+ a_flag = 1 ;
436
+ });
437
+
438
+ EXPECT_EQ (n_flag, 1 );
439
+ EXPECT_EQ (a_flag, 1 );
440
+ }
421
441
}
422
442
423
443
TEST_F (ResultTest, GetHistoryInfoNode) {
You can’t perform that action at this time.
0 commit comments