This repository has been archived by the owner on Sep 3, 2020. It is now read-only.
/
ExpandCaseClassBindingTest.scala
153 lines (140 loc) · 3.36 KB
/
ExpandCaseClassBindingTest.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*
* Copyright 2005-2010 LAMP/EPFL
*/
package scala.tools.refactoring
package tests.implementations
import implementations.InlineLocal
import tests.util.TestRefactoring
import tests.util.TestHelper
import org.junit.Assert._
import scala.tools.refactoring.implementations.ExpandCaseClassBinding
import language.reflectiveCalls
class ExpandCaseClassBindingTest extends TestHelper with TestRefactoring {
def expand(pro: FileSet) = new TestRefactoringImpl(pro) {
val refactoring = new ExpandCaseClassBinding with TestProjectIndex
val changes = performRefactoring()
}.changes
@Test
def expandSome() = new FileSet {
"""
package extractLocal
object Demo {
Some("string") match {
case /*(*/s/*)*/ =>
}
}
""" becomes
"""
package extractLocal
object Demo {
Some("string") match {
case /*(*/Some(x)/*)*/ =>
}
}
"""
} applyRefactoring(expand)
@Test
def expandSomeWithReference() = new FileSet {
"""
package extractLocal
object Demo {
Some("string") match {
case /*(*/s/*)*/ => s
}
}
""" becomes
"""
package extractLocal
object Demo {
Some("string") match {
case /*(*/s @ Some(x)/*)*/ => s
}
}
"""
} applyRefactoring(expand)
@Test
def expandWithMultipleParams() = new FileSet {
"""
package expandWithMultipleParams
case class Abc(a: String, b: Int, c: Double)
object Demo {
Abc("", 5, 5.0) match {
case /*(*/whatever/*)*/ =>
}
}
""" becomes
"""
package expandWithMultipleParams
case class Abc(a: String, b: Int, c: Double)
object Demo {
Abc("", 5, 5.0) match {
case /*(*/Abc(a, b, c)/*)*/ =>
}
}
"""
} applyRefactoring(expand)
@Test
def expandTuple() = new FileSet {
"""
object Demo {
("", 5, 5.0) match {
case /*(*/whatever/*)*/ =>
}
}
""" becomes
"""
object Demo {
("", 5, 5.0) match {
case /*(*/(_1, _2, _3)/*)*/ =>
}
}
"""
} applyRefactoring(expand)
@Test
def expandNested() = new FileSet {
"""
case class Pair[T, U](first: T, second: U)
object Demo {
List(Pair(true, false)) match {
case /*(*/whatever/*)*/ :: Nil => whatever
}
}
""" becomes
"""
case class Pair[T, U](first: T, second: U)
object Demo {
List(Pair(true, false)) match {
case /*(*/whatever @ Pair(first, second)/*)*/ :: Nil => whatever
}
}
"""
} applyRefactoring(expand)
@Test
def expandInnerNested() = new FileSet {
"""
case class Pair[T, U](first: T, second: U)
object Demo {
List(Pair(Some(true), false)) match {
case pair @ Pair(/*(*/first/*)*/, second) :: Nil =>
}
}
""" becomes
"""
case class Pair[T, U](first: T, second: U)
object Demo {
List(Pair(Some(true), false)) match {
case pair @ Pair(/*(*/Some(x)/*)*/, second) :: Nil =>
}
}
"""
} applyRefactoring(expand)
@Test(expected=classOf[PreparationException])
def illegalExpansion() = new FileSet {
"""
package illegalExpansion
object /*(*/Xy/*)*/ {
}
""" becomes
""""""
} applyRefactoring(expand)
}