Skip to content

Commit

Permalink
more tests in unit-udt
Browse files Browse the repository at this point in the history
  • Loading branch information
Théo DELRIEU committed Jan 14, 2017
1 parent a1c5737 commit 3affbfa
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions test/src/unit-udt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,15 +394,22 @@ namespace nlohmann
template <>
struct adl_serializer<std::vector<float>>
{
static void to_json(json& j, std::vector<float> const&)
using type = std::vector<float>;
static void to_json(json& j, type const&)
{
j = "hijacked!";
}

static void from_json(json const&, std::vector<float>& opt)
static void from_json(json const&, type& opt)
{
opt = {42.0, 42.0, 42.0};
}

// preferred version
static type from_json(json const&)
{
return {4.0, 5.0, 6.0};
}
};
}

Expand All @@ -411,7 +418,8 @@ TEST_CASE("even supported types can be specialized", "[udt]")
json j = std::vector<float> {1.0, 2.0, 3.0};
CHECK(j.dump() == R"("hijacked!")");
auto f = j.get<std::vector<float>>();
CHECK((f == std::vector<float>{42.0, 42.0, 42.0}));
// the single argument from_json method is preferred
CHECK((f == std::vector<float>{4.0, 5.0, 6.0}));
}

namespace nlohmann
Expand Down

0 comments on commit 3affbfa

Please sign in to comment.