Skip to content

Commit

Permalink
add unary_visitor test
Browse files Browse the repository at this point in the history
  • Loading branch information
artemp committed Jun 24, 2014
1 parent 54d07c9 commit 3b31c34
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions test/unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,25 @@

using namespace mapbox;

template <typename T>
struct mutating_visitor : util::static_visitor<>
{
mutating_visitor(T & val)
: val_(val) {}

void operator() (T & val) const
{
val = val_;
}

template <typename T1>
void operator() (T1& ) const {} // no-op

T & val_;
};



TEST_CASE( "variant version", "[variant]" ) {
unsigned int version = VARIANT_VERSION;
REQUIRE(version == 100);
Expand Down Expand Up @@ -208,6 +227,17 @@ TEST_CASE( "variant default constructor", "variant()" ) {
REQUIRE((util::variant<int, double, std::string>().get_type_index() == 2));
}


TEST_CASE( "variant visitation", "unary visitor" )
{
util::variant<int, double, std::string> var(123);
REQUIRE(var.get<int>() == 123);
int val = 456;
mutating_visitor<int> visitor(val);
util::apply_visitor(visitor,var);
REQUIRE(var.get<int>() == 456);
}

int main (int argc, char* const argv[])
{
int result = Catch::Session().run( argc, argv );
Expand Down

0 comments on commit 3b31c34

Please sign in to comment.