13 #include "llvm/Support/SMLoc.h"
14 #include "llvm/Support/ScopedPrinter.h"
15 #include "llvm/Support/SourceMgr.h"
16 #include "gmock/gmock.h"
17 #include "gtest/gtest.h"
23 *
OS << ::testing::PrintToString(*V);
27 using ::testing::AllOf;
28 using ::testing::ElementsAre;
29 using ::testing::IsEmpty;
34 *result_listener <<
"value is " << *arg;
38 TEST(ParseYAML, SyntacticForms) {
40 const char *YAML = R
"yaml(
44 CompileFlags: { Add: [foo, bar] }
54 EXPECT_FALSE(
Results.front().If.HasUnrecognizedCondition);
55 EXPECT_THAT(
Results.front().If.PathMatch, ElementsAre(Val(
"abc")));
56 EXPECT_THAT(
Results.front().CompileFlags.Add,
57 ElementsAre(Val(
"foo"), Val(
"bar")));
59 EXPECT_THAT(
Results.back().CompileFlags.Add, ElementsAre(Val(
"b\naz\n")));
62 TEST(ParseYAML, Locations) {
64 Annotations YAML(R
"yaml(
66 PathMatch: [['???bad***regex(((']]
72 ASSERT_NE(
Results.front().Source.Manager,
nullptr);
74 *
Results.front().Source.Manager),
78 TEST(ParseYAML, Diagnostics) {
80 Annotations
YAML(R
"yaml(
82 [[UnknownCondition]]: "foo"
93 ElementsAre(AllOf(DiagMessage(
"Unknown If key UnknownCondition"),
94 DiagKind(llvm::SourceMgr::DK_Warning),
95 DiagPos(
YAML.range().start), DiagRange(
YAML.range())),
96 AllOf(DiagMessage(
"Unexpected token. Expected Key, Flow "
97 "Entry, or Flow Mapping End."),
98 DiagKind(llvm::SourceMgr::DK_Error),
102 EXPECT_THAT(
Results.front().CompileFlags.Add, ElementsAre(Val(
"first")));
103 EXPECT_TRUE(
Results.front().If.HasUnrecognizedCondition);
106 TEST(ParseYAML, Invalid) {
108 const char *
YAML = R
"yaml(
117 ElementsAre(DiagMessage(
"If should be a dictionary"),
118 DiagMessage(
"Config should be a dictionary")));
119 ASSERT_THAT(
Results, IsEmpty());