Skip to content

Commit 9973e8d

Browse files
Tests added for enum java compat API
1 parent 2bbab7f commit 9973e8d

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

tests/run/enums-java-compat.check

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: EARTH
2+
ordinal: 0
3+
toString: EARTH
4+
Values class: class [LA;
5+
MONDAY : 0
6+
TUESDAY : 1
7+
SATURDAY : 2
8+
Stuff : 3
9+
By-name value: MONDAY
10+
Correctly failed to retrieve illegal name, message: key not found: stuff
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class JEnum {
2+
def name: String = "Foo"
3+
def ordinal: Int = 10
4+
def action = "fofofo"
5+
}
6+
7+
enum A extends JEnum {
8+
case MONDAY, TUESDAY, SATURDAY
9+
case Stuff
10+
case Someday(x: String)
11+
def report = "Reported"
12+
}
13+
14+
trait Foo1
15+
trait Bar
16+
17+
enum B(val gravity: Double)(val isItGood: Boolean) extends Foo1 {
18+
case EARTH extends B(9.8)(true)
19+
case JUPITER extends B(100)(true)
20+
case MOON extends B(4.3)(true)
21+
case Foo extends B(10)(true) with Bar
22+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
object Test {
2+
def main(args: Array[String]): Unit = {
3+
val t1 = B.EARTH
4+
val t2 = B.JUPITER
5+
6+
println("name: " + t1.name)
7+
println("ordinal: " + t1.ordinal)
8+
println("toString: " + t1.toString)
9+
10+
val values: Array[A] = A.values
11+
println("Values class: " + values.getClass)
12+
values.foreach(v => println(v.name + " : " + v.ordinal))
13+
println("By-name value: " + A.valueOf("MONDAY"))
14+
try A.valueOf("stuff")
15+
catch { case e: IllegalArgumentException =>
16+
println("Correctly failed to retrieve illegal name, message: " + e.getMessage)
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)