NFC: Use a simple macro to test AST node introspection

This commit is contained in:
Stephen Kelly 2021-03-17 12:08:28 +00:00
parent 0a74a7161b
commit b90e7bf25d
1 changed files with 8 additions and 7 deletions

View File

@ -40,6 +40,8 @@ FormatExpected(const MapType &Accessors) {
return Result;
}
#define STRING_LOCATION_PAIR(INSTANCE, LOC) Pair(#LOC, INSTANCE->LOC)
TEST(Introspection, SourceLocations) {
auto AST = buildASTFromCode("void foo() {} void bar() { foo(); }", "foo.cpp",
std::make_shared<PCHContainerOperations>());
@ -67,14 +69,13 @@ TEST(Introspection, SourceLocations) {
EXPECT_THAT(
ExpectedLocations,
UnorderedElementsAre(Pair("getBeginLoc()", FooCall->getBeginLoc()),
Pair("getEndLoc()", FooCall->getEndLoc()),
Pair("getExprLoc()", FooCall->getExprLoc()),
Pair("getRParenLoc()", FooCall->getRParenLoc())));
UnorderedElementsAre(STRING_LOCATION_PAIR(FooCall, getBeginLoc()),
STRING_LOCATION_PAIR(FooCall, getEndLoc()),
STRING_LOCATION_PAIR(FooCall, getExprLoc()),
STRING_LOCATION_PAIR(FooCall, getRParenLoc())));
auto ExpectedRanges = FormatExpected<SourceRange>(Result.RangeAccessors);
EXPECT_THAT(ExpectedRanges,
UnorderedElementsAre(
Pair("getSourceRange()", FooCall->getSourceRange())));
EXPECT_THAT(ExpectedRanges, UnorderedElementsAre(STRING_LOCATION_PAIR(
FooCall, getSourceRange())));
}