File: optional_test.cpp

package info (click to toggle)
cataclysm-dda 0.C%2Bgit20190228.faafa3a-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 181,636 kB
  • sloc: cpp: 256,609; python: 2,621; makefile: 862; sh: 495; perl: 37; xml: 33
file content (40 lines) | stat: -rw-r--r-- 731 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#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 = std::move( d );
    REQUIRE( a );
    CHECK( *a == 4 );

    const int e = 5;
    a = e;
    REQUIRE( a );
    CHECK( *a == 5 );
}