Commit f466919e authored by chenguoping's avatar chenguoping

change test cases

parent 8aaa4013
......@@ -148,45 +148,6 @@ TEST_CASE("element access 2")
SECTION("access specified element with default value")
{
SECTION("move semantics")
{
SECTION("json is rvalue")
{
json j = {{"x", "123"}};
std::string defval = "default";
auto val = std::move(j).value("x", defval);
CHECK(j["x"] == "");
CHECK(defval == "default");
CHECK(val == "123");
}
SECTION("default is rvalue")
{
json j = {{"x", "123"}};
std::string defval = "default";
auto val = std::move(j).value("y", std::move(defval));
CHECK(j["x"] == "123");
CHECK(defval == "");
CHECK(val == "default");
}
SECTION("access on non-object value")
{
json j_nonobject(json::value_t::array);
const json j_nonobject_const(j_nonobject);
std::string defval = "default";
CHECK_THROWS_AS(std::move(j_nonobject).value("foo", defval), json::type_error&);
CHECK_THROWS_AS(std::move(j_nonobject_const).value("foo", defval), json::type_error&);
CHECK_THROWS_WITH(std::move(j_nonobject).value("foo", defval),
"[json.exception.type_error.306] cannot use value() with array");
CHECK_THROWS_WITH(std::move(j_nonobject_const).value("foo", defval),
"[json.exception.type_error.306] cannot use value() with array");
}
}
SECTION("given a key")
{
SECTION("access existing value")
......@@ -226,6 +187,7 @@ TEST_CASE("element access 2")
CHECK(j.value("_", 12.34) == Approx(12.34));
CHECK(j.value("_", json({{"foo", "bar"}})) == json({{"foo", "bar"}}));
CHECK(j.value("_", json({10, 100})) == json({10, 100}));
CHECK(j.value("_", std::move("default_value")) == "default_value");
CHECK(j_const.value("_", 2) == 2);
CHECK(j_const.value("_", 2u) == 2u);
......@@ -234,6 +196,7 @@ TEST_CASE("element access 2")
CHECK(j_const.value("_", 12.34) == Approx(12.34));
CHECK(j_const.value("_", json({{"foo", "bar"}})) == json({{"foo", "bar"}}));
CHECK(j_const.value("_", json({10, 100})) == json({10, 100}));
CHECK(j_const.value("_", std::move("default_value")) == "default_value");
}
SECTION("access on non-object type")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment