[ARM] Remove declaration of unimplemented function. NFC.
[llvm-complete.git] / unittests / BinaryFormat / MsgPackDocumentTest.cpp
blob00b157963f68c9d21d0ea1d0339d49d8a8cf73fd
1 //===- MsgPackDocumentTest.cpp --------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
10 #include "llvm/BinaryFormat/MsgPackDocument.h"
11 #include "gtest/gtest.h"
13 using namespace llvm;
14 using namespace msgpack;
16 TEST(MsgPackDocument, TestReadInt) {
17 Document Doc;
18 bool Ok = Doc.readFromBlob(StringRef("\xd0\x00", 2), /*Multi=*/false);
19 ASSERT_TRUE(Ok);
20 ASSERT_EQ(Doc.getRoot().getKind(), Type::Int);
21 ASSERT_EQ(Doc.getRoot().getInt(), 0);
24 TEST(MsgPackDocument, TestReadArray) {
25 Document Doc;
26 bool Ok = Doc.readFromBlob(StringRef("\x92\xd0\x01\xc0"), /*Multi=*/false);
27 ASSERT_TRUE(Ok);
28 ASSERT_EQ(Doc.getRoot().getKind(), Type::Array);
29 auto A = Doc.getRoot().getArray();
30 ASSERT_EQ(A.size(), 2u);
31 auto SI = A[0];
32 ASSERT_EQ(SI.getKind(), Type::Int);
33 ASSERT_EQ(SI.getInt(), 1);
34 auto SN = A[1];
35 ASSERT_EQ(SN.getKind(), Type::Nil);
38 TEST(MsgPackDocument, TestReadMap) {
39 Document Doc;
40 bool Ok = Doc.readFromBlob(StringRef("\x82\xa3"
41 "foo"
42 "\xd0\x01\xa3"
43 "bar"
44 "\xd0\x02"),
45 /*Multi=*/false);
46 ASSERT_TRUE(Ok);
47 ASSERT_EQ(Doc.getRoot().getKind(), Type::Map);
48 auto M = Doc.getRoot().getMap();
49 ASSERT_EQ(M.size(), 2u);
50 auto FooS = M["foo"];
51 ASSERT_EQ(FooS.getKind(), Type::Int);
52 ASSERT_EQ(FooS.getInt(), 1);
53 auto BarS = M["bar"];
54 ASSERT_EQ(BarS.getKind(), Type::Int);
55 ASSERT_EQ(BarS.getInt(), 2);
58 TEST(MsgPackDocument, TestWriteInt) {
59 Document Doc;
60 Doc.getRoot() = Doc.getNode(int64_t(1));
61 std::string Buffer;
62 Doc.writeToBlob(Buffer);
63 ASSERT_EQ(Buffer, "\x01");
66 TEST(MsgPackDocument, TestWriteArray) {
67 Document Doc;
68 auto A = Doc.getRoot().getArray(/*Convert=*/true);
69 A.push_back(Doc.getNode(int64_t(1)));
70 A.push_back(Doc.getNode());
71 std::string Buffer;
72 Doc.writeToBlob(Buffer);
73 ASSERT_EQ(Buffer, "\x92\x01\xc0");
76 TEST(MsgPackDocument, TestWriteMap) {
77 Document Doc;
78 auto M = Doc.getRoot().getMap(/*Convert=*/true);
79 M["foo"] = Doc.getNode(int64_t(1));
80 M["bar"] = Doc.getNode(int64_t(2));
81 std::string Buffer;
82 Doc.writeToBlob(Buffer);
83 ASSERT_EQ(Buffer, "\x82\xa3"
84 "bar"
85 "\x02\xa3"
86 "foo"
87 "\x01");
90 TEST(MsgPackDocument, TestOutputYAMLArray) {
91 Document Doc;
92 auto A = Doc.getRoot().getArray(/*Convert=*/true);
93 A.push_back(Doc.getNode(int64_t(1)));
94 A.push_back(Doc.getNode(int64_t(2)));
95 std::string Buffer;
96 raw_string_ostream OStream(Buffer);
97 Doc.toYAML(OStream);
98 ASSERT_EQ(OStream.str(), "---\n- 1\n- 2\n...\n");
101 TEST(MsgPackDocument, TestInputYAMLArray) {
102 Document Doc;
103 bool Ok = Doc.fromYAML("---\n- !int 0x1\n- !str 2\n...\n");
104 ASSERT_TRUE(Ok);
105 ASSERT_EQ(Doc.getRoot().getKind(), Type::Array);
106 auto A = Doc.getRoot().getArray();
107 ASSERT_EQ(A.size(), 2u);
108 auto SI = A[0];
109 ASSERT_EQ(SI.getKind(), Type::UInt);
110 ASSERT_EQ(SI.getUInt(), 1u);
111 auto SS = A[1];
112 ASSERT_EQ(SS.getKind(), Type::String);
113 ASSERT_EQ(SS.getString(), "2");
116 TEST(MsgPackDocument, TestOutputYAMLMap) {
117 Document Doc;
118 auto M = Doc.getRoot().getMap(/*Convert=*/true);
119 M["foo"] = Doc.getNode(int64_t(1));
120 M["bar"] = Doc.getNode(uint64_t(2));
121 auto N = Doc.getMapNode();
122 M["qux"] = N;
123 N["baz"] = Doc.getNode(true);
124 std::string Buffer;
125 raw_string_ostream OStream(Buffer);
126 Doc.toYAML(OStream);
127 ASSERT_EQ(OStream.str(), "---\n"
128 "bar: 2\n"
129 "foo: 1\n"
130 "qux:\n"
131 " baz: true\n"
132 "...\n");
135 TEST(MsgPackDocument, TestOutputYAMLMapHex) {
136 Document Doc;
137 Doc.setHexMode();
138 auto M = Doc.getRoot().getMap(/*Convert=*/true);
139 M["foo"] = Doc.getNode(int64_t(1));
140 M["bar"] = Doc.getNode(uint64_t(2));
141 auto N = Doc.getMapNode();
142 M["qux"] = N;
143 N["baz"] = Doc.getNode(true);
144 std::string Buffer;
145 raw_string_ostream OStream(Buffer);
146 Doc.toYAML(OStream);
147 ASSERT_EQ(OStream.str(), "---\n"
148 "bar: 0x2\n"
149 "foo: 1\n"
150 "qux:\n"
151 " baz: true\n"
152 "...\n");
155 TEST(MsgPackDocument, TestInputYAMLMap) {
156 Document Doc;
157 bool Ok = Doc.fromYAML("---\nfoo: !int 0x1\nbaz: !str 2\n...\n");
158 ASSERT_TRUE(Ok);
159 ASSERT_EQ(Doc.getRoot().getKind(), Type::Map);
160 auto M = Doc.getRoot().getMap();
161 ASSERT_EQ(M.size(), 2u);
162 auto SI = M["foo"];
163 ASSERT_EQ(SI.getKind(), Type::UInt);
164 ASSERT_EQ(SI.getUInt(), 1u);
165 auto SS = M["baz"];
166 ASSERT_EQ(SS.getKind(), Type::String);
167 ASSERT_EQ(SS.getString(), "2");