diff options
author | Francois Ferrand <thetypz@gmail.com> | 2017-06-14 12:29:47 +0000 |
---|---|---|
committer | Francois Ferrand <thetypz@gmail.com> | 2017-06-14 12:29:47 +0000 |
commit | e56a829e0980baaeb5c72ce84835cba8467d19fa (patch) | |
tree | b3e94467f7646ffd0c7cef14f06e1bce97fe2019 /clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp | |
parent | 1680ea4c1f334cfc5e43cfea368c9bb9510810d1 (diff) | |
download | bcm5719-llvm-e56a829e0980baaeb5c72ce84835cba8467d19fa.tar.gz bcm5719-llvm-e56a829e0980baaeb5c72ce84835cba8467d19fa.zip |
clang-format: Add CompactNamespaces option
Summary:
Add CompactNamespaces option, to pack namespace declarations on the
same line (somewhat similar to C++17 nested namespace definition).
With this option, consecutive namespace declarations are kept on the
same line:
namespace foo { namespace bar {
...
}} // namespace foo::bar
Reviewers: krasimir, djasper, klimek
Reviewed By: djasper
Subscribers: kimgr, cfe-commits, klimek
Tags: #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D32480
llvm-svn: 305384
Diffstat (limited to 'clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp')
-rw-r--r-- | clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp b/clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp index 6c2d3698529..92f34216293 100644 --- a/clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp +++ b/clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp @@ -185,6 +185,41 @@ TEST_F(NamespaceEndCommentsFixerTest, AddsEndComment) { "}\n" "}")); + // Add comment for namespaces which will be 'compacted' + FormatStyle CompactNamespacesStyle = getLLVMStyle(); + CompactNamespacesStyle.CompactNamespaces = true; + EXPECT_EQ("namespace out { namespace in {\n" + "int i;\n" + "int j;\n" + "}}// namespace out::in", + fixNamespaceEndComments("namespace out { namespace in {\n" + "int i;\n" + "int j;\n" + "}}", + CompactNamespacesStyle)); + EXPECT_EQ("namespace out {\n" + "namespace in {\n" + "int i;\n" + "int j;\n" + "}\n" + "}// namespace out::in", + fixNamespaceEndComments("namespace out {\n" + "namespace in {\n" + "int i;\n" + "int j;\n" + "}\n" + "}", + CompactNamespacesStyle)); + EXPECT_EQ("namespace out { namespace in {\n" + "int i;\n" + "int j;\n" + "};}// namespace out::in", + fixNamespaceEndComments("namespace out { namespace in {\n" + "int i;\n" + "int j;\n" + "};}", + CompactNamespacesStyle)); + // Adds an end comment after a semicolon. EXPECT_EQ("namespace {\n" " int i;\n" @@ -388,6 +423,27 @@ TEST_F(NamespaceEndCommentsFixerTest, UpdatesInvalidEndLineComment) { fixNamespaceEndComments("namespace A {} // namespace")); EXPECT_EQ("namespace A {}; // namespace A", fixNamespaceEndComments("namespace A {}; // namespace")); + + // Update invalid comments for compacted namespaces. + FormatStyle CompactNamespacesStyle = getLLVMStyle(); + CompactNamespacesStyle.CompactNamespaces = true; + EXPECT_EQ("namespace out { namespace in {\n" + "}} // namespace out::in", + fixNamespaceEndComments("namespace out { namespace in {\n" + "}} // namespace out", + CompactNamespacesStyle)); + EXPECT_EQ("namespace out { namespace in {\n" + "}} // namespace out::in", + fixNamespaceEndComments("namespace out { namespace in {\n" + "}} // namespace in", + CompactNamespacesStyle)); + EXPECT_EQ("namespace out { namespace in {\n" + "}\n" + "} // namespace out::in", + fixNamespaceEndComments("namespace out { namespace in {\n" + "}// banamespace in\n" + "} // namespace out", + CompactNamespacesStyle)); } TEST_F(NamespaceEndCommentsFixerTest, UpdatesInvalidEndBlockComment) { |