1 //===-- StructuredDataTest.cpp --------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "gtest/gtest.h"
10
11 #include "TestingSupport/TestUtilities.h"
12 #include "lldb/Utility/Status.h"
13 #include "lldb/Utility/StreamString.h"
14 #include "lldb/Utility/StructuredData.h"
15 #include "llvm/Support/Path.h"
16
17 using namespace lldb;
18 using namespace lldb_private;
19
TEST(StructuredDataTest,StringDump)20 TEST(StructuredDataTest, StringDump) {
21 std::pair<llvm::StringRef, llvm::StringRef> TestCases[] = {
22 {R"(asdfg)", R"("asdfg")"},
23 {R"(as"df)", R"("as\"df")"},
24 {R"(as\df)", R"("as\\df")"},
25 };
26 for (auto P : TestCases) {
27 StreamString S;
28 const bool pretty_print = false;
29 StructuredData::String(P.first).Dump(S, pretty_print);
30 EXPECT_EQ(P.second, S.GetString());
31 }
32 }
33
34 TEST(StructuredDataTest, ParseJSONFromFile) {
35 Status status;
36 auto object_sp = StructuredData::ParseJSONFromFile(
37 FileSpec("non-existing-file.json"), status);
38 EXPECT_EQ(nullptr, object_sp);
39
40 std::string input = GetInputFilePath("StructuredData-basic.json");
41 object_sp = StructuredData::ParseJSONFromFile(FileSpec(input), status);
42 ASSERT_NE(nullptr, object_sp);
43
44 StreamString S;
45 object_sp->Dump(S, false);
46 EXPECT_EQ("[1,2,3]", S.GetString());
47 }
48