From b001a0ba5e10937c3e1a6489bbd47889182cef69 Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Fri, 3 Jul 2015 17:25:16 +0000 Subject: clang-format: Add MacroBlock{Begin,End} options The MacroBlockBegin and MacroBlockEnd options make matching macro identifiers behave like '{' and '}', respectively, in terms of indentation. Mozilla code, for example, uses several macros that begin and end a scope. Previously, Clang-Format removed the indentation resulting in: MACRO_BEGIN(...) MACRO_ENTRY(...) MACRO_ENTRY(...) MACRO_END Now, using the options MacroBlockBegin: "^[A-Z_]+_BEGIN$" MacroBlockEnd: "^[A-Z_]+_END$" will yield the expected result: MACRO_BEGIN(...) MACRO_ENTRY(...) MACRO_ENTRY(...) MACRO_END Differential Revision: http://reviews.llvm.org/D10840 llvm-svn: 241363 --- clang/unittests/Format/FormatTest.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'clang/unittests/Format/FormatTest.cpp') diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 0d85789a1dd..dfc88fa8f79 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -3216,6 +3216,24 @@ TEST_F(FormatTest, PutEmptyBlocksIntoOneLine) { verifyFormat("enum E {}"); } +TEST_F(FormatTest, FormatBeginBlockEndMacros) { + FormatStyle Style = getLLVMStyle(); + Style.MacroBlockBegin = "^[A-Z_]+_BEGIN$"; + Style.MacroBlockEnd = "^[A-Z_]+_END$"; + verifyFormat("FOO_BEGIN\n" + " FOO_ENTRY\n" + "FOO_END", Style); + verifyFormat("FOO_BEGIN\n" + " NESTED_FOO_BEGIN\n" + " NESTED_FOO_ENTRY\n" + " NESTED_FOO_END\n" + "FOO_END", Style); + verifyFormat("FOO_BEGIN(Foo, Bar)\n" + " int x;\n" + " x = 1;\n" + "FOO_END(Baz)", Style); +} + //===----------------------------------------------------------------------===// // Line break tests. //===----------------------------------------------------------------------===// -- cgit v1.2.3