From 04d37e186df5c2c46d67fa4c29c3933d9867a869 Mon Sep 17 00:00:00 2001 From: John Bytheway Date: Fri, 30 Aug 2019 20:21:54 -0400 Subject: [PATCH] Additional cata_variant tests --- tests/cata_variant_test.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/cata_variant_test.cpp b/tests/cata_variant_test.cpp index 0f02f1471f9f8..a6861a18e8fdc 100644 --- a/tests/cata_variant_test.cpp +++ b/tests/cata_variant_test.cpp @@ -1,6 +1,9 @@ #include "catch/catch.hpp" +#include + #include "cata_variant.h" +#include "json.h" TEST_CASE( "variant_construction", "[variant]" ) { @@ -59,3 +62,28 @@ TEST_CASE( "variant_type_name_round_trip", "[variant]" ) CHECK( io::string_to_enum( 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" ) ) ); +}