From ccbbe8d0f02e7ce6bf0b04b7457b0aa652fb5009 Mon Sep 17 00:00:00 2001 From: Dickson Wu <33645481+DicksonWu654@users.noreply.github.com> Date: Mon, 23 Nov 2026 02:31:31 -0500 Subject: [PATCH] Add RFC 7396 section 2 merge patch test cases (#6153) Signed-off-by: Niels Lohmann --- tests/src/unit-merge_patch.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/src/unit-merge_patch.cpp b/tests/src/unit-merge_patch.cpp index bb48cf070..2cb973a38 100644 --- a/tests/src/unit-merge_patch.cpp +++ b/tests/src/unit-merge_patch.cpp @@ -295,6 +295,29 @@ TEST_CASE("JSON Merge Patch") } } } + + SECTION("derived from RFC 7396 section 2") + { + SECTION("empty object patch") + { + json document = R"({"keep":1,"nested":{"x":2}})"_json; + json const patch = R"({})"_json; + json expected = R"({"keep":1,"nested":{"x":2}})"_json; + + document.merge_patch(patch); + CHECK(document == expected); + } + + SECTION("object patch over null target") + { + json document = nullptr; + json const patch = R"({"a":1})"_json; + json expected = R"({"a":1})"_json; + + document.merge_patch(patch); + CHECK(document == expected); + } + } } TEST_CASE("JSON Merge Patch on deeply nested values")