Skip to content

Commit 359acfd

Browse files
committed
Add tests
1 parent 1f835f5 commit 359acfd

7 files changed

+47
-0
lines changed

tests/neg/enums.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
enum List[+T] {
2+
case Cons(x: T, xs: List[T])
3+
case Nil // error: illegal enum value
4+
}
5+
6+
enum class X {
7+
case Y // error: case not allowed here
8+
}

tests/run/enum-Color.check

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Red: 0
2+
Green: 1
3+
Blue: 2

tests/run/enum-Color.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
enum Color {
2+
case Red
3+
case Green
4+
case Blue
5+
}
6+
7+
object Test {
8+
def main(args: Array[String]) =
9+
for (color <- Color.values) {
10+
println(s"$color: ${color.enumTag}")
11+
assert(Color.valueOf(color.enumTag) eq color)
12+
}
13+
}

tests/run/enum-List1.check

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Cons(1,Cons(2,Cons(3,Nil())))

tests/run/enum-List1.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
enum class List[T]
2+
object List {
3+
case Cons(x: T, xs: List[T])
4+
case Nil()
5+
}
6+
object Test {
7+
import List._
8+
val xs = Cons(1, Cons(2, Cons(3, Nil())))
9+
def main(args: Array[String]) = println(xs)
10+
}

tests/run/enum-List2.check

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Cons(1,Cons(2,Cons(3,Nil)))

tests/run/enum-List2.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
enum class List[+T]
2+
object List {
3+
case Cons(x: T, xs: List[T])
4+
case Nil extends List[Nothing]
5+
}
6+
object Test {
7+
import List._
8+
val xs = Cons(1, Cons(2, Cons(3, Nil)))
9+
def main(args: Array[String]) = println(xs)
10+
}
11+

0 commit comments

Comments
 (0)