From bb42bf1a8bfd18fa2beec7fcbcb73f738fb455ba Mon Sep 17 00:00:00 2001 From: Manuel Klimek Date: Thu, 10 Jan 2013 11:52:21 +0000 Subject: Fix layout of blocks inside statements. Previously, we would not indent: SOME_MACRO({ int i; }); correctly. This is fixed by adding the trailing }); to the unwrapped line starting with SOME_MACRO({, so the formatter can correctly match the braces and indent accordingly. Also fixes incorrect parsing of initializer lists, like: int a[] = { 1 }; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172058 91177308-0d34-0410-b5e6-96231b3b80d8 --- unittests/Format/FormatTest.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'unittests/Format/FormatTest.cpp') diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 51a0bd6488..860661b432 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -615,6 +615,30 @@ TEST_F(FormatTest, LayoutStatementsAroundPreprocessorDirectives) { " trailing);", getLLVMStyleWithColumns(69)); } +TEST_F(FormatTest, LayoutBlockInsideParens) { + EXPECT_EQ("functionCall({\n" + " int i;\n" + "});", format(" functionCall ( {int i;} );")); +} + +TEST_F(FormatTest, LayoutBlockInsideStatement) { + EXPECT_EQ("SOME_MACRO {\n" + " int i;\n" + "}\n" + "int i;", format(" SOME_MACRO {int i;} int i;")); +} + +TEST_F(FormatTest, LayoutNestedBlocks) { + verifyFormat("void AddOsStrings(unsigned bitmask) {\n" + " struct s {\n" + " int i;\n" + " };\n" + " s kBitsToOs[] = { { 10 } };\n" + " for (int i = 0; i < 10; ++i)\n" + " return;\n" + "}"); +} + //===----------------------------------------------------------------------===// // Line break tests. //===----------------------------------------------------------------------===// -- cgit v1.2.3-70-g09d2