Skip to content

Commit

Permalink
Add test for printer visitor.
Browse files Browse the repository at this point in the history
  • Loading branch information
joto committed Jun 26, 2014
1 parent 12c7093 commit fd470a6
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions test/unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
#include "catch.hpp"

#include "variant.hpp"

#include <algorithm>
#include <cstdint>
#include <iterator>
#include <limits>
#include <string>
#include <ostream>
#include <memory>
#include <ostream>
#include <sstream>
#include <string>

using namespace mapbox;

Expand Down Expand Up @@ -280,9 +284,7 @@ TEST_CASE( "variant default constructor", "[variant][default constructor]" ) {
REQUIRE((util::variant<int, double, std::string>().get_type_index() == 2));
}


TEST_CASE( "variant visitation", "[visitor][unary visitor]" )
{
TEST_CASE( "variant visitation", "[visitor][unary visitor]" ) {
util::variant<int, double, std::string> var(123);
REQUIRE(var.get<int>() == 123);
int val = 456;
Expand All @@ -291,6 +293,16 @@ TEST_CASE( "variant visitation", "[visitor][unary visitor]" )
REQUIRE(var.get<int>() == 456);
}

TEST_CASE( "variant printer", "[visitor][unary visitor][printer]" ) {
typedef util::variant<int, double, std::string> variant_type;
std::vector<variant_type> var = {2.1, 123, "foo", 456};
std::stringstream out;
std::copy(var.begin(), var.end(), std::ostream_iterator<variant_type>(out, ","));
out << var[2];
REQUIRE(out.str() == "2.1,123,foo,456,foo");
}


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

0 comments on commit fd470a6

Please sign in to comment.