From c2790577d64b039792618c92e6ab7cff7a7ed824 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 8 Feb 2017 21:23:47 +1100 Subject: Add tests --- tests/neg/enums.scala | 8 ++++++++ tests/run/enum-Color.check | 3 +++ tests/run/enum-Color.scala | 13 +++++++++++++ tests/run/enum-List1.check | 1 + tests/run/enum-List1.scala | 10 ++++++++++ tests/run/enum-List2.check | 1 + tests/run/enum-List2.scala | 11 +++++++++++ 7 files changed, 47 insertions(+) create mode 100644 tests/neg/enums.scala create mode 100644 tests/run/enum-Color.check create mode 100644 tests/run/enum-Color.scala create mode 100644 tests/run/enum-List1.check create mode 100644 tests/run/enum-List1.scala create mode 100644 tests/run/enum-List2.check create mode 100644 tests/run/enum-List2.scala (limited to 'tests') diff --git a/tests/neg/enums.scala b/tests/neg/enums.scala new file mode 100644 index 000000000..83311f37c --- /dev/null +++ b/tests/neg/enums.scala @@ -0,0 +1,8 @@ +enum List[+T] { + case Cons(x: T, xs: List[T]) + case Nil // error: illegal enum value +} + +enum class X { + case Y // error: case not allowed here +} diff --git a/tests/run/enum-Color.check b/tests/run/enum-Color.check new file mode 100644 index 000000000..865c47e49 --- /dev/null +++ b/tests/run/enum-Color.check @@ -0,0 +1,3 @@ +Red: 0 +Green: 1 +Blue: 2 diff --git a/tests/run/enum-Color.scala b/tests/run/enum-Color.scala new file mode 100644 index 000000000..24916abee --- /dev/null +++ b/tests/run/enum-Color.scala @@ -0,0 +1,13 @@ +enum Color { + case Red + case Green + case Blue +} + +object Test { + def main(args: Array[String]) = + for (color <- Color.values) { + println(s"$color: ${color.enumTag}") + assert(Color.valueOf(color.enumTag) eq color) + } +} diff --git a/tests/run/enum-List1.check b/tests/run/enum-List1.check new file mode 100644 index 000000000..3ed5061b4 --- /dev/null +++ b/tests/run/enum-List1.check @@ -0,0 +1 @@ +Cons(1,Cons(2,Cons(3,Nil()))) diff --git a/tests/run/enum-List1.scala b/tests/run/enum-List1.scala new file mode 100644 index 000000000..bb75bec4a --- /dev/null +++ b/tests/run/enum-List1.scala @@ -0,0 +1,10 @@ +enum class List[T] +object List { + case Cons(x: T, xs: List[T]) + case Nil() +} +object Test { + import List._ + val xs = Cons(1, Cons(2, Cons(3, Nil()))) + def main(args: Array[String]) = println(xs) +} diff --git a/tests/run/enum-List2.check b/tests/run/enum-List2.check new file mode 100644 index 000000000..1d4812de1 --- /dev/null +++ b/tests/run/enum-List2.check @@ -0,0 +1 @@ +Cons(1,Cons(2,Cons(3,Nil))) diff --git a/tests/run/enum-List2.scala b/tests/run/enum-List2.scala new file mode 100644 index 000000000..030de0f84 --- /dev/null +++ b/tests/run/enum-List2.scala @@ -0,0 +1,11 @@ +enum class List[+T] +object List { + case Cons(x: T, xs: List[T]) + case Nil extends List[Nothing] +} +object Test { + import List._ + val xs = Cons(1, Cons(2, Cons(3, Nil))) + def main(args: Array[String]) = println(xs) +} + -- cgit v1.2.3