Skip to content

Commit aecb9c3

Browse files
committed
Add snapshot test with various examples from scala spec
1 parent 4bde54b commit aecb9c3

File tree

4 files changed

+19380
-23
lines changed

4 files changed

+19380
-23
lines changed

tests/sample.test.scala

Lines changed: 0 additions & 23 deletions
This file was deleted.

tests/snap/scala_spec.test.scala

Lines changed: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
package org.scala.syntax
2+
package test
3+
4+
5+
class TreeMap[A <: Comparable[A], B] { }
6+
class List[A] { }
7+
class I extends Comparable[I] {}
8+
9+
class F[M[_], X] { }
10+
class S[K <: String] {}
11+
class G[M[ Z <: I ], I] { }
12+
13+
case class Bird (val name: String @suspendable) extends Object {
14+
def fly(height: Int @suspendable) = ???
15+
def walk[T1 : T2](_distance: Int, empty_? : Int, `yield`: String, αρετη: Boolean)(implicit fa: Functor[T1]) = ???
16+
def c (x: Int) (y: String, z: String): String = ???
17+
def union[A <: Comparable[A]] (x: Set[A], xs: Set[A]): Set[A]
18+
}
19+
20+
trait Iterable[+X] {
21+
def flatMap[newType[+X] <: Iterable[X], S](f: X => newType[S]): newType[S]
22+
}
23+
24+
package org.scala {
25+
class List[+T]
26+
class Set[-T]
27+
}
28+
29+
class A[+T] {}
30+
class B extends A[B]
31+
class C extends A[C]
32+
33+
34+
35+
abstract class AbstractClass
36+
sealed trait Sealed
37+
38+
object Types {
39+
val x : String @suspendable = ""
40+
41+
def infix() : T1 \/ T2 = ???
42+
43+
type Z1 = Ref[T] forSome { type T <: java.lang.Number }
44+
type Z2 = Ref[x.T] forSome { val x: Outer }
45+
type Z3 = Ref[x_type # T] forSome { type x_type <: Outer with Singleton }
46+
47+
def complexBounds[A, B >: A, C >: A <: B]()
48+
def complexBounds2[M[X <: Bound[X]], Bound[_]]
49+
def complexBounds3[@specialized T, U]()
50+
51+
def compare[T](a: T = 0)(b: T = a) = (a == b)
52+
def f(a: Int = 0)(b: Int = a + 1) = b
53+
54+
def whileLoop (cond: => Boolean) (stat: => Unit): Unit
55+
56+
def sum(args: Int*) = {
57+
var result = 0
58+
for (arg <- args) result += arg
59+
result
60+
}
61+
62+
def write(str: String) { System.out.println(str) }
63+
def write(str: String): Unit = { System.out.println(str) }
64+
65+
66+
67+
type Pair[+A, +B] = Tuple2[A, B]
68+
object Pair {
69+
{ import M.{one, z => zero, _}; add(zero, one) }
70+
def apply[A, B](x: A, y: B) = Tuple2(x, y)
71+
def unapply[A, B](x: Tuple2[A, B]): Option[Tuple2[A, B]] = Some(x)
72+
}
73+
}
74+
75+
object ValueDefinitions {
76+
val pi = 3.1415
77+
val pi: Double = 3.1415 // equivalent to first definition
78+
val Some(x) = f() // a pattern definition
79+
val x :: xs = mylist // an infix pattern definition
80+
}
81+
82+
class Iter extends StringIterator with RichIterator { }
83+
trait A extends Root { type T <: A }
84+
85+
class Modifiers {
86+
final val x = e
87+
override def f()
88+
private val y = ""
89+
abstract override def g()
90+
private lazy final val h = 3
91+
}
92+
93+
object m {
94+
abstract sealed class C (x: Int) {
95+
def nextC = new C(x + 1) {}
96+
}
97+
val empty = new C(0) {}
98+
}
99+
100+
class LinkedList[A]() { self: List with Seq =>
101+
var head = ???
102+
var tail = null
103+
def isEmpty = tail != null
104+
def this(head: A) = { this(); this.head = head }
105+
def this(head: A, tail: List[A]) = { this(head); this.tail = tail }
106+
}
107+
108+
case class Lambda(x: String, e: Expr) extends Expr
109+
110+
trait Comparable[T <: Comparable[T]] { self: T =>
111+
def < (that: T): Boolean
112+
def <=(that: T): Boolean = this < that || this == that
113+
def > (that: T): Boolean = that < this
114+
def >=(that: T): Boolean = that <= this
115+
}
116+
117+
class A extends Root { override def x = "A" ; def superA = super.x }
118+
119+
object Appl {
120+
def sum(xs: Int*) = (0 /: xs) ((x, y) => x + y)
121+
sum(List(1, 2, 3, 4): _*)
122+
123+
val x : S = new Z
124+
val y : S = new Z {
125+
val x = 5
126+
}
127+
128+
def matmul(xss: Array[Array[Double]], yss: Array[Array[Double]]) = {
129+
val zss: Array[Array[Double]] = new Array(xss.length, yss(0).length)
130+
var i = 0
131+
while (i < xss.length) {
132+
var j = 0
133+
while (j < yss(0).length) {
134+
var acc = 0.0
135+
var k = 0
136+
while (k < yss.length) {
137+
acc = acc + xss(i)(k) * yss(k)(j)
138+
k += 1
139+
}
140+
zss(i)(j) = acc
141+
j += 1
142+
}
143+
i += 1
144+
}
145+
zss
146+
}
147+
148+
def whileLoop(cond: => Boolean)(body: => Unit): Unit =
149+
if (cond) { body ; whileLoop(cond)(body) } else {}
150+
151+
do {x += 2} while (x < 100)
152+
153+
for { i <- 1 until n
154+
j <- 1 until i
155+
if isPrime(i+j)
156+
} yield (i, j)
157+
158+
(1 until n)
159+
.flatMap {
160+
case i => (1 until i)
161+
.withFilter { j => isPrime(i+j) }
162+
.map { case j => (i, j) } }
163+
164+
try {
165+
throw ex;
166+
} catch {
167+
case NonFatal(e) => throw e;
168+
case other => throw other
169+
}
170+
}
171+
172+
object Inline {
173+
val summ = (x: Int,y: Int) => x + y
174+
}
175+
176+
object Monoids {
177+
implicit object stringMonoid extends Monoid[String] {
178+
def add(x: String, y: String): String = x.concat(y)
179+
def unit: String = ""
180+
}
181+
}
182+
183+
object A1 {
184+
def sum[A](xs: List[A])(implicit m: Monoid[A]): A =
185+
if (xs.isEmpty) m.unit
186+
else m.add(xs.head, sum(xs.tail))
187+
188+
implicit def list2ordered[A](x: List[A])
189+
(implicit elem2ordered: A => Ordered[A]): Ordered[List[A]]
190+
}
191+
192+
object PatternMatching {
193+
def f(x: Int, y: Int) = x match {
194+
case `y` =>
195+
case s @ Seq(_, _, _) =>
196+
case Seq(first, tail @ _*) =>
197+
case first +: tail =>
198+
case 3 | 5 | 6 =>
199+
case y: Number => y.n
200+
case Lit(n) => n
201+
case IsZero(u) => eval(u) == 0
202+
case _ => 15
203+
}
204+
205+
}
206+
207+
package p1 {
208+
package p2 {
209+
object Kitten
210+
}
211+
}
212+
213+
package a.b {
214+
class A {
215+
val x = new _root_.b.B
216+
}
217+
}
218+
219+
object HelloWorld {
220+
def main(args: Array[String]) { println("Hello World") }
221+
}
222+
223+
object HelloWorld extends App {
224+
println("Hello World")
225+
}
226+
227+
@SerialVersionUID(12345)
228+
object Annotations {
229+
@deprecated("Use D", "1.0") class C { }
230+
@transient @volatile var m: Int
231+
232+
def f(x: Option[Int]) = (x: @unchecked) match {
233+
case Some(y) => y
234+
}
235+
236+
trait Function0[@specialized(Unit, Int, Double) T] {
237+
def apply: T
238+
}
239+
240+
@UserDefinedUpperCase def x
241+
@userDefinedLowerCase def y
242+
}

0 commit comments

Comments
 (0)