Fixed wrapping bug when previous line contains comment

This commit is contained in:
Nick Lockwood
2016-08-23 18:10:49 +01:00
parent 8b316e979b
commit f5dee59827
2 changed files with 8 additions and 2 deletions
+1 -1
View File
@@ -824,7 +824,7 @@ public func indent(formatter: Formatter) {
}
// Indent each new line
if token.type == .Linebreak {
linewrapped = !tokenIsEndOfStatement(lastNonWhitespaceIndex)
linewrapped = !tokenIsEndOfStatement(lastNonWhitespaceOrLinebreakIndex)
if linewrapped && lineIndex == scopeStartLineIndexes.last {
indentStack.popLast()
indentStack.append(indentStack.last ?? "")
+7 -1
View File
@@ -682,6 +682,12 @@ class FormatterTests: XCTestCase {
XCTAssertEqual(format(input, rules: [indent]), output)
}
func testWrappedLinesWithComments() {
let input = "let foo = bar ||\n//baz||\nquux"
let output = "let foo = bar ||\n //baz||\n quux"
XCTAssertEqual(format(input, rules: [indent]), output)
}
// MARK: indent comments
func testCommentIndenting() {
@@ -741,7 +747,7 @@ class FormatterTests: XCTestCase {
let output = "func foo() { /* comment/ncomment */\n statement\n}"
XCTAssertEqual(format(input, rules: [knrBraces]), output)
}
func testExtraSpaceNotAddedBeforeBrace() {
let input = "foo({ bar })"
let output = "foo({ bar })"