owenpan updated this revision to Diff 160577. owenpan added a comment. Added a test case.
Repository: rC Clang https://reviews.llvm.org/D50699 Files: lib/Format/ContinuationIndenter.cpp unittests/Format/FormatTest.cpp Index: unittests/Format/FormatTest.cpp =================================================================== --- unittests/Format/FormatTest.cpp +++ unittests/Format/FormatTest.cpp @@ -3375,6 +3375,22 @@ " = bbbbbbbbbbbbbbbbb\n" " >> aaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaa);", Style); + + Style.ColumnLimit = 80; + Style.IndentWidth = 4; + Style.TabWidth = 4; + Style.UseTab = FormatStyle::UT_Always; + Style.AlignAfterOpenBracket = FormatStyle::BAS_DontAlign; + Style.AlignOperands = false; + EXPECT_EQ("{\n" + "\treturn someVeryVeryLongConditionThatBarelyFitsOnALine\n" + "\t\t&& (someOtherLongishConditionPart1\n" + "\t\t\t|| someOtherEvenLongerNestedConditionPart2);\n" + "}", + format("{\n" + "\treturn someVeryVeryLongConditionThatBarelyFitsOnALine && (someOtherLongishConditionPart1 || someOtherEvenLongerNestedConditionPart2);\n" + "}", + Style)); } TEST_F(FormatTest, EnforcedOperatorWraps) { Index: lib/Format/ContinuationIndenter.cpp =================================================================== --- lib/Format/ContinuationIndenter.cpp +++ lib/Format/ContinuationIndenter.cpp @@ -700,7 +700,8 @@ // Indent relative to the RHS of the expression unless this is a simple // assignment without binary expression on the RHS. Also indent relative to // unary operators and the colons of constructor initializers. - State.Stack.back().LastSpace = State.Column; + if (Style.BreakBeforeBinaryOperators == FormatStyle::BOS_None) + State.Stack.back().LastSpace = State.Column; } else if (Previous.is(TT_InheritanceColon)) { State.Stack.back().Indent = State.Column; State.Stack.back().LastSpace = State.Column;
Index: unittests/Format/FormatTest.cpp =================================================================== --- unittests/Format/FormatTest.cpp +++ unittests/Format/FormatTest.cpp @@ -3375,6 +3375,22 @@ " = bbbbbbbbbbbbbbbbb\n" " >> aaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaa);", Style); + + Style.ColumnLimit = 80; + Style.IndentWidth = 4; + Style.TabWidth = 4; + Style.UseTab = FormatStyle::UT_Always; + Style.AlignAfterOpenBracket = FormatStyle::BAS_DontAlign; + Style.AlignOperands = false; + EXPECT_EQ("{\n" + "\treturn someVeryVeryLongConditionThatBarelyFitsOnALine\n" + "\t\t&& (someOtherLongishConditionPart1\n" + "\t\t\t|| someOtherEvenLongerNestedConditionPart2);\n" + "}", + format("{\n" + "\treturn someVeryVeryLongConditionThatBarelyFitsOnALine && (someOtherLongishConditionPart1 || someOtherEvenLongerNestedConditionPart2);\n" + "}", + Style)); } TEST_F(FormatTest, EnforcedOperatorWraps) { Index: lib/Format/ContinuationIndenter.cpp =================================================================== --- lib/Format/ContinuationIndenter.cpp +++ lib/Format/ContinuationIndenter.cpp @@ -700,7 +700,8 @@ // Indent relative to the RHS of the expression unless this is a simple // assignment without binary expression on the RHS. Also indent relative to // unary operators and the colons of constructor initializers. - State.Stack.back().LastSpace = State.Column; + if (Style.BreakBeforeBinaryOperators == FormatStyle::BOS_None) + State.Stack.back().LastSpace = State.Column; } else if (Previous.is(TT_InheritanceColon)) { State.Stack.back().Indent = State.Column; State.Stack.back().LastSpace = State.Column;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits