[llvm] f1b2be4 - [MsgPack] Added a convenience operator
Saiyedul Islam via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 5 05:45:08 PDT 2020
Author: Dineshkumar Bhaskaran
Date: 2020-06-05T12:44:51Z
New Revision: f1b2be416dc52d9e2323773c26ba58101acd21ba
URL: https://github.com/llvm/llvm-project/commit/f1b2be416dc52d9e2323773c26ba58101acd21ba
DIFF: https://github.com/llvm/llvm-project/commit/f1b2be416dc52d9e2323773c26ba58101acd21ba.diff
LOG: [MsgPack] Added a convenience operator
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
Added:
Modified:
llvm/include/llvm/BinaryFormat/MsgPackDocument.h
llvm/unittests/BinaryFormat/MsgPackDocumentTest.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/BinaryFormat/MsgPackDocument.h b/llvm/include/llvm/BinaryFormat/MsgPackDocument.h
index 2bf9ed86846e..91778f6a99df 100644
--- a/llvm/include/llvm/BinaryFormat/MsgPackDocument.h
+++ b/llvm/include/llvm/BinaryFormat/MsgPackDocument.h
@@ -181,6 +181,11 @@ class DocNode {
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;
diff --git a/llvm/unittests/BinaryFormat/MsgPackDocumentTest.cpp b/llvm/unittests/BinaryFormat/MsgPackDocumentTest.cpp
index f301567afc7f..0a7b59afe728 100644
--- a/llvm/unittests/BinaryFormat/MsgPackDocumentTest.cpp
+++ b/llvm/unittests/BinaryFormat/MsgPackDocumentTest.cpp
@@ -13,6 +13,16 @@
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);
More information about the llvm-commits
mailing list