Skip to content

Commit

Permalink
Add test for expected<void> relational operators (#51, thanks @Crzyrndm)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinmoene committed Nov 13, 2022
1 parent c32b0e7 commit 938e9f7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ expected<void>: Allows to observe its error as unexpected
expected<void>: Allows to query if it contains an exception of a specific base type
expected<void>: Throws bad_expected_access on value access when disengaged
operators: Provides expected relational operators
operators: Provides expected relational operators (void)
swap: Allows expected to be swapped
std::hash: Allows to compute hash value for expected
tweak header: reads tweak header if supported [tweak]
Expand Down
21 changes: 21 additions & 0 deletions test/expected.t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,7 @@ CASE( "expected: Allows to move-construct from expected: value" )

EXPECT( b );
EXPECT( b.value() == 7 );
EXPECT( a ); // postcondition: unchanged!
}

CASE( "expected: Allows to move-construct from expected: error" )
Expand Down Expand Up @@ -1247,6 +1248,7 @@ CASE( "expected<void>: Allows to move-construct from expected<void>: value" )
expected<void, int> b{ std::move( a ) };

EXPECT( b );
EXPECT( a ); // postcondition: unchanged!
}

CASE( "expected<void>: Allows to move-construct from expected<void>: error" )
Expand Down Expand Up @@ -1589,6 +1591,25 @@ CASE( "operators: Provides expected relational operators" )
}
}

CASE( "operators: Provides expected relational operators (void)" )
{
SETUP( "" ) {
expected<void, char> ev1;
expected<void, char> ev2;
expected<void, char> evu{ unexpect };

// compare engaged expected with engaged expected

SECTION( " engaged == engaged" ) { EXPECT( ev1 == ev2 ); }
SECTION( "!(engaged != engaged)" ) { EXPECT_NOT( ev1 != ev2 ); }

// compare engaged expected with disengaged expected

SECTION( " engaged != disengaged" ) { EXPECT( ev1 != evu ); }
SECTION( "!(engaged == disengaged)" ) { EXPECT_NOT( ev1 == evu ); }
}
}

// -----------------------------------------------------------------------
// expected: specialized algorithms

Expand Down

0 comments on commit 938e9f7

Please sign in to comment.