#include "clang/Tooling/Transformer/Transformer.h"
#include "clang/ASTMatchers/ASTMatchers.h"
#include "clang/Tooling/Tooling.h"
#include "clang/Tooling/Transformer/RangeSelector.h"
#include "clang/Tooling/Transformer/RewriteRule.h"
#include "clang/Tooling/Transformer/Stencil.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/Errc.h"
#include "llvm/Support/Error.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <optional>
usingnamespaceclang;
usingnamespacetooling;
usingnamespaceast_matchers;
namespace {
addInclude;
applyFirst;
before;
cat;
changeTo;
editList;
makeRule;
member;
name;
node;
noEdits;
remove;
rewriteDescendants;
RewriteRule;
RewriteRuleWith;
statement;
ElementsAre;
IsEmpty;
ResultOf;
UnorderedElementsAre;
constexpr char KHeaderContents[] = …;
static ast_matchers::internal::Matcher<clang::QualType>
isOrPointsTo(const clang::ast_matchers::DeclarationMatcher &TypeMatcher) { … }
static std::string format(StringRef Code) { … }
static void compareSnippets(StringRef Expected,
const std::optional<std::string> &MaybeActual) { … }
class ClangRefactoringTestBase : public testing::Test { … };
class TransformerTest : public ClangRefactoringTestBase { … };
static RewriteRuleWith<std::string> ruleStrlenSize() { … }
TEST_F(TransformerTest, StrlenSize) { … }
TEST_F(TransformerTest, NoMatch) { … }
TEST_F(TransformerTest, Flag) { … }
TEST_F(TransformerTest, AddIncludeQuoted) { … }
TEST_F(TransformerTest, AddIncludeAngled) { … }
TEST_F(TransformerTest, AddIncludeQuotedForRule) { … }
TEST_F(TransformerTest, AddIncludeAngledForRule) { … }
TEST_F(TransformerTest, NodePartNameNamedDecl) { … }
TEST_F(TransformerTest, NodePartNameDeclRef) { … }
TEST_F(TransformerTest, NodePartNameDeclRefFailure) { … }
TEST_F(TransformerTest, NodePartMember) { … }
TEST_F(TransformerTest, NodePartMemberQualified) { … }
TEST_F(TransformerTest, NodePartMemberMultiToken) { … }
TEST_F(TransformerTest, NoEdits) { … }
TEST_F(TransformerTest, NoopEdit) { … }
TEST_F(TransformerTest, IfBound2Args) { … }
TEST_F(TransformerTest, IfBound3Args) { … }
TEST_F(TransformerTest, ShrinkTo) { … }
TEST_F(TransformerTest, RewriteDescendantsDeclChangeStmt) { … }
TEST_F(TransformerTest, RewriteDescendantsDeclChangeTypeLoc) { … }
TEST_F(TransformerTest, RewriteDescendantsStmt) { … }
TEST_F(TransformerTest, RewriteDescendantsStmtWithAdditionalChange) { … }
TEST_F(TransformerTest, RewriteDescendantsTypeLoc) { … }
TEST_F(TransformerTest, RewriteDescendantsReferToParentBinding) { … }
TEST_F(TransformerTest, RewriteDescendantsUnboundNode) { … }
TEST_F(TransformerTest, RewriteDescendantsInvalidNodeType) { … }
TEST_F(TransformerTest, RewriteDescendantsTypedStmt) { … }
TEST_F(TransformerTest, RewriteDescendantsTypedDecl) { … }
TEST_F(TransformerTest, RewriteDescendantsTypedTypeLoc) { … }
TEST_F(TransformerTest, RewriteDescendantsTypedDynTyped) { … }
TEST_F(TransformerTest, InsertBeforeEdit) { … }
TEST_F(TransformerTest, InsertAfterEdit) { … }
TEST_F(TransformerTest, RemoveEdit) { … }
TEST_F(TransformerTest, WithMetadata) { … }
TEST_F(TransformerTest, MultiChange) { … }
TEST_F(TransformerTest, EditList) { … }
TEST_F(TransformerTest, Flatten) { … }
TEST_F(TransformerTest, FlattenWithMixedArgs) { … }
TEST_F(TransformerTest, OrderedRuleUnrelated) { … }
TEST_F(TransformerTest, OrderedRuleRelated) { … }
TEST_F(TransformerTest, OrderedRuleRelatedSwapped) { … }
TEST_F(TransformerTest, OrderedRuleMultipleKinds) { … }
TEST_F(TransformerTest, OrderedRuleImplicitMatched) { … }
TEST_F(TransformerTest, TextGeneratorFailure) { … }
TEST_F(TransformerTest, OverlappingEditsInRule) { … }
TEST_F(TransformerTest, OverlappingEditsMultipleMatches) { … }
TEST_F(TransformerTest, ErrorOccurredMatchSkipped) { … }
TEST_F(TransformerTest, ImplicitNodes_ConstructorDecl) { … }
TEST_F(TransformerTest, ImplicitNodes_RangeFor) { … }
TEST_F(TransformerTest, ImplicitNodes_ForStmt) { … }
TEST_F(TransformerTest, ImplicitNodes_ForStmt2) { … }
TEST_F(TransformerTest, TemplateInstantiation) { … }
TEST_F(TransformerTest, SimpleMacro) { … }
TEST_F(TransformerTest, FunctionMacro) { … }
TEST_F(TransformerTest, MacroArg) { … }
TEST_F(TransformerTest, MacroArgInMacroDef) { … }
TEST_F(TransformerTest, IdentityMacro) { … }
TEST_F(TransformerTest, TwoChangesInOneMacroExpansion) { … }
TEST_F(TransformerTest, MatchSpansMacroTextButChangeDoesNot) { … }
TEST_F(TransformerTest, MatchSpansMacroTextButChangeDoesNotAnchoredInMacro) { … }
TEST_F(TransformerTest, NoPartialRewriteOMacroExpansion) { … }
TEST_F(TransformerTest, NoPartialRewriteOfMacroExpansionForMacroArgs) { … }
#if !defined(NDEBUG) && GTEST_HAS_DEATH_TEST
TEST(TransformerDeathTest, OrderedRuleTypes) {
RewriteRule QualTypeRule = makeRule(qualType(), changeTo(cat("Q")));
EXPECT_DEATH(transformer::detail::buildMatchers(QualTypeRule),
"Matcher must be.*node matcher");
RewriteRule TypeRule = makeRule(arrayType(), changeTo(cat("T")));
EXPECT_DEATH(transformer::detail::buildMatchers(TypeRule),
"Matcher must be.*node matcher");
}
#endif
TEST_F(TransformerTest, MultipleFiles) { … }
TEST_F(TransformerTest, AddIncludeMultipleFiles) { … }
TEST_F(TransformerTest, MultiFileEdit) { … }
TEST_F(TransformerTest, GeneratesMetadata) { … }
TEST_F(TransformerTest, GeneratesMetadataWithNoEdits) { … }
TEST_F(TransformerTest, PropagateMetadataErrors) { … }
}