added test cases and fixed some warnings

pull/36/head
Niels 2015-02-09 20:21:26 +01:00
parent 0df642ded0
commit 0cfd0f5d68
3 changed files with 115 additions and 8 deletions

View File

@ -443,8 +443,9 @@ class basic_json
}
/// copy assignment
inline reference operator=(basic_json other) noexcept
inline reference& operator=(basic_json other) noexcept
{
assert(false); // not sure if function will ever be called
std::swap(m_type, other.m_type);
std::swap(m_value, other.m_value);
return *this;
@ -1704,6 +1705,7 @@ class basic_json
/// copy assignment
inline iterator& operator=(const iterator& other) noexcept
{
assert(false); // not sure if function will ever be called
m_object = other.m_object;
m_it = other.m_it;
return *this;
@ -2085,7 +2087,7 @@ class basic_json
}
/// copy assignment
inline const_iterator operator=(const const_iterator& other) noexcept
inline const_iterator& operator=(const const_iterator& other) noexcept
{
m_object = other.m_object;
m_it = other.m_it;
@ -3329,7 +3331,7 @@ json_parser_60:
}
}
inline std::string token_type_name(token_type t)
inline static std::string token_type_name(token_type t)
{
switch (t)
{

View File

@ -443,8 +443,9 @@ class basic_json
}
/// copy assignment
inline reference operator=(basic_json other) noexcept
inline reference& operator=(basic_json other) noexcept
{
assert(false); // not sure if function will ever be called
std::swap(m_type, other.m_type);
std::swap(m_value, other.m_value);
return *this;
@ -1704,6 +1705,7 @@ class basic_json
/// copy assignment
inline iterator& operator=(const iterator& other) noexcept
{
assert(false); // not sure if function will ever be called
m_object = other.m_object;
m_it = other.m_it;
return *this;
@ -2085,7 +2087,7 @@ class basic_json
}
/// copy assignment
inline const_iterator operator=(const const_iterator& other) noexcept
inline const_iterator& operator=(const const_iterator& other) noexcept
{
m_object = other.m_object;
m_it = other.m_it;
@ -2689,7 +2691,7 @@ class basic_json
}
}
inline std::string token_type_name(token_type t)
inline static std::string token_type_name(token_type t)
{
switch (t)
{

View File

@ -2518,8 +2518,8 @@ TEST_CASE("iterators")
SECTION("const json + begin/end")
{
json::iterator it_begin = j_const.begin();
json::iterator it_end = j_const.end();
json::const_iterator it_begin = j_const.begin();
json::const_iterator it_end = j_const.end();
auto it = it_begin;
CHECK(it != it_end);
@ -3464,4 +3464,107 @@ TEST_CASE("modifiers")
CHECK(j == json(json::value_t::null));
}
}
SECTION("swap()")
{
SECTION("json")
{
SECTION("member swap")
{
json j("hello world");
json k(42.23);
j.swap(k);
CHECK(j == json(42.23));
CHECK(k == json("hello world"));
}
SECTION("nonmember swap")
{
json j("hello world");
json k(42.23);
std::swap(j, k);
CHECK(j == json(42.23));
CHECK(k == json("hello world"));
}
}
SECTION("array_t")
{
SECTION("array_t type")
{
json j = {1, 2, 3, 4};
json::array_t a = {"foo", "bar", "baz"};
j.swap(a);
CHECK(j == json({"foo", "bar", "baz"}));
j.swap(a);
CHECK(j == json({1, 2, 3, 4}));
}
SECTION("non-array_t type")
{
json j = 17;
json::array_t a = {"foo", "bar", "baz"};
CHECK_THROWS_AS(j.swap(a), std::runtime_error);
}
}
SECTION("object_t")
{
SECTION("object_t type")
{
json j = {{"one", 1}, {"two", 2}};
json::object_t o = {{"cow", "Kuh"}, {"chicken", "Huhn"}};
j.swap(o);
CHECK(j == json({{"cow", "Kuh"}, {"chicken", "Huhn"}}));
j.swap(o);
CHECK(j == json({{"one", 1}, {"two", 2}}));
}
SECTION("non-object_t type")
{
json j = 17;
json::object_t o = {{"cow", "Kuh"}, {"chicken", "Huhn"}};
CHECK_THROWS_AS(j.swap(o), std::runtime_error);
}
}
SECTION("string_t")
{
SECTION("string_t type")
{
json j = "Hello world";
json::string_t s = "Hallo Welt";
j.swap(s);
CHECK(j == json("Hallo Welt"));
j.swap(s);
CHECK(j == json("Hello world"));
}
SECTION("non-string_t type")
{
json j = 17;
json::string_t s = "Hallo Welt";
CHECK_THROWS_AS(j.swap(s), std::runtime_error);
}
}
}
}