diff options
Diffstat (limited to 'unittests/Format/FormatTestSelective.cpp')
-rw-r--r-- | unittests/Format/FormatTestSelective.cpp | 68 |
1 files changed, 60 insertions, 8 deletions
diff --git a/unittests/Format/FormatTestSelective.cpp b/unittests/Format/FormatTestSelective.cpp index 8d2cb5a..d53d1c0 100644 --- a/unittests/Format/FormatTestSelective.cpp +++ b/unittests/Format/FormatTestSelective.cpp @@ -45,8 +45,14 @@ TEST_F(FormatTestSelective, RemovesTrailingWhitespaceOfFormattedLine) { } TEST_F(FormatTestSelective, FormatsCorrectRegionForLeadingWhitespace) { - EXPECT_EQ("int b;\nint a;", format("int b;\n int a;", 7, 0)); - EXPECT_EQ("int b;\n int a;", format("int b;\n int a;", 6, 0)); + EXPECT_EQ("{int b;\n" + " int a;\n" + "}", + format("{int b;\n int a;}", 8, 0)); + EXPECT_EQ("{\n" + " int b;\n" + " int a;}", + format("{int b;\n int a;}", 7, 0)); Style.ColumnLimit = 12; EXPECT_EQ("#define A \\\n" @@ -84,11 +90,11 @@ TEST_F(FormatTestSelective, ReformatsMovedLines) { "template <typename T> T *getFETokenInfo() const {\n" " return static_cast<T *>(FETokenInfo);\n" "}\n" - " int a; // <- Should not be formatted", + "int a; // <- Should not be formatted", format( "template<typename T>\n" "T *getFETokenInfo() const { return static_cast<T*>(FETokenInfo); }\n" - " int a; // <- Should not be formatted", + "int a; // <- Should not be formatted", 9, 5)); } @@ -142,12 +148,12 @@ TEST_F(FormatTestSelective, FormatsCommentsLocally) { " // is\n" " // a\n" "\n" - " // This is unrelated", + "//This is unrelated", format("int a; // This\n" " // is\n" " // a\n" "\n" - " // This is unrelated", + "//This is unrelated", 0, 0)); EXPECT_EQ("int a;\n" "// This is\n" @@ -267,6 +273,27 @@ TEST_F(FormatTestSelective, IndividualStatementsOfNestedBlocks) { 0, 0)); } +TEST_F(FormatTestSelective, WrongIndent) { + EXPECT_EQ("namespace {\n" + "int i;\n" + "int j;\n" + "}", + format("namespace {\n" + " int i;\n" // Format here. + " int j;\n" + "}", + 15, 0)); + EXPECT_EQ("namespace {\n" + " int i;\n" + " int j;\n" + "}", + format("namespace {\n" + " int i;\n" + " int j;\n" // Format here. + "}", + 24, 0)); +} + TEST_F(FormatTestSelective, AlwaysFormatsEntireMacroDefinitions) { Style.AlignEscapedNewlinesLeft = true; EXPECT_EQ("int i;\n" @@ -310,13 +337,17 @@ TEST_F(FormatTestSelective, ReformatRegionAdjustsIndent) { EXPECT_EQ("{\n" "{\n" " a;\n" - "b;\n" + " b;\n" + " c;\n" + " d;\n" "}\n" "}", format("{\n" "{\n" " a;\n" - "b;\n" + " b;\n" + " c;\n" + " d;\n" "}\n" "}", 9, 2)); @@ -436,6 +467,27 @@ TEST_F(FormatTestSelective, UnderstandsTabs) { 21, 0)); } +TEST_F(FormatTestSelective, StopFormattingWhenLeavingScope) { + EXPECT_EQ( + "void f() {\n" + " if (a) {\n" + " g();\n" + " h();\n" + "}\n" + "\n" + "void g() {\n" + "}", + format("void f() {\n" + " if (a) {\n" // Assume this was added without the closing brace. + " g();\n" + " h();\n" + "}\n" + "\n" + "void g() {\n" // Make sure not to format this. + "}", + 15, 0)); +} + } // end namespace } // end namespace format } // end namespace clang |