From 2b179f9db25288f7c0b9bfa42356924a598bfd4f Mon Sep 17 00:00:00 2001 From: Kevin Hurley Date: Tue, 15 Sep 2015 14:06:07 -0700 Subject: [PATCH] Add unit test for update_missing Summary: Forgot to add a test for this when I added update_missing. This adds a test for it Reviewed By: @yfeldblum Differential Revision: D2441612 --- folly/test/DynamicTest.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/folly/test/DynamicTest.cpp b/folly/test/DynamicTest.cpp index 97af70be..e043d914 100644 --- a/folly/test/DynamicTest.cpp +++ b/folly/test/DynamicTest.cpp @@ -107,18 +107,31 @@ TEST(Dynamic, ObjectBasics) { dynamic mergeObj2 = folly::dynamic::object ("key2", "value3") ("key3", "value4"); - dynamic combinedObj = folly::dynamic::object + + // Merged object where we prefer the values in mergeObj2 + dynamic combinedPreferObj2 = folly::dynamic::object ("key1", "value1") ("key2", "value3") ("key3", "value4"); + + // Merged object where we prefer the values in mergeObj1 + dynamic combinedPreferObj1 = folly::dynamic::object + ("key1", "value1") + ("key2", "value2") + ("key3", "value4"); + auto newMergeObj = dynamic::merge(mergeObj1, mergeObj2); - EXPECT_EQ(newMergeObj, combinedObj); + EXPECT_EQ(newMergeObj, combinedPreferObj2); EXPECT_EQ(mergeObj1, origMergeObj1); // mergeObj1 should be unchanged mergeObj1.update(mergeObj2); - EXPECT_EQ(mergeObj1, combinedObj); + EXPECT_EQ(mergeObj1, combinedPreferObj2); dynamic arr = { 1, 2, 3, 4, 5, 6 }; EXPECT_THROW(mergeObj1.update(arr), std::exception); + + mergeObj1 = origMergeObj1; // reset it + mergeObj1.update_missing(mergeObj2); + EXPECT_EQ(mergeObj1, combinedPreferObj1); } TEST(Dynamic, ObjectErase) { -- 2.34.1