Files
Cataclysm-DDA/tests/optional_test.cpp
T
Binrui Dong 9fdb7ef59c Run IWYU
* Change _ctype.h and __locale to cctype and clocale

* Change _wctype.h to cwctype in game.cpp

* Change __functional_base to functional

* Remove libcxx internal headers

* Remove UNIX system headers

* Fix clang-tidy error with -nostdinc++
2021-02-06 00:18:41 -05:00

44 lines
757 B
C++

#include <new>
#include <type_traits>
#include "catch/catch.hpp"
#include "optional.h"
TEST_CASE( "optional_assignment_works", "[optional]" )
{
cata::optional<int> a( 1 );
REQUIRE( a );
CHECK( *a == 1 );
cata::optional<int> b( 2 );
cata::optional<int> unset;
a = b;
REQUIRE( a );
CHECK( *a == 2 );
a = unset;
CHECK( !a );
a = std::move( b );
REQUIRE( a );
CHECK( *a == 2 );
a = std::move( unset );
CHECK( !a );
const cata::optional<int> c( 3 );
a = c;
REQUIRE( a );
CHECK( *a == 3 );
int d = 4;
a = d;
REQUIRE( a );
CHECK( *a == 4 );
a = d;
REQUIRE( a );
CHECK( *a == 4 );
const int e = 5;
a = e;
REQUIRE( a );
CHECK( *a == 5 );
}