[MsgPack] Added a convenience operator
authorDineshkumar Bhaskaran <dineshkumar.bhaskaran@amd.com>
Fri, 5 Jun 2020 12:41:37 +0000 (12:41 +0000)
committerSaiyedul Islam <Saiyedul.Islam@amd.com>
Fri, 5 Jun 2020 12:44:51 +0000 (12:44 +0000)
Summary: Added "not equal to" operator for DocNode comparison

Reviewers: arsenm, scott.linder, saiislam

Reviewed By: saiislam

Subscribers: wdng, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D81250

llvm/include/llvm/BinaryFormat/MsgPackDocument.h
llvm/unittests/BinaryFormat/MsgPackDocumentTest.cpp

index 2bf9ed8..91778f6 100644 (file)
@@ -181,6 +181,11 @@ public:
     return !(Lhs < Rhs) && !(Rhs < Lhs);
   }
 
+  /// Inequality operator
+  friend bool operator!=(const DocNode &Lhs, const DocNode &Rhs) {
+    return !(Lhs == Rhs);
+  }
+
   /// Convert this node to a string, assuming it is scalar.
   std::string toString() const;
 
index f301567..0a7b59a 100644 (file)
 using namespace llvm;
 using namespace msgpack;
 
+TEST(MsgPackDocument, DocNodeTest) {
+  Document Doc;
+
+  DocNode Int1 = Doc.getNode(1), Int2 = Doc.getNode(2);
+  DocNode Str1 = Doc.getNode("ab"), Str2 = Doc.getNode("ab");
+
+  ASSERT_TRUE(Int1 != Int2);
+  ASSERT_TRUE(Str1 == Str2);
+}
+
 TEST(MsgPackDocument, TestReadInt) {
   Document Doc;
   bool Ok = Doc.readFromBlob(StringRef("\xd0\x00", 2), /*Multi=*/false);