-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
242 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
196 changes: 196 additions & 0 deletions
196
Tests/SwiftFormatTests/PrettyPrint/IndentBlankLinesTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,196 @@ | ||
import SwiftFormat | ||
|
||
final class IndentBlankLinesTests: PrettyPrintTestCase { | ||
func testIndentBlankLinesEnabled() { | ||
let input = | ||
""" | ||
class A { | ||
func foo() -> Int { | ||
return 1 | ||
} | ||
\u{0020}\u{0020} | ||
func bar() -> Int { | ||
return 2 | ||
} | ||
} | ||
""" | ||
|
||
let expected = | ||
""" | ||
class A { | ||
func foo() -> Int { | ||
return 1 | ||
} | ||
\u{0020}\u{0020} | ||
func bar() -> Int { | ||
return 2 | ||
} | ||
} | ||
""" | ||
var config = Configuration.forTesting | ||
config.indentBlankLines = true | ||
assertPrettyPrintEqual(input: input, expected: expected, linelength: 80, configuration: config) | ||
} | ||
|
||
func testIndentBlankLinesDisabled() { | ||
let input = | ||
""" | ||
class A { | ||
func foo() -> Int { | ||
return 1 | ||
} | ||
\u{0020}\u{0020} | ||
func bar() -> Int { | ||
return 2 | ||
} | ||
} | ||
""" | ||
|
||
let expected = | ||
""" | ||
class A { | ||
func foo() -> Int { | ||
return 1 | ||
} | ||
func bar() -> Int { | ||
return 2 | ||
} | ||
} | ||
""" | ||
var config = Configuration.forTesting | ||
config.indentBlankLines = false | ||
assertPrettyPrintEqual(input: input, expected: expected, linelength: 80, configuration: config) | ||
} | ||
|
||
func testLineWithMoreWhitespacesThanIndentation() { | ||
let input = | ||
""" | ||
class A { | ||
func foo() -> Int { | ||
return 1 | ||
} | ||
\u{0020}\u{0020}\u{0020}\u{0020}\u{0020} | ||
func bar() -> Int { | ||
return 2 | ||
} | ||
} | ||
""" | ||
|
||
let expected = | ||
""" | ||
class A { | ||
func foo() -> Int { | ||
return 1 | ||
} | ||
\u{0020}\u{0020} | ||
func bar() -> Int { | ||
return 2 | ||
} | ||
} | ||
""" | ||
var config = Configuration.forTesting | ||
config.indentBlankLines = true | ||
assertPrettyPrintEqual(input: input, expected: expected, linelength: 80, configuration: config) | ||
} | ||
|
||
func testLineWithFewerWhitespacesThanIndentation() { | ||
let input = | ||
""" | ||
class A { | ||
func foo() -> Int { | ||
return 1 | ||
} | ||
\u{0020} | ||
func bar() -> Int { | ||
return 2 | ||
} | ||
} | ||
""" | ||
|
||
let expected = | ||
""" | ||
class A { | ||
func foo() -> Int { | ||
return 1 | ||
} | ||
\u{0020}\u{0020} | ||
func bar() -> Int { | ||
return 2 | ||
} | ||
} | ||
""" | ||
var config = Configuration.forTesting | ||
config.indentBlankLines = true | ||
assertPrettyPrintEqual(input: input, expected: expected, linelength: 80, configuration: config) | ||
} | ||
|
||
func testLineWithoutWhitespace() { | ||
let input = | ||
""" | ||
class A { | ||
func foo() -> Int { | ||
return 1 | ||
} | ||
func bar() -> Int { | ||
return 2 | ||
} | ||
} | ||
""" | ||
|
||
let expected = | ||
""" | ||
class A { | ||
func foo() -> Int { | ||
return 1 | ||
} | ||
\u{0020}\u{0020} | ||
func bar() -> Int { | ||
return 2 | ||
} | ||
} | ||
""" | ||
var config = Configuration.forTesting | ||
config.indentBlankLines = true | ||
assertPrettyPrintEqual(input: input, expected: expected, linelength: 80, configuration: config) | ||
} | ||
|
||
|
||
func testExpressionsWithUnnecessaryWhitespaces() { | ||
let input = | ||
""" | ||
class A { | ||
func foo() -> Int { | ||
return 1 | ||
} | ||
\u{0020}\u{0020} | ||
func bar() -> Int { | ||
return 2 | ||
} | ||
} | ||
""" | ||
|
||
let expected = | ||
""" | ||
class A { | ||
func foo() -> Int { | ||
return 1 | ||
} | ||
\u{0020}\u{0020} | ||
func bar() -> Int { | ||
return 2 | ||
} | ||
} | ||
""" | ||
var config = Configuration.forTesting | ||
config.indentBlankLines = true | ||
assertPrettyPrintEqual(input: input, expected: expected, linelength: 80, configuration: config) | ||
} | ||
} |