forked from scala-ide/scala-ide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TemplateValTest.scala
194 lines (175 loc) · 4.31 KB
/
TemplateValTest.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
package scala.tools.eclipse.semantichighlighting.classifier
import SymbolTypes._
import org.junit._
class TemplateValTest extends AbstractSymbolClassifierTest {
@Test
def basic_template_val {
checkSymbolClassification("""
object A {
val xxxxxx = 12
}""", """
object A {
val $TVAL$ = 12
}""",
Map("TVAL" -> TemplateVal))
}
@Test
def set_in_predef_is_a_val {
checkSymbolClassification("""
object A {
Set(1, 2, 3)
}""", """
object A {
$T$(1, 2, 3)
}""",
Map("T" -> TemplateVal))
}
@Test
def backticked_identifiers() {
checkSymbolClassification("""
class A {
val `identifier` = 42
`identifier`
}""", """
class A {
val $ TVAL $ = 42
$ TVAL $
}""",
Map("TVAL" -> TemplateVal))
}
@Test
def vals_from_objects() {
checkSymbolClassification("""
object X { val objectMember = 42 }
class A { X.objectMember }""", """
object X { val $ TVAL $ = 42 }
class A { X.$ TVAL $ }""",
Map("TVAL" -> TemplateVal))
}
@Test
def self_references_are_classified_as_template_vals() {
checkSymbolClassification("""
class A { self =>
self
def self(n: Int) = 42
}""", """
class A { $TV$ =>
$TV$
def $MD$(n: Int) = 42
}""",
Map("TV" -> TemplateVal, "MD" -> Method))
}
@Test
def case_class_params() {
checkSymbolClassification("""
case class A(xxxxxx: String)
""", """
case class A($TVAL$: String)
""",
Map("TVAL" -> TemplateVal))
}
@Test
def class_params() {
checkSymbolClassification("""
class A(xxxxxxx: String)
class B(val xxxxxx: String)
""", """
class A($PARAM$: String)
class B(val $TVAL$: String)
""",
Map("PARAM" -> Param, "TVAL" -> TemplateVal))
}
@Test
def class_params_passed_into_super_constructor() {
checkSymbolClassification("""
class A(xxxxxx: String) extends RuntimeException(xxxxxx)
""", """
class A($PARA$: String) extends RuntimeException($PARA$)
""",
Map("PARA" -> Param))
}
@Test
def val_class_params_passed_into_super_constructor() {
checkSymbolClassification("""
class A(val xxxxxx: String) extends RuntimeException(xxxxxx)
""", """
class A(val $TVAL$: String) extends RuntimeException($PARA$)
""",
Map("TVAL" -> TemplateVal, "PARA" -> Param))
}
@Test
def class_params_passed_into_super_constructor_as_expression() {
checkSymbolClassification("""
class A(xxxxxx: String) extends RuntimeException(xxxxxx + "")
""", """
class A($PARA$: String) extends RuntimeException($PARA$ + "")
""",
Map("PARA" -> Param))
}
@Test
def self_references_with_ascription() {
checkSymbolClassification("""
class A { self: AnyRef =>
self
}""", """
class A { $TV$: AnyRef =>
$TV$
}""",
Map("TV" -> TemplateVal))
}
@Test
def static_import() {
checkSymbolClassification("""
import java.io.File.pathSeparator
object A {
pathSeparator
}""", """
import java.io.File.$ TVAL $
object A {
$ TVAL $
}""",
Map("TVAL" -> TemplateVal))
}
@Test
def created_from_pair() {
checkSymbolClassification("""
class X {
val (xxxxxx, yyyyyy) = (1, 2)
}""", """
class X {
val ($TVAL$, $TVAL$) = (1, 2)
}""",
Map("TVAL" -> TemplateVal))
}
@Test
def created_from_case_deconstruction() {
checkSymbolClassification("""
class X {
val Some(xxxxxx) = Some(42)
}""", """
class X {
val Some($TVAL$) = Some(42)
}""",
Map("TVAL" -> TemplateVal))
}
@Test
@Ignore("does not work until presentation compiler stores more information in the AST (ticket #1001261)")
def in_package_object() {
checkSymbolClassification("""
object X {
val pv = packageObject.packageVal
}
package object packageObject {
val packageVal = 42
}
""", """
object X {
val pv = $POBJ $.$TVAL $
}
package object $POBJ $ {
val $TVAL $ = 42
}
""",
Map("TVAL" -> TemplateVal, "POBJ" -> Package))
}
}