diff options
author | Yitzhak Mandelbaum <yitzhakm@google.com> | 2019-07-02 13:11:04 +0000 |
---|---|---|
committer | Yitzhak Mandelbaum <yitzhakm@google.com> | 2019-07-02 13:11:04 +0000 |
commit | 727bdcb23764b309bd5f42cba52263dcd5bc2a62 (patch) | |
tree | ecd866f65532ca2eb183da9db8b24c6b0e69cc43 /clang/unittests/Tooling/TransformerTest.cpp | |
parent | 234f5f675e7d48b8b23ca2a38f9f60d4ab9ef340 (diff) | |
download | llvm-727bdcb23764b309bd5f42cba52263dcd5bc2a62.zip llvm-727bdcb23764b309bd5f42cba52263dcd5bc2a62.tar.gz llvm-727bdcb23764b309bd5f42cba52263dcd5bc2a62.tar.bz2 |
[LibTooling] Extend `RewriteRule` with support for adding includes.
Summary:
This revision allows users to specify the insertion of an included directive (at
the top of the file being rewritten) as part of a rewrite rule. These
directives are bundled with `RewriteRule` cases, so that different cases can
potentially result in different include actions.
Reviewers: ilya-biryukov, gribozavr
Subscribers: cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D63892
llvm-svn: 364917
Diffstat (limited to 'clang/unittests/Tooling/TransformerTest.cpp')
-rw-r--r-- | clang/unittests/Tooling/TransformerTest.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/clang/unittests/Tooling/TransformerTest.cpp b/clang/unittests/Tooling/TransformerTest.cpp index e9de00d..64f511b 100644 --- a/clang/unittests/Tooling/TransformerTest.cpp +++ b/clang/unittests/Tooling/TransformerTest.cpp @@ -198,6 +198,42 @@ TEST_F(TransformerTest, Flag) { testRule(std::move(Rule), Input, Expected); } +TEST_F(TransformerTest, AddIncludeQuoted) { + RewriteRule Rule = makeRule(callExpr(callee(functionDecl(hasName("f")))), + change(text("other()"))); + addInclude(Rule, "clang/OtherLib.h"); + + std::string Input = R"cc( + int f(int x); + int h(int x) { return f(x); } + )cc"; + std::string Expected = R"cc(#include "clang/OtherLib.h" + + int f(int x); + int h(int x) { return other(); } + )cc"; + + testRule(Rule, Input, Expected); +} + +TEST_F(TransformerTest, AddIncludeAngled) { + RewriteRule Rule = makeRule(callExpr(callee(functionDecl(hasName("f")))), + change(text("other()"))); + addInclude(Rule, "clang/OtherLib.h", IncludeFormat::Angled); + + std::string Input = R"cc( + int f(int x); + int h(int x) { return f(x); } + )cc"; + std::string Expected = R"cc(#include <clang/OtherLib.h> + + int f(int x); + int h(int x) { return other(); } + )cc"; + + testRule(Rule, Input, Expected); +} + TEST_F(TransformerTest, NodePartNameNamedDecl) { StringRef Fun = "fun"; RewriteRule Rule = makeRule(functionDecl(hasName("bad")).bind(Fun), |