Skip to content

Commit

Permalink
Additional cata_variant tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jbytheway committed Aug 31, 2019
1 parent 36764f4 commit 04d37e1
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/cata_variant_test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include "catch/catch.hpp"

#include <sstream>

#include "cata_variant.h"
#include "json.h"

TEST_CASE( "variant_construction", "[variant]" )
{
Expand Down Expand Up @@ -59,3 +62,28 @@ TEST_CASE( "variant_type_name_round_trip", "[variant]" )
CHECK( io::string_to_enum<cata_variant_type>( type_as_string ) == type );
}
}

TEST_CASE( "variant_default_constructor", "[variant]" )
{
cata_variant v;
CHECK( v.type() == cata_variant_type::void_ );
CHECK( v.get_string() == "" );
}

TEST_CASE( "variant_serialization", "[variant]" )
{
cata_variant v = cata_variant( mtype_id( "zombie" ) );
std::ostringstream os;
JsonOut jsout( os );
v.serialize( jsout );
CHECK( os.str() == R"(["mtype_id","zombie"])" );
}

TEST_CASE( "variant_deserialization", "[variant]" )
{
std::istringstream is( R"(["mtype_id","zombie"])" );
JsonIn jsin( is );
cata_variant v;
v.deserialize( jsin );
CHECK( v == cata_variant( mtype_id( "zombie" ) ) );
}

0 comments on commit 04d37e1

Please sign in to comment.