Repository: mesos Updated Branches: refs/heads/master 89969592a -> da0880035
Added a not equal operator for JSON objects. For consistency, adds a non equal operator to the JSON objects. It also adds tests to the equality operators. Review: https://reviews.apache.org/r/32198 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/49ea8874 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/49ea8874 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/49ea8874 Branch: refs/heads/master Commit: 49ea8874ca52c6f868de77c4d99cd8a44b0a6f4f Parents: 8996959 Author: Alexander Rojas <[email protected]> Authored: Thu May 7 13:38:11 2015 -0700 Committer: Till Toenshoff <[email protected]> Committed: Thu May 7 14:30:22 2015 -0700 ---------------------------------------------------------------------- .../3rdparty/stout/include/stout/json.hpp | 6 ++ .../3rdparty/stout/tests/json_tests.cpp | 59 ++++++++++++++++++++ 2 files changed, 65 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/49ea8874/3rdparty/libprocess/3rdparty/stout/include/stout/json.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/json.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/json.hpp index 334c898..2337337 100644 --- a/3rdparty/libprocess/3rdparty/stout/include/stout/json.hpp +++ b/3rdparty/libprocess/3rdparty/stout/include/stout/json.hpp @@ -346,6 +346,12 @@ inline bool operator == (const Value& lhs, const Value& rhs) } +inline bool operator != (const Value& lhs, const Value& rhs) +{ + return !(lhs == rhs); +} + + inline std::ostream& operator << (std::ostream& out, const String& string) { // TODO(benh): This escaping DOES NOT handle unicode, it encodes as ASCII. http://git-wip-us.apache.org/repos/asf/mesos/blob/49ea8874/3rdparty/libprocess/3rdparty/stout/tests/json_tests.cpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/3rdparty/stout/tests/json_tests.cpp b/3rdparty/libprocess/3rdparty/stout/tests/json_tests.cpp index f60d1bb..d1f0248 100644 --- a/3rdparty/libprocess/3rdparty/stout/tests/json_tests.cpp +++ b/3rdparty/libprocess/3rdparty/stout/tests/json_tests.cpp @@ -244,3 +244,62 @@ TEST(JsonTest, Find) // Also test getting JSON::Value when you don't know the type. ASSERT_SOME(object.find<JSON::Value>("nested1.nested2.null")); } + + +// Test the equality operator between two objects. +TEST(JsonTest, Equals) +{ + // Array checks. + Try<JSON::Value> _array = JSON::parse("{\"array\" : [1, 2, 3]}"); + ASSERT_SOME(_array); + const JSON::Value array = _array.get(); + + EXPECT_SOME_EQ(array, JSON::parse("{\"array\" : [1, 2, 3]}")); + EXPECT_SOME_NE(array, JSON::parse("{\"array\" : [3, 2, 1, 0]}")); + EXPECT_SOME_NE(array, JSON::parse("{\"array\" : [1, 2, 3, 4]}")); + EXPECT_SOME_NE(array, JSON::parse("{\"array\" : [3, 2, 1]}")); + EXPECT_SOME_NE(array, JSON::parse("{\"array\" : [1, 2, 4]}")); + EXPECT_SOME_NE(array, JSON::parse("{\"array\" : [1, 2]}")); + EXPECT_SOME_NE(array, JSON::parse("{\"array\" : []}")); + EXPECT_SOME_NE(array, JSON::parse("{\"array\" : null}")); + EXPECT_SOME_NE(array, JSON::parse("{\"array\" : 42}")); + + // Boolean checks. + Try<JSON::Value> _boolean = JSON::parse("{\"boolean\" : true}"); + ASSERT_SOME(_boolean); + const JSON::Value boolean = _boolean.get(); + + EXPECT_SOME_EQ(boolean, JSON::parse("{\"boolean\" : true}")); + EXPECT_SOME_NE(boolean, JSON::parse("{\"boolean\" : false}")); + EXPECT_SOME_NE(boolean, JSON::parse("{\"boolean\" : null}")); + EXPECT_SOME_NE(boolean, JSON::parse("{\"boolean\" : 42}")); + + // Null checks. + Try<JSON::Value> _nullEntry = JSON::parse("{\"null_entry\" : null}"); + ASSERT_SOME(_nullEntry); + const JSON::Value nullEntry = _nullEntry.get(); + + EXPECT_SOME_EQ(nullEntry, JSON::parse("{\"null_entry\" : null}")); + EXPECT_SOME_NE(nullEntry, JSON::parse("{\"null_entry\" : 42}")); + + // String checks. + Try<JSON::Value> _str = JSON::parse("{\"string\" : \"Hello World!\"}"); + ASSERT_SOME(_str); + const JSON::Value str = _str.get(); + + EXPECT_SOME_EQ(str, JSON::parse("{\"string\" : \"Hello World!\"}")); + EXPECT_SOME_NE(str, JSON::parse("{\"string\" : \"Goodbye World!\"}")); + EXPECT_SOME_NE(str, JSON::parse("{\"string\" : \"\"}")); + EXPECT_SOME_NE(str, JSON::parse("{\"string\" : null}")); + EXPECT_SOME_NE(str, JSON::parse("{\"string\" : 42}")); + + // Object's checks. + Try<JSON::Value> _object = JSON::parse("{\"a\" : 1, \"b\" : 2}"); + ASSERT_SOME(_object); + const JSON::Value object = _object.get(); + + EXPECT_SOME_EQ(object, JSON::parse("{\"a\" : 1, \"b\" : 2}")); + EXPECT_SOME_NE(object, JSON::parse("{\"a\" : 1, \"b\" : []}")); + EXPECT_SOME_NE(object, JSON::parse("{\"a\" : 1}")); + EXPECT_SOME_NE(object, JSON::parse("{}")); +}
