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