13#include "llvm/ADT/StringRef.h"
14#include "llvm/Support/SMLoc.h"
15#include "llvm/Support/SourceMgr.h"
16#include "llvm/Testing/Support/SupportHelpers.h"
17#include "gmock/gmock.h"
18#include "gtest/gtest.h"
27 *
OS << ::testing::PrintToString(*V);
31using ::testing::AllOf;
32using ::testing::ElementsAre;
33using ::testing::IsEmpty;
38 *result_listener <<
"value is " << *arg;
43 if (*arg.first == Value1 && *arg.second == Value2)
45 *result_listener <<
"values are [" << *arg.first <<
", " << *arg.second
50TEST(ParseYAML, SyntacticForms) {
52 const char *
YAML = R
"yaml(
56CompileFlags: { Add: [foo, bar] }
70 example-check.ExampleOption: 0
71 UnusedIncludes: Strict
74 EXPECT_THAT(Diags.Diagnostics, IsEmpty());
75 EXPECT_THAT(Diags.Files, ElementsAre(
"config.yaml"));
77 EXPECT_FALSE(
Results[0].If.HasUnrecognizedCondition);
78 EXPECT_THAT(
Results[0].If.PathMatch, ElementsAre(val(
"abc")));
79 EXPECT_THAT(
Results[0].CompileFlags.Add, ElementsAre(val(
"foo"), val(
"bar")));
81 EXPECT_THAT(
Results[1].CompileFlags.Add, ElementsAre(val(
"b\naz\n")));
83 ASSERT_TRUE(
Results[2].Index.Background);
84 EXPECT_EQ(
"Skip", **
Results[2].Index.Background);
86 ElementsAre(PairVal(
"IgnoreMacros",
"true"),
87 PairVal(
"example-check.ExampleOption",
"0")));
92TEST(ParseYAML, Locations) {
94 Annotations
YAML(R
"yaml(
96 PathMatch: [['???bad***regex(((']]
100 EXPECT_THAT(Diags.Diagnostics, IsEmpty());
102 ASSERT_NE(
Results.front().Source.Manager,
nullptr);
104 *
Results.front().Source.Manager),
108TEST(ParseYAML, ConfigDiagnostics) {
110 Annotations
YAML(R
"yaml(
112 $unknown[[UnknownCondition]]: "foo"
116CompileFlags: {$unexpected^
123 ElementsAre(AllOf(diagMessage(
"Unknown If key 'UnknownCondition'"),
124 diagKind(llvm::SourceMgr::DK_Warning),
125 diagPos(
YAML.range(
"unknown").start),
126 diagRange(
YAML.range(
"unknown"))),
127 AllOf(diagMessage(
"Unexpected token. Expected Key, Flow "
128 "Entry, or Flow Mapping End."),
129 diagKind(llvm::SourceMgr::DK_Error),
130 diagPos(
YAML.point(
"unexpected")),
131 diagRange(std::nullopt))));
134 EXPECT_THAT(
Results.front().CompileFlags.Add, ElementsAre(val(
"first")));
135 EXPECT_TRUE(
Results.front().If.HasUnrecognizedCondition);
138TEST(ParseYAML, Invalid) {
140 const char *
YAML = R
"yaml(
148 EXPECT_THAT(Diags.Diagnostics,
149 ElementsAre(diagMessage(
"If should be a dictionary"),
150 diagMessage(
"Config should be a dictionary")));
151 ASSERT_THAT(
Results, IsEmpty());
154TEST(ParseYAML, ExternalBlockNone) {
156 Annotations
YAML(R
"yaml(
162 ASSERT_THAT(Diags.Diagnostics, IsEmpty());
164 ASSERT_TRUE(
Results[0].Index.External);
165 EXPECT_FALSE((*
Results[0].Index.External)->File.has_value());
166 EXPECT_FALSE((*
Results[0].Index.External)->MountPoint.has_value());
167 EXPECT_FALSE((*
Results[0].Index.External)->Server.has_value());
168 EXPECT_THAT(*(*
Results[0].Index.External)->IsNone, testing::Eq(
true));
171TEST(ParseYAML, ExternalBlock) {
173 Annotations
YAML(R
"yaml(
183 ASSERT_TRUE(
Results[0].Index.External);
184 EXPECT_THAT(*(*
Results[0].Index.External)->File, val(
"foo"));
185 EXPECT_THAT(*(*
Results[0].Index.External)->MountPoint, val(
"baz"));
186 ASSERT_THAT(Diags.Diagnostics, IsEmpty());
187 EXPECT_THAT(*(*
Results[0].Index.External)->Server, val(
"bar"));
190TEST(ParseYAML, AllScopes) {
192 Annotations
YAML(R
"yaml(
198 ASSERT_THAT(Diags.Diagnostics, IsEmpty());
200 EXPECT_THAT(
Results[0].Completion.AllScopes, llvm::ValueIs(val(
true)));
203TEST(ParseYAML, AllScopesWarn) {
205 Annotations
YAML(R
"yaml(
207 AllScopes: $diagrange[[Truex]]
211 EXPECT_THAT(Diags.Diagnostics,
212 ElementsAre(AllOf(diagMessage(
"AllScopes should be a boolean"),
213 diagKind(llvm::SourceMgr::DK_Warning),
214 diagPos(
YAML.range(
"diagrange").start),
215 diagRange(
YAML.range(
"diagrange")))));
217 EXPECT_THAT(
Results[0].Completion.AllScopes, testing::Eq(std::nullopt));
220TEST(ParseYAML, ShowAKA) {
222 Annotations
YAML(R
"yaml(
228 ASSERT_THAT(Diags.Diagnostics, IsEmpty());
230 EXPECT_THAT(
Results[0].Hover.ShowAKA, llvm::ValueIs(val(
true)));
233TEST(ParseYAML, InlayHints) {
235 Annotations
YAML(R
"yaml(
242 ASSERT_THAT(Diags.Diagnostics, IsEmpty());
244 EXPECT_THAT(
Results[0].InlayHints.Enabled, llvm::ValueIs(val(
false)));
245 EXPECT_THAT(
Results[0].InlayHints.ParameterNames, llvm::ValueIs(val(
true)));
246 EXPECT_EQ(
Results[0].InlayHints.DeducedTypes, std::nullopt);
249TEST(ParseYAML, SemanticTokens) {
251 Annotations
YAML(R
"yaml(
253 DisabledKinds: [ Operator, InactiveCode]
254 DisabledModifiers: Readonly
258 ASSERT_THAT(Diags.Diagnostics, IsEmpty());
260 EXPECT_THAT(
Results[0].SemanticTokens.DisabledKinds,
261 ElementsAre(val(
"Operator"), val(
"InactiveCode")));
262 EXPECT_THAT(
Results[0].SemanticTokens.DisabledModifiers,
263 ElementsAre(val(
"Readonly")));
266TEST(ParseYAML, IncludesIgnoreHeader) {
268 Annotations
YAML(R
"yaml(
271 IgnoreHeader: [foo, bar]
275 ASSERT_THAT(Diags.Diagnostics, IsEmpty());
278 ElementsAre(val(
"foo"), val(
"bar")));
281TEST(ParseYAML, IncludesAnalyzeAngledIncludes) {
283 Annotations
YAML(R
"yaml(
286 AnalyzeAngledIncludes: true
290 ASSERT_THAT(Diags.Diagnostics, IsEmpty());
293 llvm::ValueIs(val(
true)));
296TEST(ParseYAML, Style) {
298 Annotations
YAML(R
"yaml(
300 FullyQualifiedNamespaces: [foo, bar])yaml");
303 ASSERT_THAT(Diags.Diagnostics, IsEmpty());
305 EXPECT_THAT(
Results[0].Style.FullyQualifiedNamespaces,
306 ElementsAre(val(
"foo"), val(
"bar")));
std::vector< CodeCompletionResult > Results
WantDiagnostics Diagnostics
llvm::raw_string_ostream OS
MATCHER_P(diagMessage, M, "")
Range toRange(llvm::SMRange R, const llvm::SourceMgr &SM)
void PrintTo(const Located< T > &V, std::ostream *OS)
MATCHER_P2(hasFlag, Flag, Path, "")
TEST(BackgroundQueueTest, Priority)
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
static std::vector< Fragment > parseYAML(llvm::StringRef YAML, llvm::StringRef BufferName, DiagnosticCallback)
Parses fragments from a YAML file (one from each — delimited document).
An entity written in config along, with its optional location in the file.