Add helpers for matching common subtrees in parse tests.

This commit is contained in:
Richard Smith
2021-04-20 23:43:25 -07:00
parent 4a92c41673
commit c0e83206be
2 changed files with 178 additions and 222 deletions
+20
View File
@@ -316,6 +316,26 @@ auto MatchNode(Args... args) -> ExpectedNode {
return MatchNode(ParseNodeKind::kind(), args...); \
}
#include "parse_node_kind.def"
// Helper for matching a designator `lhs.rhs`.
auto MatchDesignator(ExpectedNode lhs, std::string rhs) -> ExpectedNode {
return MatchDesignatorExpression(lhs, MatchDesignatedName(rhs));
}
// Helper for matching a function parameter list.
template <typename... Args>
auto MatchParameters(Args... args) -> ExpectedNode {
return MatchParameterList("(", args..., MatchParameterListEnd());
}
// Helper for matching the statements in the body of a simple function
// definition with no parameters.
template <typename... Args>
auto MatchFunctionWithBody(Args... args) -> ExpectedNode {
return MatchFunctionDeclaration(MatchDeclaredName(), MatchParameters(),
MatchCodeBlock(args..., MatchCodeBlockEnd()));
}
} // namespace NodeMatchers
} // namespace Testing