1 //===-- FormatEntityTest.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 "lldb/Core/FormatEntity.h"
10 #include "lldb/Utility/Status.h"
12 #include "llvm/ADT/StringRef.h"
13 #include "gtest/gtest.h"
15 using namespace lldb_private
;
17 using Definition
= FormatEntity::Entry::Definition
;
18 using Entry
= FormatEntity::Entry
;
20 TEST(FormatEntityTest
, DefinitionConstructionNameAndType
) {
21 Definition
d("foo", FormatEntity::Entry::Type::Invalid
);
23 EXPECT_STREQ(d
.name
, "foo");
24 EXPECT_EQ(d
.string
, nullptr);
25 EXPECT_EQ(d
.type
, FormatEntity::Entry::Type::Invalid
);
26 EXPECT_EQ(d
.data
, 0UL);
27 EXPECT_EQ(d
.num_children
, 0UL);
28 EXPECT_EQ(d
.children
, nullptr);
29 EXPECT_FALSE(d
.keep_separator
);
32 TEST(FormatEntityTest
, DefinitionConstructionNameAndString
) {
33 Definition
d("foo", "string");
35 EXPECT_STREQ(d
.name
, "foo");
36 EXPECT_STREQ(d
.string
, "string");
37 EXPECT_EQ(d
.type
, FormatEntity::Entry::Type::EscapeCode
);
38 EXPECT_EQ(d
.data
, 0UL);
39 EXPECT_EQ(d
.num_children
, 0UL);
40 EXPECT_EQ(d
.children
, nullptr);
41 EXPECT_FALSE(d
.keep_separator
);
44 TEST(FormatEntityTest
, DefinitionConstructionNameTypeData
) {
45 Definition
d("foo", FormatEntity::Entry::Type::Invalid
, 33);
47 EXPECT_STREQ(d
.name
, "foo");
48 EXPECT_EQ(d
.string
, nullptr);
49 EXPECT_EQ(d
.type
, FormatEntity::Entry::Type::Invalid
);
50 EXPECT_EQ(d
.data
, 33UL);
51 EXPECT_EQ(d
.num_children
, 0UL);
52 EXPECT_EQ(d
.children
, nullptr);
53 EXPECT_FALSE(d
.keep_separator
);
56 TEST(FormatEntityTest
, DefinitionConstructionNameTypeChildren
) {
57 Definition
d("foo", FormatEntity::Entry::Type::Invalid
, 33);
58 Definition
parent("parent", FormatEntity::Entry::Type::Invalid
, 1, &d
);
59 EXPECT_STREQ(parent
.name
, "parent");
60 EXPECT_STREQ(parent
.string
, nullptr);
61 EXPECT_EQ(parent
.type
, FormatEntity::Entry::Type::Invalid
);
62 EXPECT_EQ(parent
.num_children
, 1UL);
63 EXPECT_EQ(parent
.children
, &d
);
64 EXPECT_FALSE(parent
.keep_separator
);
66 EXPECT_STREQ(parent
.children
[0].name
, "foo");
67 EXPECT_EQ(parent
.children
[0].string
, nullptr);
68 EXPECT_EQ(parent
.children
[0].type
, FormatEntity::Entry::Type::Invalid
);
69 EXPECT_EQ(parent
.children
[0].data
, 33UL);
70 EXPECT_EQ(parent
.children
[0].num_children
, 0UL);
71 EXPECT_EQ(parent
.children
[0].children
, nullptr);
72 EXPECT_FALSE(d
.keep_separator
);
75 constexpr llvm::StringRef lookupStrings
[] = {
104 "${frame.is-artificial}",
107 "${function.name-without-args}",
108 "${function.name-with-args}",
109 "${function.mangled-name}",
110 "${function.addr-offset}",
111 "${function.concrete-only-addr-offset-no-padding}",
112 "${function.line-offset}",
113 "${function.pc-offset}",
114 "${function.initial-function}",
115 "${function.changed}",
116 "${function.is-optimized}",
117 "${line.file.basename}",
118 "${line.file.dirname}",
119 "${line.file.fullpath}",
122 "${line.start-addr}",
124 "${module.file.basename}",
125 "${module.file.dirname}",
126 "${module.file.fullpath}",
129 "${process.file.basename}",
130 "${process.file.dirname}",
131 "${process.file.fullpath}",
139 "${svar.dummy-svar-to-test-wildcard}",
141 "${thread.protocol_id}",
146 "${thread.stop-reason}",
147 "${thread.stop-reason-raw}",
148 "${thread.return-value}",
149 "${thread.completed-expression}",
151 "${var.dummy-var-to-test-wildcard}"};
153 TEST(FormatEntity
, LookupAllEntriesInTree
) {
154 for (const llvm::StringRef testString
: lookupStrings
) {
156 EXPECT_TRUE(FormatEntity::Parse(testString
, e
).Success())
157 << "Formatting " << testString
<< " did not succeed";