From d0df796a10f6bee78d2dd130854c58b74c0a9c8c Mon Sep 17 00:00:00 2001 From: Niels Date: Sun, 8 Feb 2015 14:54:16 +0100 Subject: [PATCH] more test cases --- test/unit.cpp | 139 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 138 insertions(+), 1 deletion(-) diff --git a/test/unit.cpp b/test/unit.cpp index 3bb530b0..1fbbd04d 100644 --- a/test/unit.cpp +++ b/test/unit.cpp @@ -15,7 +15,7 @@ using nlohmann::json; #include #include -TEST_CASE("Constructors") +TEST_CASE("constructors") { SECTION("create an empty value with a given type") { @@ -894,3 +894,140 @@ TEST_CASE("Constructors") } } } + +TEST_CASE("other constructors and destructor") +{ + SECTION("copy constructor") + { + SECTION("object") + { + json j {{"foo", 1}, {"bar", false}}; + json k(j); + CHECK(j == k); + } + + SECTION("array") + { + json j {"foo", 1, 42.23, false}; + json k(j); + CHECK(j == k); + } + + SECTION("null") + { + json j(nullptr); + json k(j); + CHECK(j == k); + } + + SECTION("boolean") + { + json j(true); + json k(j); + CHECK(j == k); + } + + SECTION("string") + { + json j("Hello world"); + json k(j); + CHECK(j == k); + } + + SECTION("number (integer)") + { + json j(42); + json k(j); + CHECK(j == k); + } + + SECTION("number (floating-point)") + { + json j(42.23); + json k(j); + CHECK(j == k); + } + } + + SECTION("move constructor") + { + json j {{"foo", "bar"}, {"baz", {1, 2, 3, 4}}, {"a", 42.23}, {"b", nullptr}}; + CHECK(j.type() == json::value_t::object); + json k(std::move(j)); + CHECK(k.type() == json::value_t::object); + CHECK(j.type() == json::value_t::null); + } + + SECTION("copy assignment") + { + SECTION("object") + { + json j {{"foo", 1}, {"bar", false}}; + json k = j; + CHECK(j == k); + } + + SECTION("array") + { + json j {"foo", 1, 42.23, false}; + json k = j; + CHECK(j == k); + } + + SECTION("null") + { + json j(nullptr); + json k = j; + CHECK(j == k); + } + + SECTION("boolean") + { + json j(true); + json k = j; + CHECK(j == k); + } + + SECTION("string") + { + json j("Hello world"); + json k = j; + CHECK(j == k); + } + + SECTION("number (integer)") + { + json j(42); + json k = j; + CHECK(j == k); + } + + SECTION("number (floating-point)") + { + json j(42.23); + json k = j; + CHECK(j == k); + } + } + + SECTION("destructor") + { + SECTION("object") + { + auto j = new json {{"foo", 1}, {"bar", false}}; + delete j; + } + + SECTION("array") + { + auto j = new json {"foo", 1, false, 23.42}; + delete j; + } + + SECTION("string") + { + auto j = new json("Hello world"); + delete j; + } + } +}