summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/Support/JSONTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/unittests/Support/JSONTest.cpp')
-rw-r--r--llvm/unittests/Support/JSONTest.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/llvm/unittests/Support/JSONTest.cpp b/llvm/unittests/Support/JSONTest.cpp
index 23645b35f43..14c11b1c4ed 100644
--- a/llvm/unittests/Support/JSONTest.cpp
+++ b/llvm/unittests/Support/JSONTest.cpp
@@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/Support/JSON.h"
+#include "llvm/Support/raw_ostream.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
@@ -383,6 +384,44 @@ TEST(JSONTest, Deserialize) {
<< "Wrong type for Optional<T> " << V;
}
+TEST(JSONTest, Stream) {
+ auto StreamStuff = [](unsigned Indent) {
+ std::string S;
+ llvm::raw_string_ostream OS(S);
+ OStream J(OS, Indent);
+ J.object([&] {
+ J.attributeArray("foo", [&] {
+ J.value(nullptr);
+ J.value(42.5);
+ J.arrayBegin();
+ J.value(43);
+ J.arrayEnd();
+ });
+ J.attributeBegin("bar");
+ J.objectBegin();
+ J.objectEnd();
+ J.attributeEnd();
+ J.attribute("baz", "xyz");
+ });
+ return OS.str();
+ };
+
+ const char *Plain = R"({"foo":[null,42.5,[43]],"bar":{},"baz":"xyz"})";
+ EXPECT_EQ(Plain, StreamStuff(0));
+ const char *Pretty = R"({
+ "foo": [
+ null,
+ 42.5,
+ [
+ 43
+ ]
+ ],
+ "bar": {},
+ "baz": "xyz"
+})";
+ EXPECT_EQ(Pretty, StreamStuff(2));
+}
+
} // namespace
} // namespace json
} // namespace llvm
OpenPOWER on IntegriCloud