From 58cef11a28eb4abe9eb055ce4ada18eaa2bc3205 Mon Sep 17 00:00:00 2001 From: Florian Albrechtskirchinger Date: Tue, 2 Aug 2022 08:10:00 +0200 Subject: [PATCH] Add checks to unit test readme --- tests/src/unit-readme.cpp | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/tests/src/unit-readme.cpp b/tests/src/unit-readme.cpp index 6d296f02f..00d34c170 100644 --- a/tests/src/unit-readme.cpp +++ b/tests/src/unit-readme.cpp @@ -106,12 +106,10 @@ TEST_CASE("README" * doctest::skip()) json j = "{ \"happy\": true, \"pi\": 3.141 }"_json; // NOLINT(modernize-raw-string-literal) // or even nicer with a raw string literal - auto j2 = R"( - { - "happy": true, - "pi": 3.141 - } - )"_json; + auto j2 = R"({ + "happy": true, + "pi": 3.141 + })"_json; // or explicitly auto j3 = json::parse(R"({"happy": true, "pi": 3.141})"); @@ -160,10 +158,10 @@ TEST_CASE("README" * doctest::skip()) CHECK(foo == true); // other stuff - j.size(); // 3 entries - j.empty(); // false - j.type(); // json::value_t::array - j.clear(); // the array is empty again + CHECK(j.size() == 3); // 3 entries + CHECK_FALSE(j.empty()); // false + CHECK(j.type() == json::value_t::array); // json::value_t::array + j.clear(); // the array is empty again // create an object json o; @@ -172,6 +170,7 @@ TEST_CASE("README" * doctest::skip()) o["baz"] = 3.141; // find an entry + CHECK(o.find("foo") != o.end()); if (o.find("foo") != o.end()) { // there is an entry with key "foo" @@ -266,9 +265,9 @@ TEST_CASE("README" * doctest::skip()) { // a JSON value json j_original = R"({ - "baz": ["one", "two", "three"], - "foo": "bar" - })"_json; + "baz": ["one", "two", "three"], + "foo": "bar" + })"_json; // access members with a JSON pointer (RFC 6901) j_original["/baz/1"_json_pointer]; @@ -276,10 +275,10 @@ TEST_CASE("README" * doctest::skip()) // a JSON patch (RFC 6902) json j_patch = R"([ - { "op": "replace", "path": "/baz", "value": "boo" }, - { "op": "add", "path": "/hello", "value": ["world"] }, - { "op": "remove", "path": "/foo"} - ])"_json; + { "op": "replace", "path": "/baz", "value": "boo" }, + { "op": "add", "path": "/hello", "value": ["world"] }, + { "op": "remove", "path": "/foo"} + ])"_json; // apply the patch json j_result = j_original.patch(j_patch);