/
DefOrDclFormatterTest.scala
101 lines (67 loc) · 2.01 KB
/
DefOrDclFormatterTest.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package scalariform.formatter
import scalariform.parser._
import scalariform.formatter._
// format: OFF
class DefOrDclFormatterTest extends AbstractFormatterTest {
override val debug = false
"def foo" ==> "def foo"
"def foo()" ==> "def foo()"
"def foo=42" ==> "def foo = 42"
"def foo{doStuff()}" ==> "def foo { doStuff() }"
"def foo={doStuff()}" ==> "def foo = { doStuff() }"
"def foo ()" ==> "def foo()"
"def foo(n:Int)" ==> "def foo(n: Int)"
"def foo( n:Int,m:String )" ==> "def foo(n: Int, m: String)"
"def foo:Int" ==> "def foo: Int"
"def modN ( n :Int ) (x: Int) = ((x % n) == 0)" ==> "def modN(n: Int)(x: Int) = ((x % n) == 0)"
"def foo(a: Int=123+2, b: Int=456+7)" ==> "def foo(a: Int = 123 + 2, b: Int = 456 + 7)"
"def foo [ - T , + U ] (t: T): U" ==> "def foo[-T, +U](t: T): U"
"def foo[X<%T1,Y<:T2,Z>:T3]()" ==> "def foo[X <% T1, Y <: T2, Z >: T3]()"
"def foo(x: =>Int, y: Int *)" ==> "def foo(x: => Int, y: Int*)"
"def foo(x_ : Int)" ==> "def foo(x_ : Int)"
"private def x" ==> "private def x"
"private[pack]def x" ==> "private[pack] def x"
"private[pack]val x" ==> "private[pack] val x"
"private[pack]var x" ==> "private[pack] var x"
"""def a
|: String""" ==>
"""def a: String"""
"""def foo =
| if (true)
| 1
| else
| 2""" ==>
"""def foo =
| if (true)
| 1
| else
| 2"""
"""val x =
| if (true)
| 42
| else
| 24""" ==>
"""val x =
| if (true)
| 42
| else
| 24"""
"""def a()
|{
|b
| }""" ==>
"""def a() {
| b
|}"""
"""type
|B""" ==>
"""type B"""
"""type
|
|B""" ==>
"""type B"""
"class A { val b = _.c }" ==> "class A { val b = _.c }"
type Result = FullDefOrDcl
def getParser(parser: ScalaCombinatorParser): ScalaCombinatorParser#Parser[Result] = parser.phrase(parser.nonLocalDefOrDcl)
def format(formatter: ScalaFormatter, result: Result) = formatter.format(result)(FormatterState(indentLevel = 0))
}