forked from scala-ide/scalariform
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an option to doubly-indent method parameters.
Fixes scala-ide#122 (by adding a formatting option).
- Loading branch information
Showing
5 changed files
with
128 additions
and
3 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
94 changes: 94 additions & 0 deletions
94
scalariform/src/test/scala/scalariform/formatter/DoubleIndentMethodFormatterTest.scala
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,94 @@ | ||
package scalariform.formatter | ||
|
||
import scalariform.parser._ | ||
import scalariform.formatter.preferences._ | ||
|
||
// format: OFF | ||
class DoubleIndentMethodFormatterTest extends AbstractFormatterTest { | ||
|
||
override val debug = false | ||
|
||
{ | ||
|
||
implicit val formattingPreferences = | ||
FormattingPreferences.setPreference(DoubleIndentMethodDeclaration, true) | ||
|
||
// Test basic formatting for regressions. | ||
"def foo" ==> "def foo" | ||
|
||
"def foo=42" ==> "def foo = 42" | ||
|
||
"def foo()" ==> "def foo()" | ||
|
||
"def foo(n:Int)" ==> "def foo(n: Int)" | ||
|
||
"""def foo(n: Int | ||
|)""" ==> | ||
"def foo(n: Int)" | ||
|
||
"def foo( n:Int,m:String )" ==> "def foo(n: Int, m: String)" | ||
|
||
"def foo{doStuff()}" ==> "def foo { doStuff() }" | ||
|
||
"def foo(x_ : Int)" ==> "def foo(x_ : Int)" | ||
|
||
"""def a | ||
|: String""" ==> | ||
"""def a: String""" | ||
|
||
"""def a() | ||
|{ | ||
|b | ||
| }""" ==> | ||
"""def a() { | ||
| b | ||
|}""" | ||
|
||
"""def a[B, | ||
|C] | ||
|()""" ==> | ||
"""def a[B, C]()""" | ||
|
||
// Verify that continued parameters are maintained & doubly-indented. | ||
"""def foo( | ||
| a: String)""" ==> | ||
"""def foo( | ||
| a: String | ||
|)""" | ||
|
||
// TODO: Broken until https://github.com/scala-ide/scalariform/issues/187 is fixed. | ||
"""def foo(a: String, | ||
| b: String)""" =/=> | ||
"""def foo( | ||
| a: String, | ||
| b: String | ||
|)""" | ||
|
||
// TODO: Broken until https://github.com/scala-ide/scalariform/issues/187 is fixed. | ||
"""def foo(a: String, | ||
| b: String)""" =/=> | ||
"""def foo( | ||
| a: String, | ||
| b: String | ||
|)""" | ||
|
||
"""def foo(a: String, b: String, | ||
| c: String)""" ==> | ||
"""def foo(a: String, b: String, | ||
| c: String)""" | ||
|
||
"""def foo( | ||
| a: String, | ||
| b: String)""" ==> | ||
"""def foo( | ||
| a: String, | ||
| b: String | ||
|)""" | ||
} | ||
|
||
def parse(parser: ScalaParser) = parser.nonLocalDefOrDcl() | ||
|
||
type Result = FullDefOrDcl | ||
|
||
def format(formatter: ScalaFormatter, result: Result) = formatter.format(result)(FormatterState(indentLevel = 0)) | ||
} |