diff options
author | Daniel Jasper <djasper@google.com> | 2013-01-14 16:24:39 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2013-01-14 16:24:39 +0000 |
commit | 1b750edda14879a16ce782b3ade3af599bfbb717 (patch) | |
tree | c73821f399a78165dda169fee089261a7ab3f3b9 /clang/unittests/Format/FormatTest.cpp | |
parent | 9d3209b5c771a6e90a698d7d7a494a36c6e1637f (diff) | |
download | bcm5719-llvm-1b750edda14879a16ce782b3ade3af599bfbb717.tar.gz bcm5719-llvm-1b750edda14879a16ce782b3ade3af599bfbb717.zip |
Make single-line if statements optional.
Now, "if (a) return;" is only allowed, if this option is set.
Also add a Chromium style which is currently identical to Google style
except for this option.
llvm-svn: 172431
Diffstat (limited to 'clang/unittests/Format/FormatTest.cpp')
-rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 8e55ddb5d0f..1ab4a53c404 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -78,6 +78,12 @@ protected: return Style; } + FormatStyle getGoogleStyleWithColumns(unsigned ColumnLimit) { + FormatStyle Style = getGoogleStyle(); + Style.ColumnLimit = ColumnLimit; + return Style; + } + void verifyFormat(llvm::StringRef Code, const FormatStyle &Style = getLLVMStyle()) { EXPECT_EQ(Code.str(), format(messUp(Code), Style)); @@ -130,16 +136,16 @@ TEST_F(FormatTest, FormatsNestedCall) { //===----------------------------------------------------------------------===// TEST_F(FormatTest, FormatIfWithoutCompountStatement) { - verifyFormat("if (true) f();\ng();"); - verifyFormat("if (a)\n if (b)\n if (c) g();\nh();"); + verifyFormat("if (true)\n f();\ng();"); + verifyFormat("if (a)\n if (b)\n if (c)\n g();\nh();"); verifyFormat("if (a)\n if (b) {\n f();\n }\ng();"); - verifyFormat("if (a)\n" - " // comment\n" - " f();"); - verifyFormat("if (a) return;", getLLVMStyleWithColumns(14)); - verifyFormat("if (a)\n return;", getLLVMStyleWithColumns(13)); + verifyGoogleFormat("if (a)\n" + " // comment\n" + " f();"); + verifyFormat("if (a) return;", getGoogleStyleWithColumns(14)); + verifyFormat("if (a)\n return;", getGoogleStyleWithColumns(13)); verifyFormat("if (aaaaaaaaa)\n" - " return;", getLLVMStyleWithColumns(14)); + " return;", getGoogleStyleWithColumns(14)); } TEST_F(FormatTest, ParseIfElse) { @@ -156,7 +162,8 @@ TEST_F(FormatTest, ParseIfElse) { verifyFormat("if (true)\n" " if (true)\n" " if (true) {\n" - " if (true) f();\n" + " if (true)\n" + " f();\n" " } else {\n" " g();\n" " }\n" @@ -1461,7 +1468,8 @@ TEST_F(FormatTest, FormatObjCImplementation) { verifyFormat("@implementation Foo\n" "+ (id)init {\n" - " if (true) return nil;\n" + " if (true)\n" + " return nil;\n" "}\n" "// Look, a comment!\n" "- (int)answerWith:(int)i {\n" |