summaryrefslogtreecommitdiff
path: root/unittests
diff options
context:
space:
mode:
authorDinesh Dwivedi <dinesh.d@samsung.com>2014-05-05 11:36:35 +0000
committerDinesh Dwivedi <dinesh.d@samsung.com>2014-05-05 11:36:35 +0000
commit4114947c775bbd2b0182a4aefc1c9fe2d4f9a1b0 (patch)
tree8963364ad6b11358aa18bd0c2e6a911803d37a07 /unittests
parentdb5c09f0d9f57df91c2e1fe8325dd9a757c848cb (diff)
downloadclang-4114947c775bbd2b0182a4aefc1c9fe2d4f9a1b0.tar.gz
clang-4114947c775bbd2b0182a4aefc1c9fe2d4f9a1b0.tar.bz2
clang-4114947c775bbd2b0182a4aefc1c9fe2d4f9a1b0.tar.xz
Fix bug in clang-format while merging short function
Before: #ifdef _DEBUG int foo( int i = 0 ) #else int foo( int i = 5 ) #endif { return i; } After: #ifdef _DEBUG int foo( int i = 0 ) #else int foo( int i = 5 ) #endif { return i; } git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@207958 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r--unittests/Format/FormatTest.cpp90
1 files changed, 90 insertions, 0 deletions
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index 009df106e4..1380dd85a4 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -7367,6 +7367,36 @@ TEST_F(FormatTest, StroustrupBraceBreaking) {
"}\n"
"}",
BreakBeforeBrace);
+
+ verifyFormat("#ifdef _DEBUG\n"
+ "int foo(int i = 0)\n"
+ "#else\n"
+ "int foo(int i = 5)\n"
+ "#endif\n"
+ "{\n"
+ " return i;\n"
+ "}",
+ BreakBeforeBrace);
+
+ verifyFormat("void foo() {}\n"
+ "void bar()\n"
+ "#ifdef _DEBUG\n"
+ "{\n"
+ " foo();\n"
+ "}\n"
+ "#else\n"
+ "{\n"
+ "}\n"
+ "#endif",
+ BreakBeforeBrace);
+
+ verifyFormat("void foobar() { int i = 5; }\n"
+ "#ifdef _DEBUG\n"
+ "void bar() {}\n"
+ "#else\n"
+ "void bar() { foobar(); }\n"
+ "#endif",
+ BreakBeforeBrace);
}
TEST_F(FormatTest, AllmanBraceBreaking) {
@@ -7457,6 +7487,36 @@ TEST_F(FormatTest, AllmanBraceBreaking) {
"@end\n",
BreakBeforeBrace);
+ verifyFormat("#ifdef _DEBUG\n"
+ "int foo(int i = 0)\n"
+ "#else\n"
+ "int foo(int i = 5)\n"
+ "#endif\n"
+ "{\n"
+ " return i;\n"
+ "}",
+ BreakBeforeBrace);
+
+ verifyFormat("void foo() {}\n"
+ "void bar()\n"
+ "#ifdef _DEBUG\n"
+ "{\n"
+ " foo();\n"
+ "}\n"
+ "#else\n"
+ "{\n"
+ "}\n"
+ "#endif",
+ BreakBeforeBrace);
+
+ verifyFormat("void foobar() { int i = 5; }\n"
+ "#ifdef _DEBUG\n"
+ "void bar() {}\n"
+ "#else\n"
+ "void bar() { foobar(); }\n"
+ "#endif",
+ BreakBeforeBrace);
+
BreakBeforeBrace.ColumnLimit = 19;
verifyFormat("void f() { int i; }", BreakBeforeBrace);
BreakBeforeBrace.ColumnLimit = 18;
@@ -7585,6 +7645,36 @@ TEST_F(FormatTest, GNUBraceBreaking) {
"}\n"
"@end\n",
GNUBraceStyle);
+
+ verifyFormat("#ifdef _DEBUG\n"
+ "int foo(int i = 0)\n"
+ "#else\n"
+ "int foo(int i = 5)\n"
+ "#endif\n"
+ "{\n"
+ " return i;\n"
+ "}",
+ GNUBraceStyle);
+
+ verifyFormat("void foo() {}\n"
+ "void bar()\n"
+ "#ifdef _DEBUG\n"
+ "{\n"
+ " foo();\n"
+ "}\n"
+ "#else\n"
+ "{\n"
+ "}\n"
+ "#endif",
+ GNUBraceStyle);
+
+ verifyFormat("void foobar() { int i = 5; }\n"
+ "#ifdef _DEBUG\n"
+ "void bar() {}\n"
+ "#else\n"
+ "void bar() { foobar(); }\n"
+ "#endif",
+ GNUBraceStyle);
}
TEST_F(FormatTest, CatchExceptionReferenceBinding) {
verifyFormat("void f() {\n"