aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests
diff options
context:
space:
mode:
Diffstat (limited to 'clang/unittests')
-rw-r--r--clang/unittests/Format/ConfigParseTest.cpp1
-rw-r--r--clang/unittests/Format/FormatTest.cpp132
2 files changed, 133 insertions, 0 deletions
diff --git a/clang/unittests/Format/ConfigParseTest.cpp b/clang/unittests/Format/ConfigParseTest.cpp
index 172aaab..2a8d793 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -184,6 +184,7 @@ TEST(ConfigParseTest, ParsesConfigurationBools) {
CHECK_PARSE_BOOL(ReflowComments);
CHECK_PARSE_BOOL(RemoveBracesLLVM);
CHECK_PARSE_BOOL(RemoveSemicolon);
+ CHECK_PARSE_BOOL(SkipMacroDefinitionBody);
CHECK_PARSE_BOOL(SpacesInSquareBrackets);
CHECK_PARSE_BOOL(SpaceInEmptyBlock);
CHECK_PARSE_BOOL(SpacesInContainerLiterals);
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index c229d9b..44896c1 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -24387,6 +24387,138 @@ TEST_F(FormatTest, WhitespaceSensitiveMacros) {
verifyNoChange("FOO(String-ized&Messy+But: :Still=Intentional);", Style);
}
+TEST_F(FormatTest, SkipMacroDefinitionBody) {
+ auto Style = getLLVMStyle();
+ Style.SkipMacroDefinitionBody = true;
+
+ verifyFormat("#define A", "#define A", Style);
+ verifyFormat("#define A a aa", "#define A a aa", Style);
+ verifyNoChange("#define A b", Style);
+ verifyNoChange("#define A ( args )", Style);
+ verifyNoChange("#define A ( args ) = func ( args )", Style);
+ verifyNoChange("#define A ( args ) { int a = 1 ; }", Style);
+ verifyNoChange("#define A ( args ) \\\n"
+ " {\\\n"
+ " int a = 1 ;\\\n"
+ "}",
+ Style);
+
+ verifyNoChange("#define A x:", Style);
+ verifyNoChange("#define A a. b", Style);
+
+ // Surrounded with formatted code.
+ verifyFormat("int a;\n"
+ "#define A a\n"
+ "int a;",
+ "int a ;\n"
+ "#define A a\n"
+ "int a ;",
+ Style);
+
+ // Columns are not broken when a limit is set.
+ Style.ColumnLimit = 10;
+ verifyFormat("#define A a a a a", " # define A a a a a ", Style);
+ verifyNoChange("#define A a a a a", Style);
+
+ Style.ColumnLimit = 15;
+ verifyFormat("#define A // a\n"
+ " // very\n"
+ " // long\n"
+ " // comment",
+ "#define A //a very long comment", Style);
+ Style.ColumnLimit = 0;
+
+ // Multiline definition.
+ verifyNoChange("#define A \\\n"
+ "Line one with spaces . \\\n"
+ " Line two.",
+ Style);
+ verifyNoChange("#define A \\\n"
+ "a a \\\n"
+ "a \\\n"
+ "a",
+ Style);
+ Style.AlignEscapedNewlines = FormatStyle::ENAS_Left;
+ verifyNoChange("#define A \\\n"
+ "a a \\\n"
+ "a \\\n"
+ "a",
+ Style);
+ Style.AlignEscapedNewlines = FormatStyle::ENAS_Right;
+ verifyNoChange("#define A \\\n"
+ "a a \\\n"
+ "a \\\n"
+ "a",
+ Style);
+
+ // Adjust indendations but don't change the definition.
+ Style.IndentPPDirectives = FormatStyle::PPDIS_None;
+ verifyNoChange("#if A\n"
+ "#define A a\n"
+ "#endif",
+ Style);
+ verifyFormat("#if A\n"
+ "#define A a\n"
+ "#endif",
+ "#if A\n"
+ " #define A a\n"
+ "#endif",
+ Style);
+ Style.IndentPPDirectives = FormatStyle::PPDIS_AfterHash;
+ verifyNoChange("#if A\n"
+ "# define A a\n"
+ "#endif",
+ Style);
+ verifyFormat("#if A\n"
+ "# define A a\n"
+ "#endif",
+ "#if A\n"
+ " #define A a\n"
+ "#endif",
+ Style);
+ Style.IndentPPDirectives = FormatStyle::PPDIS_BeforeHash;
+ verifyNoChange("#if A\n"
+ " #define A a\n"
+ "#endif",
+ Style);
+ verifyFormat("#if A\n"
+ " #define A a\n"
+ "#endif",
+ "#if A\n"
+ " # define A a\n"
+ "#endif",
+ Style);
+
+ Style.IndentPPDirectives = FormatStyle::PPDIS_None;
+ // SkipMacroDefinitionBody should not affect other PP directives
+ verifyFormat("#if !defined(A)\n"
+ "#define A a\n"
+ "#endif",
+ "#if ! defined ( A )\n"
+ " #define A a\n"
+ "#endif",
+ Style);
+
+ // With comments.
+ verifyFormat("/* */ #define A a // a a", "/* */ # define A a // a a",
+ Style);
+ verifyNoChange("/* */ #define A a // a a", Style);
+
+ verifyFormat("int a; // a\n"
+ "#define A // a\n"
+ "int aaa; // a",
+ "int a; // a\n"
+ "#define A // a\n"
+ "int aaa; // a",
+ Style);
+
+ // multiline macro definitions
+ verifyNoChange("#define A a\\\n"
+ " A a \\\n "
+ " A a",
+ Style);
+}
+
TEST_F(FormatTest, VeryLongNamespaceCommentSplit) {
// These tests are not in NamespaceEndCommentsFixerTest because that doesn't
// test its interaction with line wrapping