diff options
author | Krasimir Georgiev <krasimir@google.com> | 2017-03-07 14:07:43 +0000 |
---|---|---|
committer | Krasimir Georgiev <krasimir@google.com> | 2017-03-07 14:07:43 +0000 |
commit | eb62118e6d8fe924abceea869ae4cc43534e1fb2 (patch) | |
tree | 43e057da98fb37c5a51b01577bbb32095acfa17c /clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp | |
parent | 30e6cbfcfca4836c2b3497d84ffc2043b548b2a6 (diff) | |
download | bcm5719-llvm-eb62118e6d8fe924abceea869ae4cc43534e1fb2.tar.gz bcm5719-llvm-eb62118e6d8fe924abceea869ae4cc43534e1fb2.zip |
[clang-format] Support namespaces ending in semicolon
Summary:
This patch adds support for namespaces ending in semicolon to the namespace comment fixer.
source:
```
namespace A {
int i;
int j;
};
```
clang-format before:
```
namespace A {
int i;
int j;
} // namespace A;
```
clang-format after:
```
namespace A {
int i;
int j;
}; // namespace A
```
Reviewers: djasper
Reviewed By: djasper
Subscribers: cfe-commits, klimek
Differential Revision: https://reviews.llvm.org/D30688
llvm-svn: 297140
Diffstat (limited to 'clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp')
-rw-r--r-- | clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp | 85 |
1 files changed, 84 insertions, 1 deletions
diff --git a/clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp b/clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp index f0e67b39a3b..48ecdb038e9 100644 --- a/clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp +++ b/clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp @@ -184,6 +184,34 @@ TEST_F(NamespaceEndCommentsFixerTest, AddsEndComment) { "}\n" "}\n" "}")); + + // Adds an end comment after a semicolon. + EXPECT_EQ("namespace {\n" + " int i;\n" + " int j;\n" + "};// namespace", + fixNamespaceEndComments("namespace {\n" + " int i;\n" + " int j;\n" + "};")); + EXPECT_EQ("namespace A {\n" + " int i;\n" + " int j;\n" + "};// namespace A", + fixNamespaceEndComments("namespace A {\n" + " int i;\n" + " int j;\n" + "};")); + EXPECT_EQ("namespace A {\n" + " int i;\n" + " int j;\n" + "};// namespace A\n" + "// unrelated", + fixNamespaceEndComments("namespace A {\n" + " int i;\n" + " int j;\n" + "};\n" + "// unrelated")); } TEST_F(NamespaceEndCommentsFixerTest, AddsNewlineIfNeeded) { @@ -220,6 +248,24 @@ TEST_F(NamespaceEndCommentsFixerTest, AddsNewlineIfNeeded) { " int j;\n" " int k;\n" "}")); + EXPECT_EQ("namespace {\n" + " int i;\n" + " int j;\n" + "};// namespace\n" + "int k;", + fixNamespaceEndComments("namespace {\n" + " int i;\n" + " int j;\n" + "};int k;")); + EXPECT_EQ("namespace {\n" + " int i;\n" + " int j;\n" + "};// namespace\n" + ";", + fixNamespaceEndComments("namespace {\n" + " int i;\n" + " int j;\n" + "};;")); } TEST_F(NamespaceEndCommentsFixerTest, DoesNotAddEndCommentForShortNamespace) { @@ -227,6 +273,8 @@ TEST_F(NamespaceEndCommentsFixerTest, DoesNotAddEndCommentForShortNamespace) { EXPECT_EQ("namespace A {}", fixNamespaceEndComments("namespace A {}")); EXPECT_EQ("namespace A { a }", fixNamespaceEndComments("namespace A { a }")); + EXPECT_EQ("namespace A { a };", + fixNamespaceEndComments("namespace A { a };")); } TEST_F(NamespaceEndCommentsFixerTest, DoesNotAddCommentAfterUnaffectedRBrace) { @@ -238,6 +286,14 @@ TEST_F(NamespaceEndCommentsFixerTest, DoesNotAddCommentAfterUnaffectedRBrace) { "}", // The range (16, 3) spans the 'int' above. /*Ranges=*/{1, tooling::Range(16, 3)})); + EXPECT_EQ("namespace A {\n" + " int i;\n" + "};", + fixNamespaceEndComments("namespace A {\n" + " int i;\n" + "};", + // The range (16, 3) spans the 'int' above. + /*Ranges=*/{1, tooling::Range(16, 3)})); } TEST_F(NamespaceEndCommentsFixerTest, DoesNotAddCommentAfterRBraceInPPDirective) { @@ -276,6 +332,18 @@ TEST_F(NamespaceEndCommentsFixerTest, KeepsValidEndComment) { fixNamespaceEndComments("namespace A::B {\n" " int i;\n" "} // end namespace A::B")); + EXPECT_EQ("namespace A {\n" + " int i;\n" + "}; // end namespace A", + fixNamespaceEndComments("namespace A {\n" + " int i;\n" + "}; // end namespace A")); + EXPECT_EQ("namespace {\n" + " int i;\n" + "}; /* unnamed namespace */", + fixNamespaceEndComments("namespace {\n" + " int i;\n" + "}; /* unnamed namespace */")); } TEST_F(NamespaceEndCommentsFixerTest, UpdatesInvalidEndLineComment) { @@ -309,10 +377,17 @@ TEST_F(NamespaceEndCommentsFixerTest, UpdatesInvalidEndLineComment) { fixNamespaceEndComments("namespace A {\n" " int i;\n" "} // banamespace A")); - + EXPECT_EQ("namespace A {\n" + " int i;\n" + "}; // namespace A", + fixNamespaceEndComments("namespace A {\n" + " int i;\n" + "}; // banamespace A")); // Updates invalid line comments even for short namespaces. EXPECT_EQ("namespace A {} // namespace A", fixNamespaceEndComments("namespace A {} // namespace")); + EXPECT_EQ("namespace A {}; // namespace A", + fixNamespaceEndComments("namespace A {}; // namespace")); } TEST_F(NamespaceEndCommentsFixerTest, UpdatesInvalidEndBlockComment) { @@ -346,8 +421,16 @@ TEST_F(NamespaceEndCommentsFixerTest, UpdatesInvalidEndBlockComment) { fixNamespaceEndComments("namespace A {\n" " int i;\n" "} /* banamespace A */")); + EXPECT_EQ("namespace A {\n" + " int i;\n" + "}; // namespace A", + fixNamespaceEndComments("namespace A {\n" + " int i;\n" + "}; /* banamespace A */")); EXPECT_EQ("namespace A {} // namespace A", fixNamespaceEndComments("namespace A {} /**/")); + EXPECT_EQ("namespace A {}; // namespace A", + fixNamespaceEndComments("namespace A {}; /**/")); } TEST_F(NamespaceEndCommentsFixerTest, |