2017-02-27 21:28:36 +08:00
|
|
|
//===- NamespaceEndCommentsFixerTest.cpp - Formatting unit tests ----------===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2017-02-27 21:28:36 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/Format/Format.h"
|
|
|
|
|
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
|
|
#define DEBUG_TYPE "namespace-end-comments-fixer-test"
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace format {
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class NamespaceEndCommentsFixerTest : public ::testing::Test {
|
|
|
|
protected:
|
|
|
|
std::string
|
|
|
|
fixNamespaceEndComments(llvm::StringRef Code,
|
2017-04-21 22:30:01 +08:00
|
|
|
const std::vector<tooling::Range> &Ranges,
|
2017-02-27 21:28:36 +08:00
|
|
|
const FormatStyle &Style = getLLVMStyle()) {
|
2018-05-15 21:30:56 +08:00
|
|
|
LLVM_DEBUG(llvm::errs() << "---\n");
|
|
|
|
LLVM_DEBUG(llvm::errs() << Code << "\n\n");
|
2017-02-27 21:28:36 +08:00
|
|
|
tooling::Replacements Replaces =
|
|
|
|
clang::format::fixNamespaceEndComments(Style, Code, Ranges, "<stdin>");
|
|
|
|
auto Result = applyAllReplacements(Code, Replaces);
|
|
|
|
EXPECT_TRUE(static_cast<bool>(Result));
|
2018-05-15 21:30:56 +08:00
|
|
|
LLVM_DEBUG(llvm::errs() << "\n" << *Result << "\n\n");
|
2017-02-27 21:28:36 +08:00
|
|
|
return *Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string
|
|
|
|
fixNamespaceEndComments(llvm::StringRef Code,
|
|
|
|
const FormatStyle &Style = getLLVMStyle()) {
|
|
|
|
return fixNamespaceEndComments(
|
|
|
|
Code,
|
|
|
|
/*Ranges=*/{1, tooling::Range(0, Code.size())}, Style);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(NamespaceEndCommentsFixerTest, AddsEndComment) {
|
|
|
|
EXPECT_EQ("namespace {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"}// namespace",
|
|
|
|
fixNamespaceEndComments("namespace {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"}"));
|
2019-06-07 04:06:23 +08:00
|
|
|
|
2017-02-27 21:28:36 +08:00
|
|
|
EXPECT_EQ("namespace {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"}// namespace\n",
|
|
|
|
fixNamespaceEndComments("namespace {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"}\n"));
|
|
|
|
EXPECT_EQ("namespace A {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"}// namespace A",
|
|
|
|
fixNamespaceEndComments("namespace A {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"}"));
|
2022-03-04 03:59:57 +08:00
|
|
|
EXPECT_EQ("#define M(x) x##x\n"
|
|
|
|
"namespace M(x) {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}// namespace M(x)",
|
|
|
|
fixNamespaceEndComments("#define M(x) x##x\n"
|
|
|
|
"namespace M(x) {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}"));
|
|
|
|
EXPECT_EQ("#define M(x) x##x\n"
|
|
|
|
"namespace A::M(x) {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}// namespace A::M(x)",
|
|
|
|
fixNamespaceEndComments("#define M(x) x##x\n"
|
|
|
|
"namespace A::M(x) {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}"));
|
|
|
|
EXPECT_EQ("#define M(x) x##x\n"
|
|
|
|
"namespace M(x)::A {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}// namespace M(x)::A",
|
|
|
|
fixNamespaceEndComments("#define M(x) x##x\n"
|
|
|
|
"namespace M(x)::A {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}"));
|
|
|
|
EXPECT_EQ("#define M(x) x##x\n"
|
|
|
|
"namespace A::inline M(x)::B {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}// namespace A::inline M(x)::B",
|
|
|
|
fixNamespaceEndComments("#define M(x) x##x\n"
|
|
|
|
"namespace A::inline M(x)::B {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}"));
|
|
|
|
EXPECT_EQ("#define M(x) x##x\n"
|
|
|
|
"namespace [[deprecated(\"foo\")]] A::inline M(x)::A {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}// namespace A::inline M(x)::A",
|
|
|
|
fixNamespaceEndComments(
|
|
|
|
"#define M(x) x##x\n"
|
|
|
|
"namespace [[deprecated(\"foo\")]] A::inline M(x)::A {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}"));
|
|
|
|
EXPECT_EQ(
|
|
|
|
"namespace /* comment */ [[deprecated(\"foo\")]] /* comment */ A {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}// namespace A",
|
|
|
|
fixNamespaceEndComments(
|
|
|
|
"namespace /* comment */ [[deprecated(\"foo\")]] /* comment */ A {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}"));
|
|
|
|
EXPECT_EQ("namespace /* comment */ [[deprecated(\"foo\")]] A {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}// namespace A",
|
|
|
|
fixNamespaceEndComments(
|
|
|
|
"namespace /* comment */ [[deprecated(\"foo\")]] A {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}"));
|
|
|
|
EXPECT_EQ(
|
|
|
|
"#define M(x) x##x\n"
|
|
|
|
"namespace /* comment */ [[deprecated(\"foo\")]] /* comment */ M(x) {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}// namespace M(x)",
|
|
|
|
fixNamespaceEndComments("#define M(x) x##x\n"
|
|
|
|
"namespace /* comment */ "
|
|
|
|
"[[deprecated(\"foo\")]] /* comment */ M(x) {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}"));
|
|
|
|
EXPECT_EQ("#define M(x) x##x\n"
|
|
|
|
"namespace /* comment */ [[deprecated(\"foo\")]] /* comment */ "
|
|
|
|
"A::M(x) {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}// namespace A::M(x)",
|
|
|
|
fixNamespaceEndComments(
|
|
|
|
"#define M(x) x##x\n"
|
|
|
|
"namespace /* comment */ "
|
|
|
|
"[[deprecated(\"foo\")]] /* comment */ A::M(x) {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}"));
|
|
|
|
EXPECT_EQ("#define M(x) x##x\n"
|
|
|
|
"namespace /* comment */ [[deprecated(\"foo\")]] /* comment */ "
|
|
|
|
"M(x) /* comment */ {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}// namespace M(x)",
|
|
|
|
fixNamespaceEndComments(
|
|
|
|
"#define M(x) x##x\n"
|
|
|
|
"namespace /* comment */ [[deprecated(\"foo\")]] /* comment "
|
|
|
|
"*/ M(x) /* comment */ {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}"));
|
|
|
|
EXPECT_EQ("#define M(x) x##x\n"
|
|
|
|
"namespace /* comment */ [[deprecated(\"foo\")]] /* comment */ "
|
|
|
|
"A::M(x) /* comment */ {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}// namespace A::M(x)",
|
|
|
|
fixNamespaceEndComments(
|
|
|
|
"#define M(x) x##x\n"
|
|
|
|
"namespace /* comment */ [[deprecated(\"foo\")]] /* comment "
|
|
|
|
"*/ A::M(x) /* comment */ {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}"));
|
2022-03-09 10:59:46 +08:00
|
|
|
EXPECT_EQ("#define M(x) x##x\n"
|
|
|
|
"namespace A M(x) {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}// namespace A M(x)",
|
|
|
|
fixNamespaceEndComments("#define M(x) x##x\n"
|
|
|
|
"namespace A M(x) {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}"));
|
|
|
|
EXPECT_EQ(
|
|
|
|
"#define B __attribute__((availability(macos, introduced=10.15)))\n"
|
|
|
|
"namespace A B {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}// namespace A B",
|
|
|
|
fixNamespaceEndComments(
|
|
|
|
"#define B __attribute__((availability(macos, introduced=10.15)))\n"
|
|
|
|
"namespace A B {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}"));
|
|
|
|
EXPECT_EQ("#define M(x) x##x\n"
|
|
|
|
"namespace A::B M(x) {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}// namespace A::B",
|
|
|
|
fixNamespaceEndComments("#define M(x) x##x\n"
|
|
|
|
"namespace A::B M(x) {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}"));
|
|
|
|
EXPECT_EQ(
|
|
|
|
"namespace A __attribute__((availability(macos, introduced=10.15))) {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}// namespace A",
|
|
|
|
fixNamespaceEndComments(
|
|
|
|
"namespace A __attribute__((availability(macos, introduced=10.15))) "
|
|
|
|
"{\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}"));
|
2017-02-27 21:28:36 +08:00
|
|
|
EXPECT_EQ("inline namespace A {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"}// namespace A",
|
|
|
|
fixNamespaceEndComments("inline namespace A {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"}"));
|
2019-07-24 01:49:45 +08:00
|
|
|
|
|
|
|
EXPECT_EQ("namespace [[deprecated(\"foo\")]] A::B {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}// namespace A::B",
|
|
|
|
fixNamespaceEndComments("namespace [[deprecated(\"foo\")]] A::B {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}"));
|
|
|
|
|
|
|
|
EXPECT_EQ("namespace [[deprecated(\"foo\")]] A::inline B::inline C {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}// namespace A::inline B::inline C",
|
|
|
|
fixNamespaceEndComments(
|
|
|
|
"namespace [[deprecated(\"foo\")]] A::inline B::inline C {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}"));
|
|
|
|
|
|
|
|
EXPECT_EQ("namespace DEPRECATED A::B {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}// namespace A::B",
|
|
|
|
fixNamespaceEndComments("namespace DEPRECATED A::B {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}"));
|
|
|
|
|
|
|
|
EXPECT_EQ("inline namespace [[deprecated]] A {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}// namespace A",
|
|
|
|
fixNamespaceEndComments("inline namespace [[deprecated]] A {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}"));
|
|
|
|
|
2017-02-27 21:28:36 +08:00
|
|
|
EXPECT_EQ("namespace ::A {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"}// namespace ::A",
|
|
|
|
fixNamespaceEndComments("namespace ::A {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"}"));
|
|
|
|
EXPECT_EQ("namespace ::A::B {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"}// namespace ::A::B",
|
|
|
|
fixNamespaceEndComments("namespace ::A::B {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"}"));
|
|
|
|
EXPECT_EQ("namespace /**/::/**/A/**/::/**/B/**/ {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"}// namespace ::A::B",
|
|
|
|
fixNamespaceEndComments("namespace /**/::/**/A/**/::/**/B/**/ {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"}"));
|
|
|
|
EXPECT_EQ("namespace A {\n"
|
|
|
|
"namespace B {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
2017-03-02 17:54:44 +08:00
|
|
|
"}\n"
|
|
|
|
"}// namespace A",
|
|
|
|
fixNamespaceEndComments("namespace A {\n"
|
|
|
|
"namespace B {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
2017-03-02 17:54:44 +08:00
|
|
|
"}\n"
|
|
|
|
"}"));
|
|
|
|
EXPECT_EQ("namespace A {\n"
|
|
|
|
"namespace B {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"}// namespace B\n"
|
|
|
|
"}// namespace A",
|
|
|
|
fixNamespaceEndComments("namespace A {\n"
|
|
|
|
"namespace B {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"}\n"
|
|
|
|
"}"));
|
|
|
|
EXPECT_EQ("namespace A {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int a;\n"
|
|
|
|
"int b;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"}// namespace A\n"
|
|
|
|
"namespace B {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int b;\n"
|
|
|
|
"int a;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"}// namespace B",
|
|
|
|
fixNamespaceEndComments("namespace A {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int a;\n"
|
|
|
|
"int b;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"}\n"
|
|
|
|
"namespace B {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int b;\n"
|
|
|
|
"int a;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"}"));
|
|
|
|
EXPECT_EQ("namespace A {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int a1;\n"
|
|
|
|
"int a2;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"}// namespace A\n"
|
|
|
|
"namespace A {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int a2;\n"
|
|
|
|
"int a1;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"}// namespace A",
|
|
|
|
fixNamespaceEndComments("namespace A {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int a1;\n"
|
|
|
|
"int a2;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"}\n"
|
|
|
|
"namespace A {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int a2;\n"
|
|
|
|
"int a1;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"}"));
|
|
|
|
EXPECT_EQ("namespace A {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int a;\n"
|
|
|
|
"int b;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"}// namespace A\n"
|
|
|
|
"// comment about b\n"
|
|
|
|
"int b;",
|
|
|
|
fixNamespaceEndComments("namespace A {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int a;\n"
|
|
|
|
"int b;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"}\n"
|
|
|
|
"// comment about b\n"
|
|
|
|
"int b;"));
|
|
|
|
|
|
|
|
EXPECT_EQ("namespace A {\n"
|
|
|
|
"namespace B {\n"
|
|
|
|
"namespace C {\n"
|
|
|
|
"namespace D {\n"
|
2017-03-02 17:54:44 +08:00
|
|
|
"}\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"}// namespace C\n"
|
|
|
|
"}// namespace B\n"
|
|
|
|
"}// namespace A",
|
|
|
|
fixNamespaceEndComments("namespace A {\n"
|
|
|
|
"namespace B {\n"
|
|
|
|
"namespace C {\n"
|
|
|
|
"namespace D {\n"
|
|
|
|
"}\n"
|
|
|
|
"}\n"
|
|
|
|
"}\n"
|
|
|
|
"}"));
|
2017-03-07 22:07:43 +08:00
|
|
|
|
2017-06-14 20:29:47 +08:00
|
|
|
// 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));
|
2022-01-14 18:37:04 +08:00
|
|
|
EXPECT_EQ("namespace out { namespace {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}}// namespace out",
|
|
|
|
fixNamespaceEndComments("namespace out { namespace {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}}",
|
|
|
|
CompactNamespacesStyle));
|
2017-06-14 20:29:47 +08:00
|
|
|
|
2017-03-07 22:07:43 +08:00
|
|
|
// Adds an end comment after a semicolon.
|
|
|
|
EXPECT_EQ("namespace {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
2017-03-07 22:07:43 +08:00
|
|
|
"};// namespace",
|
|
|
|
fixNamespaceEndComments("namespace {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
2017-03-07 22:07:43 +08:00
|
|
|
"};"));
|
|
|
|
EXPECT_EQ("namespace A {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
2017-03-07 22:07:43 +08:00
|
|
|
"};// namespace A",
|
|
|
|
fixNamespaceEndComments("namespace A {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
2017-03-07 22:07:43 +08:00
|
|
|
"};"));
|
|
|
|
EXPECT_EQ("namespace A {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
2017-03-07 22:07:43 +08:00
|
|
|
"};// namespace A\n"
|
|
|
|
"// unrelated",
|
|
|
|
fixNamespaceEndComments("namespace A {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
2017-03-07 22:07:43 +08:00
|
|
|
"};\n"
|
|
|
|
"// unrelated"));
|
2017-02-27 21:28:36 +08:00
|
|
|
}
|
2022-03-07 22:42:35 +08:00
|
|
|
|
|
|
|
TEST_F(NamespaceEndCommentsFixerTest, WorksForObjCpp) {
|
|
|
|
FormatStyle ObjCppStyle = getLLVMStyle();
|
|
|
|
ObjCppStyle.Language = FormatStyle::LK_ObjC;
|
|
|
|
EXPECT_EQ("namespace {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}// namespace",
|
|
|
|
fixNamespaceEndComments("namespace {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
2022-03-17 16:01:37 +08:00
|
|
|
"}",
|
|
|
|
ObjCppStyle));
|
2022-03-07 22:42:35 +08:00
|
|
|
}
|
2017-02-27 21:28:36 +08:00
|
|
|
|
2019-06-07 04:06:23 +08:00
|
|
|
TEST_F(NamespaceEndCommentsFixerTest, AddsMacroEndComment) {
|
|
|
|
FormatStyle Style = getLLVMStyle();
|
|
|
|
Style.NamespaceMacros.push_back("TESTSUITE");
|
|
|
|
|
|
|
|
EXPECT_EQ("TESTSUITE() {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}// TESTSUITE()",
|
|
|
|
fixNamespaceEndComments("TESTSUITE() {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}",
|
|
|
|
Style));
|
|
|
|
|
|
|
|
EXPECT_EQ("TESTSUITE(A) {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}// TESTSUITE(A)",
|
|
|
|
fixNamespaceEndComments("TESTSUITE(A) {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}",
|
|
|
|
Style));
|
|
|
|
EXPECT_EQ("inline TESTSUITE(A) {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}// TESTSUITE(A)",
|
|
|
|
fixNamespaceEndComments("inline TESTSUITE(A) {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}",
|
|
|
|
Style));
|
|
|
|
EXPECT_EQ("TESTSUITE(::A) {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}// TESTSUITE(::A)",
|
|
|
|
fixNamespaceEndComments("TESTSUITE(::A) {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}",
|
|
|
|
Style));
|
|
|
|
EXPECT_EQ("TESTSUITE(::A::B) {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}// TESTSUITE(::A::B)",
|
|
|
|
fixNamespaceEndComments("TESTSUITE(::A::B) {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}",
|
|
|
|
Style));
|
|
|
|
EXPECT_EQ("TESTSUITE(/**/::/**/A/**/::/**/B/**/) {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}// TESTSUITE(::A::B)",
|
|
|
|
fixNamespaceEndComments("TESTSUITE(/**/::/**/A/**/::/**/B/**/) {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}",
|
|
|
|
Style));
|
|
|
|
EXPECT_EQ("TESTSUITE(A, B) {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}// TESTSUITE(A)",
|
|
|
|
fixNamespaceEndComments("TESTSUITE(A, B) {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}",
|
|
|
|
Style));
|
|
|
|
EXPECT_EQ("TESTSUITE(\"Test1\") {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}// TESTSUITE(\"Test1\")",
|
|
|
|
fixNamespaceEndComments("TESTSUITE(\"Test1\") {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}",
|
|
|
|
Style));
|
|
|
|
}
|
|
|
|
|
2017-02-27 21:28:36 +08:00
|
|
|
TEST_F(NamespaceEndCommentsFixerTest, AddsNewlineIfNeeded) {
|
|
|
|
EXPECT_EQ("namespace A {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"}// namespace A\n"
|
2017-03-02 17:54:44 +08:00
|
|
|
" int k;",
|
2017-02-27 21:28:36 +08:00
|
|
|
fixNamespaceEndComments("namespace A {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
2017-03-02 17:54:44 +08:00
|
|
|
"} int k;"));
|
2017-02-27 21:28:36 +08:00
|
|
|
EXPECT_EQ("namespace {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"}// namespace\n"
|
2017-03-02 17:54:44 +08:00
|
|
|
" int k;",
|
2017-02-27 21:28:36 +08:00
|
|
|
fixNamespaceEndComments("namespace {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
2017-03-02 17:54:44 +08:00
|
|
|
"} int k;"));
|
2017-02-27 21:28:36 +08:00
|
|
|
EXPECT_EQ("namespace A {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"}// namespace A\n"
|
|
|
|
" namespace B {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int j;\n"
|
|
|
|
"int k;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"}// namespace B",
|
|
|
|
fixNamespaceEndComments("namespace A {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"} namespace B {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int j;\n"
|
|
|
|
"int k;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"}"));
|
2017-03-07 22:07:43 +08:00
|
|
|
EXPECT_EQ("namespace {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
2017-03-07 22:07:43 +08:00
|
|
|
"};// namespace\n"
|
|
|
|
"int k;",
|
|
|
|
fixNamespaceEndComments("namespace {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
2017-03-07 22:07:43 +08:00
|
|
|
"};int k;"));
|
|
|
|
EXPECT_EQ("namespace {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
2017-03-07 22:07:43 +08:00
|
|
|
"};// namespace\n"
|
|
|
|
";",
|
|
|
|
fixNamespaceEndComments("namespace {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
2017-03-07 22:07:43 +08:00
|
|
|
"};;"));
|
2017-02-27 21:28:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(NamespaceEndCommentsFixerTest, DoesNotAddEndCommentForShortNamespace) {
|
|
|
|
EXPECT_EQ("namespace {}", fixNamespaceEndComments("namespace {}"));
|
|
|
|
EXPECT_EQ("namespace A {}", fixNamespaceEndComments("namespace A {}"));
|
2020-05-02 22:42:20 +08:00
|
|
|
EXPECT_EQ("namespace A { a }", fixNamespaceEndComments("namespace A { a }"));
|
2017-03-07 22:07:43 +08:00
|
|
|
EXPECT_EQ("namespace A { a };",
|
|
|
|
fixNamespaceEndComments("namespace A { a };"));
|
2017-02-27 21:28:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(NamespaceEndCommentsFixerTest, DoesNotAddCommentAfterUnaffectedRBrace) {
|
|
|
|
EXPECT_EQ("namespace A {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"}",
|
|
|
|
fixNamespaceEndComments("namespace A {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"}",
|
|
|
|
// The range (16, 3) spans the 'int' above.
|
|
|
|
/*Ranges=*/{1, tooling::Range(16, 3)}));
|
2017-03-07 22:07:43 +08:00
|
|
|
EXPECT_EQ("namespace A {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
2017-03-07 22:07:43 +08:00
|
|
|
"};",
|
|
|
|
fixNamespaceEndComments("namespace A {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
2017-03-07 22:07:43 +08:00
|
|
|
"};",
|
|
|
|
// The range (16, 3) spans the 'int' above.
|
|
|
|
/*Ranges=*/{1, tooling::Range(16, 3)}));
|
2017-02-27 21:28:36 +08:00
|
|
|
}
|
|
|
|
|
2019-07-24 01:49:45 +08:00
|
|
|
TEST_F(NamespaceEndCommentsFixerTest,
|
|
|
|
DoesNotAddCommentAfterRBraceInPPDirective) {
|
2017-02-27 21:28:36 +08:00
|
|
|
EXPECT_EQ("#define SAD \\\n"
|
|
|
|
"namespace A { \\\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i; \\\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"}",
|
|
|
|
fixNamespaceEndComments("#define SAD \\\n"
|
|
|
|
"namespace A { \\\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i; \\\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"}"));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(NamespaceEndCommentsFixerTest, KeepsValidEndComment) {
|
|
|
|
EXPECT_EQ("namespace {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"} // end anonymous namespace",
|
|
|
|
fixNamespaceEndComments("namespace {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"} // end anonymous namespace"));
|
|
|
|
EXPECT_EQ("namespace A {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"} /* end of namespace A */",
|
|
|
|
fixNamespaceEndComments("namespace A {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"} /* end of namespace A */"));
|
|
|
|
EXPECT_EQ("namespace A {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"} // namespace A",
|
|
|
|
fixNamespaceEndComments("namespace A {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"} // namespace A"));
|
|
|
|
EXPECT_EQ("namespace A::B {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"} // end namespace A::B",
|
|
|
|
fixNamespaceEndComments("namespace A::B {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"} // end namespace A::B"));
|
2017-03-07 22:07:43 +08:00
|
|
|
EXPECT_EQ("namespace A {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
2017-03-07 22:07:43 +08:00
|
|
|
"}; // end namespace A",
|
|
|
|
fixNamespaceEndComments("namespace A {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
2017-03-07 22:07:43 +08:00
|
|
|
"}; // end namespace A"));
|
|
|
|
EXPECT_EQ("namespace {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
2017-03-07 22:07:43 +08:00
|
|
|
"}; /* unnamed namespace */",
|
|
|
|
fixNamespaceEndComments("namespace {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
2017-03-07 22:07:43 +08:00
|
|
|
"}; /* unnamed namespace */"));
|
2017-02-27 21:28:36 +08:00
|
|
|
}
|
|
|
|
|
2019-06-07 04:06:23 +08:00
|
|
|
TEST_F(NamespaceEndCommentsFixerTest, KeepsValidMacroEndComment) {
|
|
|
|
FormatStyle Style = getLLVMStyle();
|
|
|
|
Style.NamespaceMacros.push_back("TESTSUITE");
|
|
|
|
|
|
|
|
EXPECT_EQ("TESTSUITE() {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"} // end anonymous TESTSUITE()",
|
|
|
|
fixNamespaceEndComments("TESTSUITE() {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"} // end anonymous TESTSUITE()",
|
|
|
|
Style));
|
|
|
|
EXPECT_EQ("TESTSUITE(A) {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"} /* end of TESTSUITE(A) */",
|
|
|
|
fixNamespaceEndComments("TESTSUITE(A) {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"} /* end of TESTSUITE(A) */",
|
|
|
|
Style));
|
|
|
|
EXPECT_EQ("TESTSUITE(A) {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"} // TESTSUITE(A)",
|
|
|
|
fixNamespaceEndComments("TESTSUITE(A) {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"} // TESTSUITE(A)",
|
|
|
|
Style));
|
|
|
|
EXPECT_EQ("TESTSUITE(A::B) {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"} // end TESTSUITE(A::B)",
|
|
|
|
fixNamespaceEndComments("TESTSUITE(A::B) {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"} // end TESTSUITE(A::B)",
|
|
|
|
Style));
|
|
|
|
EXPECT_EQ("TESTSUITE(A) {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"}; // end TESTSUITE(A)",
|
|
|
|
fixNamespaceEndComments("TESTSUITE(A) {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"}; // end TESTSUITE(A)",
|
|
|
|
Style));
|
|
|
|
EXPECT_EQ("TESTSUITE() {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"}; /* unnamed TESTSUITE() */",
|
|
|
|
fixNamespaceEndComments("TESTSUITE() {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"}; /* unnamed TESTSUITE() */",
|
|
|
|
Style));
|
|
|
|
}
|
|
|
|
|
2017-02-27 21:28:36 +08:00
|
|
|
TEST_F(NamespaceEndCommentsFixerTest, UpdatesInvalidEndLineComment) {
|
|
|
|
EXPECT_EQ("namespace {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"} // namespace",
|
|
|
|
fixNamespaceEndComments("namespace {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"} // namespace A"));
|
|
|
|
EXPECT_EQ("namespace A {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"} // namespace A",
|
|
|
|
fixNamespaceEndComments("namespace A {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"} // namespace"));
|
|
|
|
EXPECT_EQ("namespace A {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"} // namespace A",
|
|
|
|
fixNamespaceEndComments("namespace A {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"} //"));
|
|
|
|
EXPECT_EQ("namespace A {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
|
|
|
"}; // namespace A",
|
2017-02-27 21:28:36 +08:00
|
|
|
fixNamespaceEndComments("namespace A {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
|
|
|
"}; //"));
|
|
|
|
|
2017-02-27 21:28:36 +08:00
|
|
|
EXPECT_EQ("namespace A {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"} // namespace A",
|
|
|
|
fixNamespaceEndComments("namespace A {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"} // banamespace A"));
|
2017-03-07 22:07:43 +08:00
|
|
|
EXPECT_EQ("namespace A {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
2017-03-07 22:07:43 +08:00
|
|
|
"}; // namespace A",
|
|
|
|
fixNamespaceEndComments("namespace A {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
2017-03-07 22:07:43 +08:00
|
|
|
"}; // banamespace A"));
|
2017-02-27 21:28:36 +08:00
|
|
|
// Updates invalid line comments even for short namespaces.
|
|
|
|
EXPECT_EQ("namespace A {} // namespace A",
|
|
|
|
fixNamespaceEndComments("namespace A {} // namespace"));
|
2017-03-07 22:07:43 +08:00
|
|
|
EXPECT_EQ("namespace A {}; // namespace A",
|
|
|
|
fixNamespaceEndComments("namespace A {}; // namespace"));
|
2017-06-14 20:29:47 +08:00
|
|
|
|
|
|
|
// 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));
|
2022-01-14 18:37:04 +08:00
|
|
|
EXPECT_EQ("namespace out { namespace {\n"
|
|
|
|
"}} // namespace out",
|
|
|
|
fixNamespaceEndComments("namespace out { namespace {\n"
|
|
|
|
"}} // namespace out::",
|
|
|
|
CompactNamespacesStyle));
|
2017-02-27 21:28:36 +08:00
|
|
|
}
|
|
|
|
|
2019-06-07 04:06:23 +08:00
|
|
|
TEST_F(NamespaceEndCommentsFixerTest, UpdatesInvalidMacroEndLineComment) {
|
|
|
|
FormatStyle Style = getLLVMStyle();
|
|
|
|
Style.NamespaceMacros.push_back("TESTSUITE");
|
|
|
|
|
|
|
|
EXPECT_EQ("TESTSUITE() {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"} // TESTSUITE()",
|
|
|
|
fixNamespaceEndComments("TESTSUITE() {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"} // TESTSUITE(A)",
|
|
|
|
Style));
|
|
|
|
EXPECT_EQ("TESTSUITE(A) {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"} // TESTSUITE(A)",
|
|
|
|
fixNamespaceEndComments("TESTSUITE(A) {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"} // TESTSUITE()",
|
|
|
|
Style));
|
|
|
|
EXPECT_EQ("TESTSUITE(A) {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"} // TESTSUITE(A)",
|
|
|
|
fixNamespaceEndComments("TESTSUITE(A) {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"} //",
|
|
|
|
Style));
|
|
|
|
EXPECT_EQ("TESTSUITE(A) {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"}; // TESTSUITE(A)",
|
|
|
|
fixNamespaceEndComments("TESTSUITE(A) {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"}; //",
|
|
|
|
Style));
|
|
|
|
EXPECT_EQ("TESTSUITE(A) {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"} // TESTSUITE(A)",
|
|
|
|
fixNamespaceEndComments("TESTSUITE(A) {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"} // TESTSUITE A",
|
|
|
|
Style));
|
|
|
|
EXPECT_EQ("TESTSUITE() {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"} // TESTSUITE()",
|
|
|
|
fixNamespaceEndComments("TESTSUITE() {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"} // TESTSUITE",
|
|
|
|
Style));
|
|
|
|
EXPECT_EQ("TESTSUITE(A) {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"} // TESTSUITE(A)",
|
|
|
|
fixNamespaceEndComments("TESTSUITE(A) {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"} // TOASTSUITE(A)",
|
|
|
|
Style));
|
|
|
|
EXPECT_EQ("TESTSUITE(A) {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"}; // TESTSUITE(A)",
|
|
|
|
fixNamespaceEndComments("TESTSUITE(A) {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"}; // TOASTSUITE(A)",
|
|
|
|
Style));
|
|
|
|
// Updates invalid line comments even for short namespaces.
|
|
|
|
EXPECT_EQ("TESTSUITE(A) {} // TESTSUITE(A)",
|
|
|
|
fixNamespaceEndComments("TESTSUITE(A) {} // TESTSUITE()", Style));
|
|
|
|
EXPECT_EQ("TESTSUITE(A) {}; // TESTSUITE(A)",
|
|
|
|
fixNamespaceEndComments("TESTSUITE(A) {}; // TESTSUITE()", Style));
|
|
|
|
|
|
|
|
// Update invalid comments for compacted namespaces.
|
|
|
|
FormatStyle CompactNamespacesStyle = getLLVMStyle();
|
|
|
|
CompactNamespacesStyle.CompactNamespaces = true;
|
|
|
|
CompactNamespacesStyle.NamespaceMacros.push_back("TESTSUITE");
|
|
|
|
|
|
|
|
EXPECT_EQ("TESTSUITE(out) { TESTSUITE(in) {\n"
|
|
|
|
"}} // TESTSUITE(out::in)",
|
|
|
|
fixNamespaceEndComments("TESTSUITE(out) { TESTSUITE(in) {\n"
|
|
|
|
"}} // TESTSUITE(out)",
|
|
|
|
CompactNamespacesStyle));
|
|
|
|
EXPECT_EQ("TESTSUITE(out) { TESTSUITE(in) {\n"
|
|
|
|
"}} // TESTSUITE(out::in)",
|
|
|
|
fixNamespaceEndComments("TESTSUITE(out) { TESTSUITE(in) {\n"
|
|
|
|
"}} // TESTSUITE(in)",
|
|
|
|
CompactNamespacesStyle));
|
|
|
|
EXPECT_EQ("TESTSUITE(out) { TESTSUITE(in) {\n"
|
|
|
|
"}\n"
|
|
|
|
"} // TESTSUITE(out::in)",
|
|
|
|
fixNamespaceEndComments("TESTSUITE(out) { TESTSUITE(in) {\n"
|
|
|
|
"}// TAOSTSUITE(in)\n"
|
|
|
|
"} // TESTSUITE(out)",
|
|
|
|
CompactNamespacesStyle));
|
|
|
|
}
|
|
|
|
|
2017-02-27 21:28:36 +08:00
|
|
|
TEST_F(NamespaceEndCommentsFixerTest, UpdatesInvalidEndBlockComment) {
|
|
|
|
EXPECT_EQ("namespace {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"} // namespace",
|
|
|
|
fixNamespaceEndComments("namespace {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"} /* namespace A */"));
|
|
|
|
EXPECT_EQ("namespace A {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"} // namespace A",
|
|
|
|
fixNamespaceEndComments("namespace A {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"} /* end namespace */"));
|
|
|
|
EXPECT_EQ("namespace A {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"} // namespace A",
|
|
|
|
fixNamespaceEndComments("namespace A {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"} /**/"));
|
|
|
|
EXPECT_EQ("namespace A {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"} // namespace A",
|
|
|
|
fixNamespaceEndComments("namespace A {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"} /* end unnamed namespace */"));
|
|
|
|
EXPECT_EQ("namespace A {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"} // namespace A",
|
|
|
|
fixNamespaceEndComments("namespace A {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"} /* banamespace A */"));
|
2017-03-07 22:07:43 +08:00
|
|
|
EXPECT_EQ("namespace A {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
2017-03-07 22:07:43 +08:00
|
|
|
"}; // namespace A",
|
|
|
|
fixNamespaceEndComments("namespace A {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
2017-03-07 22:07:43 +08:00
|
|
|
"}; /* banamespace A */"));
|
2017-02-27 21:28:36 +08:00
|
|
|
EXPECT_EQ("namespace A {} // namespace A",
|
|
|
|
fixNamespaceEndComments("namespace A {} /**/"));
|
2017-03-07 22:07:43 +08:00
|
|
|
EXPECT_EQ("namespace A {}; // namespace A",
|
|
|
|
fixNamespaceEndComments("namespace A {}; /**/"));
|
2017-02-27 21:28:36 +08:00
|
|
|
}
|
|
|
|
|
2019-06-07 04:06:23 +08:00
|
|
|
TEST_F(NamespaceEndCommentsFixerTest, UpdatesInvalidMacroEndBlockComment) {
|
|
|
|
FormatStyle Style = getLLVMStyle();
|
|
|
|
Style.NamespaceMacros.push_back("TESTSUITE");
|
|
|
|
|
|
|
|
EXPECT_EQ("TESTSUITE() {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"} // TESTSUITE()",
|
|
|
|
fixNamespaceEndComments("TESTSUITE() {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"} /* TESTSUITE(A) */",
|
|
|
|
Style));
|
|
|
|
EXPECT_EQ("TESTSUITE(A) {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"} // TESTSUITE(A)",
|
|
|
|
fixNamespaceEndComments("TESTSUITE(A) {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"} /* end TESTSUITE() */",
|
|
|
|
Style));
|
|
|
|
EXPECT_EQ("TESTSUITE(A) {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"} // TESTSUITE(A)",
|
|
|
|
fixNamespaceEndComments("TESTSUITE(A) {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"} /**/",
|
|
|
|
Style));
|
|
|
|
EXPECT_EQ("TESTSUITE(A) {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"} // TESTSUITE(A)",
|
|
|
|
fixNamespaceEndComments("TESTSUITE(A) {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"} /* end unnamed TESTSUITE() */",
|
|
|
|
Style));
|
|
|
|
EXPECT_EQ("TESTSUITE(A) {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"} // TESTSUITE(A)",
|
|
|
|
fixNamespaceEndComments("TESTSUITE(A) {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"} /* TOASTSUITE(A) */",
|
|
|
|
Style));
|
|
|
|
EXPECT_EQ("TESTSUITE(A) {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"}; // TESTSUITE(A)",
|
|
|
|
fixNamespaceEndComments("TESTSUITE(A) {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"}; /* TAOSTSUITE(A) */",
|
|
|
|
Style));
|
|
|
|
EXPECT_EQ("TESTSUITE(A) {} // TESTSUITE(A)",
|
|
|
|
fixNamespaceEndComments("TESTSUITE(A) {} /**/", Style));
|
|
|
|
EXPECT_EQ("TESTSUITE(A) {}; // TESTSUITE(A)",
|
|
|
|
fixNamespaceEndComments("TESTSUITE(A) {}; /**/", Style));
|
|
|
|
}
|
|
|
|
|
2017-02-27 21:28:36 +08:00
|
|
|
TEST_F(NamespaceEndCommentsFixerTest,
|
|
|
|
DoesNotAddEndCommentForNamespacesControlledByMacros) {
|
|
|
|
EXPECT_EQ("#ifdef 1\n"
|
|
|
|
"namespace A {\n"
|
|
|
|
"#elseif\n"
|
|
|
|
"namespace B {\n"
|
|
|
|
"#endif\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"}\n"
|
|
|
|
"}\n",
|
|
|
|
fixNamespaceEndComments("#ifdef 1\n"
|
|
|
|
"namespace A {\n"
|
|
|
|
"#elseif\n"
|
|
|
|
"namespace B {\n"
|
|
|
|
"#endif\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"}\n"
|
|
|
|
"}\n"));
|
|
|
|
}
|
|
|
|
|
2021-03-02 04:15:04 +08:00
|
|
|
TEST_F(NamespaceEndCommentsFixerTest, AddsEndCommentForNamespacesAroundMacros) {
|
2017-07-28 15:56:14 +08:00
|
|
|
// Conditional blocks around are fine
|
|
|
|
EXPECT_EQ("namespace A {\n"
|
|
|
|
"#if 1\n"
|
|
|
|
"int i;\n"
|
|
|
|
"#endif\n"
|
|
|
|
"}// namespace A",
|
|
|
|
fixNamespaceEndComments("namespace A {\n"
|
|
|
|
"#if 1\n"
|
|
|
|
"int i;\n"
|
|
|
|
"#endif\n"
|
|
|
|
"}"));
|
|
|
|
EXPECT_EQ("#if 1\n"
|
|
|
|
"#endif\n"
|
|
|
|
"namespace A {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}// namespace A",
|
|
|
|
fixNamespaceEndComments("#if 1\n"
|
|
|
|
"#endif\n"
|
|
|
|
"namespace A {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}"));
|
|
|
|
EXPECT_EQ("namespace A {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}// namespace A\n"
|
|
|
|
"#if 1\n"
|
|
|
|
"#endif",
|
|
|
|
fixNamespaceEndComments("namespace A {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}\n"
|
|
|
|
"#if 1\n"
|
|
|
|
"#endif"));
|
|
|
|
EXPECT_EQ("#if 1\n"
|
|
|
|
"namespace A {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}// namespace A\n"
|
|
|
|
"#endif",
|
|
|
|
fixNamespaceEndComments("#if 1\n"
|
|
|
|
"namespace A {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}\n"
|
|
|
|
"#endif"));
|
|
|
|
|
|
|
|
// Macro definition has no impact
|
|
|
|
EXPECT_EQ("namespace A {\n"
|
|
|
|
"#define FOO\n"
|
|
|
|
"int i;\n"
|
|
|
|
"}// namespace A",
|
|
|
|
fixNamespaceEndComments("namespace A {\n"
|
|
|
|
"#define FOO\n"
|
|
|
|
"int i;\n"
|
|
|
|
"}"));
|
|
|
|
EXPECT_EQ("#define FOO\n"
|
|
|
|
"namespace A {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}// namespace A",
|
|
|
|
fixNamespaceEndComments("#define FOO\n"
|
|
|
|
"namespace A {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}"));
|
|
|
|
EXPECT_EQ("namespace A {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}// namespace A\n"
|
|
|
|
"#define FOO\n",
|
|
|
|
fixNamespaceEndComments("namespace A {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}\n"
|
|
|
|
"#define FOO\n"));
|
|
|
|
|
|
|
|
// No replacement if open & close in different conditional blocks
|
|
|
|
EXPECT_EQ("#if 1\n"
|
|
|
|
"namespace A {\n"
|
|
|
|
"#endif\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"#if 1\n"
|
|
|
|
"}\n"
|
|
|
|
"#endif",
|
|
|
|
fixNamespaceEndComments("#if 1\n"
|
|
|
|
"namespace A {\n"
|
|
|
|
"#endif\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"#if 1\n"
|
|
|
|
"}\n"
|
|
|
|
"#endif"));
|
|
|
|
EXPECT_EQ("#ifdef A\n"
|
|
|
|
"namespace A {\n"
|
|
|
|
"#endif\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"#ifdef B\n"
|
|
|
|
"}\n"
|
|
|
|
"#endif",
|
|
|
|
fixNamespaceEndComments("#ifdef A\n"
|
|
|
|
"namespace A {\n"
|
|
|
|
"#endif\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"#ifdef B\n"
|
|
|
|
"}\n"
|
|
|
|
"#endif"));
|
|
|
|
|
|
|
|
// No replacement inside unreachable conditional block
|
|
|
|
EXPECT_EQ("#if 0\n"
|
|
|
|
"namespace A {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}\n"
|
|
|
|
"#endif",
|
|
|
|
fixNamespaceEndComments("#if 0\n"
|
|
|
|
"namespace A {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}\n"
|
|
|
|
"#endif"));
|
|
|
|
}
|
|
|
|
|
2017-02-27 21:28:36 +08:00
|
|
|
TEST_F(NamespaceEndCommentsFixerTest,
|
|
|
|
DoesNotAddEndCommentForNamespacesInMacroDeclarations) {
|
|
|
|
EXPECT_EQ("#ifdef 1\n"
|
|
|
|
"namespace A {\n"
|
|
|
|
"#elseif\n"
|
|
|
|
"namespace B {\n"
|
|
|
|
"#endif\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"}\n"
|
|
|
|
"}\n",
|
|
|
|
fixNamespaceEndComments("#ifdef 1\n"
|
|
|
|
"namespace A {\n"
|
|
|
|
"#elseif\n"
|
|
|
|
"namespace B {\n"
|
|
|
|
"#endif\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
2017-02-27 21:28:36 +08:00
|
|
|
"}\n"
|
|
|
|
"}\n"));
|
2017-03-07 00:44:45 +08:00
|
|
|
EXPECT_EQ("namespace {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
2017-03-07 00:44:45 +08:00
|
|
|
"}// namespace\n"
|
|
|
|
"#if A\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
2017-03-07 00:44:45 +08:00
|
|
|
"#else\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int j;\n"
|
2017-03-07 00:44:45 +08:00
|
|
|
"#endif",
|
|
|
|
fixNamespaceEndComments("namespace {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
2017-03-07 00:44:45 +08:00
|
|
|
"}\n"
|
|
|
|
"#if A\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
2017-03-07 00:44:45 +08:00
|
|
|
"#else\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int j;\n"
|
2017-03-07 00:44:45 +08:00
|
|
|
"#endif"));
|
2017-03-07 01:29:25 +08:00
|
|
|
EXPECT_EQ("#if A\n"
|
|
|
|
"namespace A {\n"
|
|
|
|
"#else\n"
|
|
|
|
"namespace B {\n"
|
|
|
|
"#endif\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}",
|
|
|
|
fixNamespaceEndComments("#if A\n"
|
|
|
|
"namespace A {\n"
|
|
|
|
"#else\n"
|
|
|
|
"namespace B {\n"
|
|
|
|
"#endif\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}"));
|
|
|
|
EXPECT_EQ("#if A\n"
|
|
|
|
"namespace A {\n"
|
|
|
|
"#else\n"
|
|
|
|
"namespace B {\n"
|
|
|
|
"#endif\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"} // namespace A",
|
|
|
|
fixNamespaceEndComments("#if A\n"
|
|
|
|
"namespace A {\n"
|
|
|
|
"#else\n"
|
|
|
|
"namespace B {\n"
|
|
|
|
"#endif\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"} // namespace A"));
|
|
|
|
EXPECT_EQ("#if A\n"
|
|
|
|
"namespace A {\n"
|
|
|
|
"#else\n"
|
|
|
|
"namespace B {\n"
|
|
|
|
"#endif\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"} // namespace B",
|
|
|
|
fixNamespaceEndComments("#if A\n"
|
|
|
|
"namespace A {\n"
|
|
|
|
"#else\n"
|
|
|
|
"namespace B {\n"
|
|
|
|
"#endif\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"} // namespace B"));
|
|
|
|
EXPECT_EQ("namespace A\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"#if A\n"
|
|
|
|
"}\n"
|
|
|
|
"#else\n"
|
|
|
|
"}\n"
|
|
|
|
"#endif",
|
|
|
|
fixNamespaceEndComments("namespace A\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"#if A\n"
|
|
|
|
"}\n"
|
|
|
|
"#else\n"
|
|
|
|
"}\n"
|
|
|
|
"#endif"));
|
|
|
|
EXPECT_EQ("namespace A\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"#if A\n"
|
|
|
|
"} // namespace A\n"
|
|
|
|
"#else\n"
|
|
|
|
"} // namespace A\n"
|
|
|
|
"#endif",
|
|
|
|
fixNamespaceEndComments("namespace A\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"#if A\n"
|
|
|
|
"} // namespace A\n"
|
|
|
|
"#else\n"
|
|
|
|
"} // namespace A\n"
|
|
|
|
"#endif"));
|
2017-02-27 21:28:36 +08:00
|
|
|
}
|
2017-03-02 00:38:08 +08:00
|
|
|
|
|
|
|
TEST_F(NamespaceEndCommentsFixerTest,
|
|
|
|
DoesNotAddEndCommentForUnbalancedRBracesAfterNamespaceEnd) {
|
|
|
|
EXPECT_EQ("namespace {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
2017-03-02 00:38:08 +08:00
|
|
|
"} // namespace\n"
|
|
|
|
"}",
|
|
|
|
fixNamespaceEndComments("namespace {\n"
|
2019-05-30 00:22:43 +08:00
|
|
|
"int i;\n"
|
2017-03-02 00:38:08 +08:00
|
|
|
"} // namespace\n"
|
|
|
|
"}"));
|
|
|
|
}
|
2017-04-05 04:11:13 +08:00
|
|
|
|
|
|
|
TEST_F(NamespaceEndCommentsFixerTest, HandlesInlineAtEndOfLine_PR32438) {
|
|
|
|
EXPECT_EQ("template <int> struct a {};\n"
|
|
|
|
"struct a<bool{}> b() {\n"
|
|
|
|
"}\n"
|
|
|
|
"#define c inline\n"
|
|
|
|
"void d() {\n"
|
|
|
|
"}\n",
|
|
|
|
fixNamespaceEndComments("template <int> struct a {};\n"
|
|
|
|
"struct a<bool{}> b() {\n"
|
|
|
|
"}\n"
|
|
|
|
"#define c inline\n"
|
|
|
|
"void d() {\n"
|
|
|
|
"}\n"));
|
|
|
|
}
|
2020-05-30 20:00:35 +08:00
|
|
|
|
|
|
|
TEST_F(NamespaceEndCommentsFixerTest, IgnoreUnbalanced) {
|
|
|
|
EXPECT_EQ("namespace A {\n"
|
|
|
|
"class Foo {\n"
|
|
|
|
"}\n"
|
|
|
|
"}// namespace A\n",
|
|
|
|
fixNamespaceEndComments("namespace A {\n"
|
|
|
|
"class Foo {\n"
|
|
|
|
"}\n"
|
|
|
|
"}\n"));
|
|
|
|
EXPECT_EQ("namespace A {\n"
|
|
|
|
"class Foo {\n"
|
|
|
|
"}\n",
|
|
|
|
fixNamespaceEndComments("namespace A {\n"
|
|
|
|
"class Foo {\n"
|
|
|
|
"}\n"));
|
|
|
|
|
|
|
|
EXPECT_EQ("namespace A {\n"
|
|
|
|
"class Foo {\n"
|
|
|
|
"}\n"
|
|
|
|
"}\n"
|
|
|
|
"}\n",
|
|
|
|
fixNamespaceEndComments("namespace A {\n"
|
|
|
|
"class Foo {\n"
|
|
|
|
"}\n"
|
|
|
|
"}\n"
|
|
|
|
"}\n"));
|
|
|
|
}
|
2021-03-02 04:15:04 +08:00
|
|
|
|
|
|
|
using ShortNamespaceLinesTest = NamespaceEndCommentsFixerTest;
|
|
|
|
|
|
|
|
TEST_F(ShortNamespaceLinesTest, ZeroUnwrappedLines) {
|
|
|
|
auto Style = getLLVMStyle();
|
|
|
|
Style.ShortNamespaceLines = 0u;
|
|
|
|
|
|
|
|
EXPECT_EQ("namespace OneLinerNamespace {}\n",
|
|
|
|
fixNamespaceEndComments("namespace OneLinerNamespace {}\n", Style));
|
|
|
|
EXPECT_EQ("namespace ShortNamespace {\n"
|
|
|
|
"}\n",
|
|
|
|
fixNamespaceEndComments("namespace ShortNamespace {\n"
|
|
|
|
"}\n",
|
|
|
|
Style));
|
|
|
|
EXPECT_EQ("namespace LongNamespace {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"}// namespace LongNamespace\n",
|
|
|
|
fixNamespaceEndComments("namespace LongNamespace {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"}\n",
|
|
|
|
Style));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ShortNamespaceLinesTest, OneUnwrappedLine) {
|
|
|
|
constexpr auto DefaultUnwrappedLines = 1u;
|
|
|
|
auto const Style = getLLVMStyle();
|
|
|
|
|
|
|
|
EXPECT_EQ(DefaultUnwrappedLines, Style.ShortNamespaceLines);
|
|
|
|
EXPECT_EQ("namespace ShortNamespace {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"}\n",
|
|
|
|
fixNamespaceEndComments("namespace ShortNamespace {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"}\n"));
|
|
|
|
EXPECT_EQ("namespace LongNamespace {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}// namespace LongNamespace\n",
|
|
|
|
fixNamespaceEndComments("namespace LongNamespace {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}\n"));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ShortNamespaceLinesTest, MultipleUnwrappedLine) {
|
|
|
|
auto Style = getLLVMStyle();
|
|
|
|
Style.ShortNamespaceLines = 2u;
|
|
|
|
|
|
|
|
EXPECT_EQ("namespace ShortNamespace {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}\n",
|
|
|
|
fixNamespaceEndComments("namespace ShortNamespace {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"}\n",
|
|
|
|
Style));
|
|
|
|
EXPECT_EQ("namespace LongNamespace {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"int k;\n"
|
|
|
|
"}// namespace LongNamespace\n",
|
|
|
|
fixNamespaceEndComments("namespace LongNamespace {\n"
|
|
|
|
"int i;\n"
|
|
|
|
"int j;\n"
|
|
|
|
"int k;\n"
|
|
|
|
"}\n",
|
|
|
|
Style));
|
|
|
|
}
|
2021-12-14 22:45:26 +08:00
|
|
|
|
|
|
|
TEST_F(ShortNamespaceLinesTest, NamespaceAlias) {
|
|
|
|
auto Style = getLLVMStyle();
|
|
|
|
|
|
|
|
EXPECT_EQ("namespace n = nn;\n"
|
|
|
|
"{\n"
|
|
|
|
" int i;\n"
|
|
|
|
" int j;\n"
|
|
|
|
"}\n",
|
|
|
|
fixNamespaceEndComments("namespace n = nn;\n"
|
|
|
|
"{\n"
|
|
|
|
" int i;\n"
|
|
|
|
" int j;\n"
|
|
|
|
"}\n",
|
|
|
|
Style));
|
|
|
|
|
|
|
|
EXPECT_EQ("namespace n = nn; // comment\n"
|
|
|
|
"{\n"
|
|
|
|
" int i;\n"
|
|
|
|
" int j;\n"
|
|
|
|
"}\n",
|
|
|
|
fixNamespaceEndComments("namespace n = nn; // comment\n"
|
|
|
|
"{\n"
|
|
|
|
" int i;\n"
|
|
|
|
" int j;\n"
|
|
|
|
"}\n",
|
|
|
|
Style));
|
|
|
|
|
|
|
|
EXPECT_EQ("namespace n = nn; /* comment */\n"
|
|
|
|
"{\n"
|
|
|
|
" int i;\n"
|
|
|
|
" int j;\n"
|
|
|
|
"}\n",
|
|
|
|
fixNamespaceEndComments("namespace n = nn; /* comment */\n"
|
|
|
|
"{\n"
|
|
|
|
" int i;\n"
|
|
|
|
" int j;\n"
|
|
|
|
"}\n",
|
|
|
|
Style));
|
|
|
|
|
|
|
|
EXPECT_EQ(
|
|
|
|
"namespace n = nn; /* comment */ /* comment2 */\n"
|
|
|
|
"{\n"
|
|
|
|
" int i;\n"
|
|
|
|
" int j;\n"
|
|
|
|
"}\n",
|
|
|
|
fixNamespaceEndComments("namespace n = nn; /* comment */ /* comment2 */\n"
|
|
|
|
"{\n"
|
|
|
|
" int i;\n"
|
|
|
|
" int j;\n"
|
|
|
|
"}\n",
|
|
|
|
Style));
|
|
|
|
|
|
|
|
EXPECT_EQ("namespace n = nn; {\n"
|
|
|
|
" int i;\n"
|
|
|
|
" int j;\n"
|
|
|
|
"}\n",
|
|
|
|
fixNamespaceEndComments("namespace n = nn; {\n"
|
|
|
|
" int i;\n"
|
|
|
|
" int j;\n"
|
|
|
|
"}\n",
|
|
|
|
Style));
|
|
|
|
EXPECT_EQ("int foo;\n"
|
|
|
|
"namespace n\n"
|
|
|
|
"{\n"
|
|
|
|
" int i;\n"
|
|
|
|
" int j;\n"
|
|
|
|
"}// namespace n\n",
|
|
|
|
fixNamespaceEndComments("int foo;\n"
|
|
|
|
"namespace n\n"
|
|
|
|
"{\n"
|
|
|
|
" int i;\n"
|
|
|
|
" int j;\n"
|
|
|
|
"}\n",
|
|
|
|
Style));
|
|
|
|
}
|
2017-02-27 21:28:36 +08:00
|
|
|
} // end namespace
|
|
|
|
} // end namespace format
|
|
|
|
} // end namespace clang
|