~ubuntu-branches/debian/sid/scala/sid

« back to all changes in this revision

Viewing changes to test/files/run/SymbolsTest.scala

  • Committer: Package Import Robot
  • Author(s): Emmanuel Bourg, Mehdi Dogguy, Lucas Satabin, Frank S. Thomas, Emmanuel Bourg
  • Date: 2015-06-05 23:52:59 UTC
  • mfrom: (1.2.11)
  • Revision ID: package-import@ubuntu.com-20150605235259-wk00vgk83dh8o19g
Tags: 2.10.5-1
* Team upload.

[ Mehdi Dogguy ]
* New upstream release (Closes: #744278).

[ Lucas Satabin ]
* Update patches
* Update the clean target
* Update paths of elements to install
* Update watch file

[ Frank S. Thomas ]
* Remove myself from Uploaders.

[ Emmanuel Bourg ]
* The package has been adopted by the Java Team (Closes: #754935)
* Patched the build to avoid downloading libraries from the Internet
* Replaced the minified JavaScript files with unobfuscated ones
* No longer build scala-partest.jar until diffutils is packaged or replaced
* debian/watch: Fixed the versions matched (x.y.z instead of x.y.z..z)
* debian/rules:
  - Added the missing get-orig-source target (Closes: #724704)
  - Improved the clean target
* debian/control:
  - Build depend on scala (>= 2.10) and bnd
  - Use canonical URLs for the Vcs-* fields
  - Standards-Version updated to 3.9.6 (no changes)
* Switch to debhelper level 9

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
 
3
 
 
4
 
 
5
 
class Slazz {
6
 
  val s1 = 'myFirstSymbol
7
 
  val s2 = 'mySecondSymbol
8
 
  def s3 = 'myThirdSymbol
9
 
  var s4: Symbol = null
10
 
 
11
 
  s4 = 'myFourthSymbol
12
 
}
13
 
 
14
 
class Base {
15
 
  val basesymbol = 'symbase
16
 
}
17
 
 
18
 
class Sub extends Base {
19
 
  val subsymbol = 'symsub
20
 
}
21
 
 
22
 
trait Signs {
23
 
  val ind = 'indication
24
 
  val trace = 'trace
25
 
}
26
 
 
27
 
trait Lazy1 {
28
 
  lazy val v1 = "lazy v1"
29
 
  lazy val s1 = 'lazySymbol1
30
 
}
31
 
 
32
 
trait Lazy2 {
33
 
  lazy val v2 = "lazy v2"
34
 
  lazy val s2 = 'lazySymbol2
35
 
}
36
 
 
37
 
trait Lazy3 {
38
 
  lazy val v3 = "lazy v3"
39
 
  lazy val s3 = 'lazySymbol3
40
 
}
41
 
 
42
 
object SingletonOfLazyness {
43
 
  lazy val lazysym = 'lazySymbol
44
 
  lazy val another = 'another
45
 
  lazy val lastone = 'lastone
46
 
}
47
 
 
48
 
/*
49
 
 * Tests symbols to see if they work correct.
50
 
 */
51
 
object Test {
52
 
  class Inner {
53
 
    val simba = 'smba
54
 
    var mfs: Symbol = null
55
 
    mfs = Symbol("mfsa")
56
 
  }
57
 
  
58
 
  object InnerObject {
59
 
    val o1 = 'aaa
60
 
    val o2 = 'ddd
61
 
  }
62
 
 
63
 
  def aSymbol = 'myFirstSymbol
64
 
  val anotherSymbol = 'mySecondSymbol
65
 
 
66
 
  def main(args: Array[String]) {
67
 
    testLiterals
68
 
    testForLoop
69
 
    testInnerClasses
70
 
    testInnerObjects
71
 
    testWithHashMaps
72
 
    testLists
73
 
    testAnonymous
74
 
    testNestedObject
75
 
    testInheritance
76
 
    testTraits
77
 
    testLazyTraits
78
 
    testLazyObjects
79
 
  }
80
 
 
81
 
  def testLiterals {
82
 
    val scl = new Slazz
83
 
    assert(scl.s1 == aSymbol)
84
 
    assert(scl.s2 == anotherSymbol)
85
 
    assert(scl.s3 == 'myThirdSymbol)
86
 
    assert(scl.s4 == Symbol.apply("myFourthSymbol"))
87
 
    assert(scl.s1 == Symbol("myFirstSymbol"))
88
 
  }
89
 
 
90
 
  def testForLoop {
91
 
    for (i <- 0 until 100) List("Val" + i)
92
 
  }
93
 
 
94
 
  def testInnerClasses {
95
 
    val innerPower = new Inner
96
 
    assert(innerPower.simba == 'smba)
97
 
    assert(innerPower.mfs == 'mfsa)
98
 
  }
99
 
 
100
 
  def testInnerObjects {
101
 
    assert(InnerObject.o1 == 'aaa)
102
 
    assert(InnerObject.o2 == 'ddd)
103
 
  }
104
 
  
105
 
  def testWithHashMaps {
106
 
    val map = new collection.mutable.HashMap[Symbol, Symbol]
107
 
    map.put(InnerObject.o1, 'smba)
108
 
    map.put(InnerObject.o2, 'mfsa)
109
 
    map.put(Symbol("WeirdKey" + 1), Symbol("Weird" + "Val" + 1))
110
 
    assert(map('aaa) == 'smba)
111
 
    assert(map('ddd) == 'mfsa)
112
 
    assert(map('WeirdKey1) == Symbol("WeirdVal1"))
113
 
    
114
 
    map.clear
115
 
    for (i <- 0 until 100) map.put(Symbol("symKey" + i), Symbol("symVal" + i))
116
 
    assert(map(Symbol("symKey15")) == Symbol("symVal15"))
117
 
    assert(map('symKey22) == 'symVal22)
118
 
    assert(map('symKey73) == 'symVal73)
119
 
    assert(map('symKey56) == 'symVal56)
120
 
    assert(map('symKey91) == 'symVal91)
121
 
  }
122
 
 
123
 
  def testLists {
124
 
    var lst: List[Symbol] = Nil
125
 
    for (i <- 0 until 100) lst ::= Symbol("lsym" + (99 - i))
126
 
    assert(lst(0) == 'lsym0)
127
 
    assert(lst(10) == 'lsym10)
128
 
    assert(lst(30) == 'lsym30)
129
 
    assert(lst(40) == 'lsym40)
130
 
    assert(lst(65) == 'lsym65)
131
 
    assert(lst(90) == 'lsym90)
132
 
  }
133
 
 
134
 
  def testAnonymous { // TODO complaints classdef can't be found for some reason, runs fine in my case
135
 
    // val anon = () => {
136
 
    //   val simba = 'smba
137
 
    //   simba
138
 
    // }
139
 
    // val an2 = () => {
140
 
    //   object nested {
141
 
    //  val m = 'mfsa
142
 
    //   }
143
 
    //   nested.m
144
 
    // }
145
 
    // val an3 = () => {
146
 
    //   object nested {
147
 
    //  val f = () => {
148
 
    //    'layered
149
 
    //  }
150
 
    //  def gets = f()
151
 
    //   }
152
 
    //   nested.gets
153
 
    // }
154
 
    // val inner = new Inner
155
 
    // assert(anon() == inner.simba)
156
 
    // assert(anon().toString == "'smba")
157
 
    // assert(an2() == 'mfsa)
158
 
    // assert(an3() == Symbol("layered" + ""))
159
 
  }
160
 
 
161
 
  def testNestedObject {
162
 
    object nested {
163
 
      def sign = 'sign
164
 
      def insignia = 'insignia
165
 
    }
166
 
    assert(nested.sign == 'sign)
167
 
    assert(nested.insignia == 'insignia)
168
 
    assert(('insignia).toString == "'insignia")
169
 
  }
170
 
 
171
 
  def testInheritance {
172
 
    val base = new Base
173
 
    val sub = new Sub
174
 
    assert(base.basesymbol == 'symbase)
175
 
    assert(sub.subsymbol == 'symsub)
176
 
    assert(sub.basesymbol == 'symbase)
177
 
 
178
 
    val anon = new Sub {
179
 
      def subsubsymbol = 'symsubsub
180
 
    }
181
 
    assert(anon.subsubsymbol == 'symsubsub)
182
 
    assert(anon.subsymbol == 'symsub)
183
 
    assert(anon.basesymbol == 'symbase)
184
 
    
185
 
    object nested extends Sub {
186
 
      def objsymbol = 'symobj
187
 
    }
188
 
    assert(nested.objsymbol == 'symobj)
189
 
    assert(nested.subsymbol == 'symsub)
190
 
    assert(nested.basesymbol == 'symbase)
191
 
    assert(('symbase).toString == "'symbase")
192
 
  }
193
 
 
194
 
  def testTraits {
195
 
    val fromTrait = new AnyRef with Signs {
196
 
      def traitsymbol = 'traitSymbol
197
 
    }
198
 
 
199
 
    assert(fromTrait.traitsymbol == 'traitSymbol)
200
 
    assert(fromTrait.ind == 'indication)
201
 
    assert(fromTrait.trace == 'trace)
202
 
    assert(('trace).toString == "'trace")
203
 
 
204
 
    trait Compl {
205
 
      val s1 = 's1
206
 
      def s2 = 's2
207
 
      object inner {
208
 
        val s3 = 's3
209
 
        val s4 = 's4
210
 
      }
211
 
    }
212
 
 
213
 
    val compl = new Sub with Signs with Compl
214
 
    assert(compl.s1 == 's1)
215
 
    assert(compl.s2 == 's2)
216
 
    assert(compl.inner.s3 == 's3)
217
 
    assert(compl.inner.s4 == 's4)
218
 
    assert(compl.ind == 'indication)
219
 
    assert(compl.trace == 'trace)
220
 
    assert(compl.subsymbol == 'symsub)
221
 
    assert(compl.basesymbol == 'symbase)
222
 
 
223
 
    object Local extends Signs with Compl {
224
 
      val s5 = 's5
225
 
      def s6 = 's6
226
 
      object inner2 {
227
 
        val s7 = 's7
228
 
        def s8 = 's8
229
 
      }
230
 
    }
231
 
    assert(Local.s5 == 's5)
232
 
    assert(Local.s6 == 's6)
233
 
    assert(Local.inner2.s7 == 's7)
234
 
    assert(Local.inner2.s8 == 's8)
235
 
    assert(Local.inner.s3 == 's3)
236
 
    assert(Local.inner.s4 == 's4)
237
 
    assert(Local.s1 == 's1)
238
 
    assert(Local.s2 == 's2)
239
 
    assert(Local.trace == 'trace)
240
 
    assert(Local.ind == 'indication)
241
 
    assert(('s8).toString == "'s8")
242
 
  }
243
 
 
244
 
  def testLazyTraits {
245
 
    val l1 = new AnyRef with Lazy1
246
 
    val l2 = new AnyRef with Lazy2
247
 
    val l3 = new AnyRef with Lazy3
248
 
 
249
 
    l1.v1
250
 
    l2.v2
251
 
    l3.v3
252
 
    assert((l1.s1).toString == "'lazySymbol1")
253
 
    assert(l2.s2 == Symbol("lazySymbol" + 2))
254
 
    assert(l3.s3 == 'lazySymbol3)
255
 
  }
256
 
 
257
 
  def testLazyObjects {
258
 
    assert(SingletonOfLazyness.lazysym == 'lazySymbol)
259
 
    assert(SingletonOfLazyness.another == Symbol("ano" + "ther"))
260
 
    assert((SingletonOfLazyness.lastone).toString == "'lastone")
261
 
 
262
 
    object nested {
263
 
      lazy val sym1 = 'snested1
264
 
      lazy val sym2 = 'snested2
265
 
    }
266
 
 
267
 
    assert(nested.sym1 == 'snested1)
268
 
    assert(nested.sym2 == Symbol("snested" + "2"))
269
 
  }
270
 
 
271
 
}
272
 
 
273
 
 
274
 
 
275
 
 
276
 
 
277
 
 
278
 
 
279
 
 
280
 
 
281
 
 
282
 
 
283
 
 
 
1
 
 
2
 
 
3
 
 
4
 
 
5
class Slazz {
 
6
  val s1 = 'myFirstSymbol
 
7
  val s2 = 'mySecondSymbol
 
8
  def s3 = 'myThirdSymbol
 
9
  var s4: Symbol = null
 
10
 
 
11
  s4 = 'myFourthSymbol
 
12
}
 
13
 
 
14
class Base {
 
15
  val basesymbol = 'symbase
 
16
}
 
17
 
 
18
class Sub extends Base {
 
19
  val subsymbol = 'symsub
 
20
}
 
21
 
 
22
trait Signs {
 
23
  val ind = 'indication
 
24
  val trace = 'trace
 
25
}
 
26
 
 
27
trait Lazy1 {
 
28
  lazy val v1 = "lazy v1"
 
29
  lazy val s1 = 'lazySymbol1
 
30
}
 
31
 
 
32
trait Lazy2 {
 
33
  lazy val v2 = "lazy v2"
 
34
  lazy val s2 = 'lazySymbol2
 
35
}
 
36
 
 
37
trait Lazy3 {
 
38
  lazy val v3 = "lazy v3"
 
39
  lazy val s3 = 'lazySymbol3
 
40
}
 
41
 
 
42
object SingletonOfLazyness {
 
43
  lazy val lazysym = 'lazySymbol
 
44
  lazy val another = 'another
 
45
  lazy val lastone = 'lastone
 
46
}
 
47
 
 
48
/*
 
49
 * Tests symbols to see if they work correct.
 
50
 */
 
51
object Test {
 
52
  class Inner {
 
53
    val simba = 'smba
 
54
    var mfs: Symbol = null
 
55
    mfs = Symbol("mfsa")
 
56
  }
 
57
 
 
58
  object InnerObject {
 
59
    val o1 = 'aaa
 
60
    val o2 = 'ddd
 
61
  }
 
62
 
 
63
  def aSymbol = 'myFirstSymbol
 
64
  val anotherSymbol = 'mySecondSymbol
 
65
 
 
66
  def main(args: Array[String]) {
 
67
    testLiterals
 
68
    testForLoop
 
69
    testInnerClasses
 
70
    testInnerObjects
 
71
    testWithHashMaps
 
72
    testLists
 
73
    testAnonymous
 
74
    testNestedObject
 
75
    testInheritance
 
76
    testTraits
 
77
    testLazyTraits
 
78
    testLazyObjects
 
79
  }
 
80
 
 
81
  def testLiterals {
 
82
    val scl = new Slazz
 
83
    assert(scl.s1 == aSymbol)
 
84
    assert(scl.s2 == anotherSymbol)
 
85
    assert(scl.s3 == 'myThirdSymbol)
 
86
    assert(scl.s4 == Symbol.apply("myFourthSymbol"))
 
87
    assert(scl.s1 == Symbol("myFirstSymbol"))
 
88
  }
 
89
 
 
90
  def testForLoop {
 
91
    for (i <- 0 until 100) List("Val" + i)
 
92
  }
 
93
 
 
94
  def testInnerClasses {
 
95
    val innerPower = new Inner
 
96
    assert(innerPower.simba == 'smba)
 
97
    assert(innerPower.mfs == 'mfsa)
 
98
  }
 
99
 
 
100
  def testInnerObjects {
 
101
    assert(InnerObject.o1 == 'aaa)
 
102
    assert(InnerObject.o2 == 'ddd)
 
103
  }
 
104
 
 
105
  def testWithHashMaps {
 
106
    val map = new collection.mutable.HashMap[Symbol, Symbol]
 
107
    map.put(InnerObject.o1, 'smba)
 
108
    map.put(InnerObject.o2, 'mfsa)
 
109
    map.put(Symbol("WeirdKey" + 1), Symbol("Weird" + "Val" + 1))
 
110
    assert(map('aaa) == 'smba)
 
111
    assert(map('ddd) == 'mfsa)
 
112
    assert(map('WeirdKey1) == Symbol("WeirdVal1"))
 
113
 
 
114
    map.clear
 
115
    for (i <- 0 until 100) map.put(Symbol("symKey" + i), Symbol("symVal" + i))
 
116
    assert(map(Symbol("symKey15")) == Symbol("symVal15"))
 
117
    assert(map('symKey22) == 'symVal22)
 
118
    assert(map('symKey73) == 'symVal73)
 
119
    assert(map('symKey56) == 'symVal56)
 
120
    assert(map('symKey91) == 'symVal91)
 
121
  }
 
122
 
 
123
  def testLists {
 
124
    var lst: List[Symbol] = Nil
 
125
    for (i <- 0 until 100) lst ::= Symbol("lsym" + (99 - i))
 
126
    assert(lst(0) == 'lsym0)
 
127
    assert(lst(10) == 'lsym10)
 
128
    assert(lst(30) == 'lsym30)
 
129
    assert(lst(40) == 'lsym40)
 
130
    assert(lst(65) == 'lsym65)
 
131
    assert(lst(90) == 'lsym90)
 
132
  }
 
133
 
 
134
  def testAnonymous { // TODO complaints classdef can't be found for some reason, runs fine in my case
 
135
    // val anon = () => {
 
136
    //   val simba = 'smba
 
137
    //   simba
 
138
    // }
 
139
    // val an2 = () => {
 
140
    //   object nested {
 
141
    //  val m = 'mfsa
 
142
    //   }
 
143
    //   nested.m
 
144
    // }
 
145
    // val an3 = () => {
 
146
    //   object nested {
 
147
    //  val f = () => {
 
148
    //    'layered
 
149
    //  }
 
150
    //  def gets = f()
 
151
    //   }
 
152
    //   nested.gets
 
153
    // }
 
154
    // val inner = new Inner
 
155
    // assert(anon() == inner.simba)
 
156
    // assert(anon().toString == "'smba")
 
157
    // assert(an2() == 'mfsa)
 
158
    // assert(an3() == Symbol("layered" + ""))
 
159
  }
 
160
 
 
161
  def testNestedObject {
 
162
    object nested {
 
163
      def sign = 'sign
 
164
      def insignia = 'insignia
 
165
    }
 
166
    assert(nested.sign == 'sign)
 
167
    assert(nested.insignia == 'insignia)
 
168
    assert(('insignia).toString == "'insignia")
 
169
  }
 
170
 
 
171
  def testInheritance {
 
172
    val base = new Base
 
173
    val sub = new Sub
 
174
    assert(base.basesymbol == 'symbase)
 
175
    assert(sub.subsymbol == 'symsub)
 
176
    assert(sub.basesymbol == 'symbase)
 
177
 
 
178
    val anon = new Sub {
 
179
      def subsubsymbol = 'symsubsub
 
180
    }
 
181
    assert(anon.subsubsymbol == 'symsubsub)
 
182
    assert(anon.subsymbol == 'symsub)
 
183
    assert(anon.basesymbol == 'symbase)
 
184
 
 
185
    object nested extends Sub {
 
186
      def objsymbol = 'symobj
 
187
    }
 
188
    assert(nested.objsymbol == 'symobj)
 
189
    assert(nested.subsymbol == 'symsub)
 
190
    assert(nested.basesymbol == 'symbase)
 
191
    assert(('symbase).toString == "'symbase")
 
192
  }
 
193
 
 
194
  def testTraits {
 
195
    val fromTrait = new AnyRef with Signs {
 
196
      def traitsymbol = 'traitSymbol
 
197
    }
 
198
 
 
199
    assert(fromTrait.traitsymbol == 'traitSymbol)
 
200
    assert(fromTrait.ind == 'indication)
 
201
    assert(fromTrait.trace == 'trace)
 
202
    assert(('trace).toString == "'trace")
 
203
 
 
204
    trait Compl {
 
205
      val s1 = 's1
 
206
      def s2 = 's2
 
207
      object inner {
 
208
        val s3 = 's3
 
209
        val s4 = 's4
 
210
      }
 
211
    }
 
212
 
 
213
    val compl = new Sub with Signs with Compl
 
214
    assert(compl.s1 == 's1)
 
215
    assert(compl.s2 == 's2)
 
216
    assert(compl.inner.s3 == 's3)
 
217
    assert(compl.inner.s4 == 's4)
 
218
    assert(compl.ind == 'indication)
 
219
    assert(compl.trace == 'trace)
 
220
    assert(compl.subsymbol == 'symsub)
 
221
    assert(compl.basesymbol == 'symbase)
 
222
 
 
223
    object Local extends Signs with Compl {
 
224
      val s5 = 's5
 
225
      def s6 = 's6
 
226
      object inner2 {
 
227
        val s7 = 's7
 
228
        def s8 = 's8
 
229
      }
 
230
    }
 
231
    assert(Local.s5 == 's5)
 
232
    assert(Local.s6 == 's6)
 
233
    assert(Local.inner2.s7 == 's7)
 
234
    assert(Local.inner2.s8 == 's8)
 
235
    assert(Local.inner.s3 == 's3)
 
236
    assert(Local.inner.s4 == 's4)
 
237
    assert(Local.s1 == 's1)
 
238
    assert(Local.s2 == 's2)
 
239
    assert(Local.trace == 'trace)
 
240
    assert(Local.ind == 'indication)
 
241
    assert(('s8).toString == "'s8")
 
242
  }
 
243
 
 
244
  def testLazyTraits {
 
245
    val l1 = new AnyRef with Lazy1
 
246
    val l2 = new AnyRef with Lazy2
 
247
    val l3 = new AnyRef with Lazy3
 
248
 
 
249
    l1.v1
 
250
    l2.v2
 
251
    l3.v3
 
252
    assert((l1.s1).toString == "'lazySymbol1")
 
253
    assert(l2.s2 == Symbol("lazySymbol" + 2))
 
254
    assert(l3.s3 == 'lazySymbol3)
 
255
  }
 
256
 
 
257
  def testLazyObjects {
 
258
    assert(SingletonOfLazyness.lazysym == 'lazySymbol)
 
259
    assert(SingletonOfLazyness.another == Symbol("ano" + "ther"))
 
260
    assert((SingletonOfLazyness.lastone).toString == "'lastone")
 
261
 
 
262
    object nested {
 
263
      lazy val sym1 = 'snested1
 
264
      lazy val sym2 = 'snested2
 
265
    }
 
266
 
 
267
    assert(nested.sym1 == 'snested1)
 
268
    assert(nested.sym2 == Symbol("snested" + "2"))
 
269
  }
 
270
 
 
271
}
 
272
 
 
273
 
 
274
 
 
275
 
 
276
 
 
277
 
 
278
 
 
279
 
 
280
 
 
281
 
 
282
 
 
283