blob: 53caa5e62f02e590579e26073ffbd6402ffe625b (
plain) (
blame)
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
|
class Slazz {
val s1 = 'myFirstSymbol
val s2 = 'mySecondSymbol
def s3 = 'myThirdSymbol
var s4: Symbol = null
s4 = 'myFourthSymbol
}
class Base {
val basesymbol = 'symbase
}
class Sub extends Base {
val subsymbol = 'symsub
}
trait Signs {
val ind = 'indication
val trace = 'trace
}
trait Lazy1 {
lazy val v1 = "lazy v1"
lazy val s1 = 'lazySymbol1
}
trait Lazy2 {
lazy val v2 = "lazy v2"
lazy val s2 = 'lazySymbol2
}
trait Lazy3 {
lazy val v3 = "lazy v3"
lazy val s3 = 'lazySymbol3
}
object SingletonOfLazyness {
lazy val lazysym = 'lazySymbol
lazy val another = 'another
lazy val lastone = 'lastone
}
/*
* Tests symbols to see if they work correct.
*/
object Test {
class Inner {
val simba = 'smba
var mfs: Symbol = null
mfs = Symbol("mfsa")
}
object InnerObject {
val o1 = 'aaa
val o2 = 'ddd
}
def aSymbol = 'myFirstSymbol
val anotherSymbol = 'mySecondSymbol
def main(args: Array[String]) {
testLiterals
testForLoop
testInnerClasses
testInnerObjects
testWithHashMaps
testLists
testAnonymous
testNestedObject
testInheritance
testTraits
testLazyTraits
testLazyObjects
}
def testLiterals {
val scl = new Slazz
assert(scl.s1 == aSymbol)
assert(scl.s2 == anotherSymbol)
assert(scl.s3 == 'myThirdSymbol)
assert(scl.s4 == Symbol.apply("myFourthSymbol"))
assert(scl.s1 == Symbol("myFirstSymbol"))
}
def testForLoop {
for (i <- 0 until 100) List("Val" + i)
}
def testInnerClasses {
val innerPower = new Inner
assert(innerPower.simba == 'smba)
assert(innerPower.mfs == 'mfsa)
}
def testInnerObjects {
assert(InnerObject.o1 == 'aaa)
assert(InnerObject.o2 == 'ddd)
}
def testWithHashMaps {
val map = new collection.mutable.HashMap[Symbol, Symbol]
map.put(InnerObject.o1, 'smba)
map.put(InnerObject.o2, 'mfsa)
map.put(Symbol("WeirdKey" + 1), Symbol("Weird" + "Val" + 1))
assert(map('aaa) == 'smba)
assert(map('ddd) == 'mfsa)
assert(map('WeirdKey1) == Symbol("WeirdVal1"))
map.clear
for (i <- 0 until 100) map.put(Symbol("symKey" + i), Symbol("symVal" + i))
assert(map(Symbol("symKey15")) == Symbol("symVal15"))
assert(map('symKey22) == 'symVal22)
assert(map('symKey73) == 'symVal73)
assert(map('symKey56) == 'symVal56)
assert(map('symKey91) == 'symVal91)
}
def testLists {
var lst: List[Symbol] = Nil
for (i <- 0 until 100) lst ::= Symbol("lsym" + (99 - i))
assert(lst(0) == 'lsym0)
assert(lst(10) == 'lsym10)
assert(lst(30) == 'lsym30)
assert(lst(40) == 'lsym40)
assert(lst(65) == 'lsym65)
assert(lst(90) == 'lsym90)
}
def testAnonymous { // TODO complaints classdef can't be found for some reason, runs fine in my case
// val anon = () => {
// val simba = 'smba
// simba
// }
// val an2 = () => {
// object nested {
// val m = 'mfsa
// }
// nested.m
// }
// val an3 = () => {
// object nested {
// val f = () => {
// 'layered
// }
// def gets = f()
// }
// nested.gets
// }
// val inner = new Inner
// assert(anon() == inner.simba)
// assert(anon().toString == "'smba")
// assert(an2() == 'mfsa)
// assert(an3() == Symbol("layered" + ""))
}
def testNestedObject {
object nested {
def sign = 'sign
def insignia = 'insignia
}
assert(nested.sign == 'sign)
assert(nested.insignia == 'insignia)
assert(('insignia).toString == "'insignia")
}
def testInheritance {
val base = new Base
val sub = new Sub
assert(base.basesymbol == 'symbase)
assert(sub.subsymbol == 'symsub)
assert(sub.basesymbol == 'symbase)
val anon = new Sub {
def subsubsymbol = 'symsubsub
}
assert(anon.subsubsymbol == 'symsubsub)
assert(anon.subsymbol == 'symsub)
assert(anon.basesymbol == 'symbase)
object nested extends Sub {
def objsymbol = 'symobj
}
assert(nested.objsymbol == 'symobj)
assert(nested.subsymbol == 'symsub)
assert(nested.basesymbol == 'symbase)
assert(('symbase).toString == "'symbase")
}
def testTraits {
val fromTrait = new AnyRef with Signs {
def traitsymbol = 'traitSymbol
}
assert(fromTrait.traitsymbol == 'traitSymbol)
assert(fromTrait.ind == 'indication)
assert(fromTrait.trace == 'trace)
assert(('trace).toString == "'trace")
trait Compl {
val s1 = 's1
def s2 = 's2
object inner {
val s3 = 's3
val s4 = 's4
}
}
val compl = new Sub with Signs with Compl
assert(compl.s1 == 's1)
assert(compl.s2 == 's2)
assert(compl.inner.s3 == 's3)
assert(compl.inner.s4 == 's4)
assert(compl.ind == 'indication)
assert(compl.trace == 'trace)
assert(compl.subsymbol == 'symsub)
assert(compl.basesymbol == 'symbase)
object Local extends Signs with Compl {
val s5 = 's5
def s6 = 's6
object inner2 {
val s7 = 's7
def s8 = 's8
}
}
assert(Local.s5 == 's5)
assert(Local.s6 == 's6)
assert(Local.inner2.s7 == 's7)
assert(Local.inner2.s8 == 's8)
assert(Local.inner.s3 == 's3)
assert(Local.inner.s4 == 's4)
assert(Local.s1 == 's1)
assert(Local.s2 == 's2)
assert(Local.trace == 'trace)
assert(Local.ind == 'indication)
assert(('s8).toString == "'s8")
}
def testLazyTraits {
val l1 = new AnyRef with Lazy1
val l2 = new AnyRef with Lazy2
val l3 = new AnyRef with Lazy3
l1.v1
l2.v2
l3.v3
assert((l1.s1).toString == "'lazySymbol1")
assert(l2.s2 == Symbol("lazySymbol" + 2))
assert(l3.s3 == 'lazySymbol3)
}
def testLazyObjects {
assert(SingletonOfLazyness.lazysym == 'lazySymbol)
assert(SingletonOfLazyness.another == Symbol("ano" + "ther"))
assert((SingletonOfLazyness.lastone).toString == "'lastone")
object nested {
lazy val sym1 = 'snested1
lazy val sym2 = 'snested2
}
assert(nested.sym1 == 'snested1)
assert(nested.sym2 == Symbol("snested" + "2"))
}
}
|