1 //===-- StructuredDataTest.cpp --------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "gtest/gtest.h"
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"
18 using namespace lldb_private
;
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")"},
26 for (auto P : TestCases) {
28 const bool pretty_print = false;
29 StructuredData::String(P.first).Dump(S, pretty_print);
30 EXPECT_EQ(P.second, S.GetString());
34 TEST(StructuredDataTest, ParseJSONFromFile) {
36 auto object_sp = StructuredData::ParseJSONFromFile(
37 FileSpec("non
-existing
-file
.json
"), status);
38 EXPECT_EQ(nullptr, object_sp);
40 std::string input = GetInputFilePath("StructuredData
-basic
.json
");
41 object_sp = StructuredData::ParseJSONFromFile(FileSpec(input), status);
42 ASSERT_NE(nullptr, object_sp);
45 object_sp->Dump(S, false);
46 EXPECT_EQ("[1,2,3]", S.GetString());