more test cases
This commit is contained in:
parent
583d20a3b1
commit
4361c4d03f
3 changed files with 63 additions and 4 deletions
11
src/json.hpp
11
src/json.hpp
|
@ -1,3 +1,12 @@
|
||||||
|
/*!
|
||||||
|
@file
|
||||||
|
@copyright The code is licensed under the MIT License
|
||||||
|
<http://opensource.org/licenses/MIT>,
|
||||||
|
Copyright (c) 2013-2015 Niels Lohmann.
|
||||||
|
@author Niels Lohmann <http://nlohmann.me>
|
||||||
|
@see https://github.com/nlohmann/json
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef _NLOHMANN_JSON
|
#ifndef _NLOHMANN_JSON
|
||||||
#define _NLOHMANN_JSON
|
#define _NLOHMANN_JSON
|
||||||
|
|
||||||
|
@ -1026,14 +1035,12 @@ class basic_json
|
||||||
m_value.object->insert(value);
|
m_value.object->insert(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
/// add an object to an object
|
/// add an object to an object
|
||||||
inline reference operator+=(const typename object_t::value_type& value)
|
inline reference operator+=(const typename object_t::value_type& value)
|
||||||
{
|
{
|
||||||
push_back(value);
|
push_back(value);
|
||||||
return operator[](value.first);
|
return operator[](value.first);
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
/// swaps the contents
|
/// swaps the contents
|
||||||
inline void swap(reference other) noexcept
|
inline void swap(reference other) noexcept
|
||||||
|
|
|
@ -1,3 +1,12 @@
|
||||||
|
/*!
|
||||||
|
@file
|
||||||
|
@copyright The code is licensed under the MIT License
|
||||||
|
<http://opensource.org/licenses/MIT>,
|
||||||
|
Copyright (c) 2013-2015 Niels Lohmann.
|
||||||
|
@author Niels Lohmann <http://nlohmann.me>
|
||||||
|
@see https://github.com/nlohmann/json
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef _NLOHMANN_JSON
|
#ifndef _NLOHMANN_JSON
|
||||||
#define _NLOHMANN_JSON
|
#define _NLOHMANN_JSON
|
||||||
|
|
||||||
|
@ -1026,14 +1035,12 @@ class basic_json
|
||||||
m_value.object->insert(value);
|
m_value.object->insert(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
/// add an object to an object
|
/// add an object to an object
|
||||||
inline reference operator+=(const typename object_t::value_type& value)
|
inline reference operator+=(const typename object_t::value_type& value)
|
||||||
{
|
{
|
||||||
push_back(value);
|
push_back(value);
|
||||||
return operator[](value.first);
|
return operator[](value.first);
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
/// swaps the contents
|
/// swaps the contents
|
||||||
inline void swap(reference other) noexcept
|
inline void swap(reference other) noexcept
|
||||||
|
|
|
@ -1,3 +1,12 @@
|
||||||
|
/*!
|
||||||
|
@file
|
||||||
|
@copyright The code is licensed under the MIT License
|
||||||
|
<http://opensource.org/licenses/MIT>,
|
||||||
|
Copyright (c) 2013-2015 Niels Lohmann.
|
||||||
|
@author Niels Lohmann <http://nlohmann.me>
|
||||||
|
@see https://github.com/nlohmann/json
|
||||||
|
*/
|
||||||
|
|
||||||
#define CATCH_CONFIG_MAIN
|
#define CATCH_CONFIG_MAIN
|
||||||
#include "catch.hpp"
|
#include "catch.hpp"
|
||||||
|
|
||||||
|
@ -3553,6 +3562,16 @@ TEST_CASE("modifiers")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SECTION("to object")
|
||||||
|
{
|
||||||
|
json j(json::value_t::object);
|
||||||
|
j.push_back(json::object_t::value_type({"one", 1}));
|
||||||
|
j.push_back(json::object_t::value_type({"two", 2}));
|
||||||
|
CHECK(j.size() == 2);
|
||||||
|
CHECK(j["one"] == json(1));
|
||||||
|
CHECK(j["two"] == json(2));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("operator+=")
|
SECTION("operator+=")
|
||||||
|
@ -3614,6 +3633,16 @@ TEST_CASE("modifiers")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SECTION("to object")
|
||||||
|
{
|
||||||
|
json j(json::value_t::object);
|
||||||
|
j += json::object_t::value_type({"one", 1});
|
||||||
|
j += json::object_t::value_type({"two", 2});
|
||||||
|
CHECK(j.size() == 2);
|
||||||
|
CHECK(j["one"] == json(1));
|
||||||
|
CHECK(j["two"] == json(2));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("swap()")
|
SECTION("swap()")
|
||||||
|
@ -5073,11 +5102,23 @@ TEST_CASE("parser class")
|
||||||
CHECK(json::parser("0.999").parse() == json(0.999));
|
CHECK(json::parser("0.999").parse() == json(0.999));
|
||||||
CHECK(json::parser("128.5").parse() == json(128.5));
|
CHECK(json::parser("128.5").parse() == json(128.5));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SECTION("with exponent")
|
||||||
|
{
|
||||||
|
CHECK(json::parser("-128.5E3").parse() == json(-128.5E3));
|
||||||
|
CHECK(json::parser("-128.5E-3").parse() == json(-128.5E-3));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("invalid numbers")
|
SECTION("invalid numbers")
|
||||||
{
|
{
|
||||||
CHECK_THROWS_AS(json::parser("01").parse(), std::invalid_argument);
|
CHECK_THROWS_AS(json::parser("01").parse(), std::invalid_argument);
|
||||||
|
CHECK_THROWS_AS(json::parser("--1").parse(), std::invalid_argument);
|
||||||
|
CHECK_THROWS_AS(json::parser("1.").parse(), std::invalid_argument);
|
||||||
|
CHECK_THROWS_AS(json::parser("1E").parse(), std::invalid_argument);
|
||||||
|
CHECK_THROWS_AS(json::parser("1E-").parse(), std::invalid_argument);
|
||||||
|
CHECK_THROWS_AS(json::parser("1.E1").parse(), std::invalid_argument);
|
||||||
|
CHECK_THROWS_AS(json::parser("-1E").parse(), std::invalid_argument);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5119,8 +5160,11 @@ TEST_CASE("parser class")
|
||||||
CHECK_THROWS_AS(json::parser("fals").parse(), std::invalid_argument);
|
CHECK_THROWS_AS(json::parser("fals").parse(), std::invalid_argument);
|
||||||
|
|
||||||
// unexpected end of array
|
// unexpected end of array
|
||||||
|
CHECK_THROWS_AS(json::parser("[").parse(), std::invalid_argument);
|
||||||
|
CHECK_THROWS_AS(json::parser("[1").parse(), std::invalid_argument);
|
||||||
CHECK_THROWS_AS(json::parser("[1,").parse(), std::invalid_argument);
|
CHECK_THROWS_AS(json::parser("[1,").parse(), std::invalid_argument);
|
||||||
CHECK_THROWS_AS(json::parser("[1,]").parse(), std::invalid_argument);
|
CHECK_THROWS_AS(json::parser("[1,]").parse(), std::invalid_argument);
|
||||||
|
CHECK_THROWS_AS(json::parser("]").parse(), std::invalid_argument);
|
||||||
|
|
||||||
// unexpected end of object
|
// unexpected end of object
|
||||||
CHECK_THROWS_AS(json::parser("{").parse(), std::invalid_argument);
|
CHECK_THROWS_AS(json::parser("{").parse(), std::invalid_argument);
|
||||||
|
@ -5128,6 +5172,7 @@ TEST_CASE("parser class")
|
||||||
CHECK_THROWS_AS(json::parser("{\"foo\":").parse(), std::invalid_argument);
|
CHECK_THROWS_AS(json::parser("{\"foo\":").parse(), std::invalid_argument);
|
||||||
CHECK_THROWS_AS(json::parser("{\"foo\":}").parse(), std::invalid_argument);
|
CHECK_THROWS_AS(json::parser("{\"foo\":}").parse(), std::invalid_argument);
|
||||||
CHECK_THROWS_AS(json::parser("{\"foo\":1,}").parse(), std::invalid_argument);
|
CHECK_THROWS_AS(json::parser("{\"foo\":1,}").parse(), std::invalid_argument);
|
||||||
|
CHECK_THROWS_AS(json::parser("}").parse(), std::invalid_argument);
|
||||||
|
|
||||||
// unexpected end of string
|
// unexpected end of string
|
||||||
CHECK_THROWS_AS(json::parser("\"").parse(), std::invalid_argument);
|
CHECK_THROWS_AS(json::parser("\"").parse(), std::invalid_argument);
|
||||||
|
|
Loading…
Reference in a new issue