aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2017-02-08 21:23:47 +1100
committerMartin Odersky <odersky@gmail.com>2017-04-04 13:28:44 +0200
commitc2790577d64b039792618c92e6ab7cff7a7ed824 (patch)
tree9b9c28e583b74ca010b193c9e5aaa529e1bdead9 /tests
parentcea243a4fc38dcc8831000d1066e10362df37576 (diff)
downloaddotty-c2790577d64b039792618c92e6ab7cff7a7ed824.tar.gz
dotty-c2790577d64b039792618c92e6ab7cff7a7ed824.tar.bz2
dotty-c2790577d64b039792618c92e6ab7cff7a7ed824.zip
Add tests
Diffstat (limited to 'tests')
-rw-r--r--tests/neg/enums.scala8
-rw-r--r--tests/run/enum-Color.check3
-rw-r--r--tests/run/enum-Color.scala13
-rw-r--r--tests/run/enum-List1.check1
-rw-r--r--tests/run/enum-List1.scala10
-rw-r--r--tests/run/enum-List2.check1
-rw-r--r--tests/run/enum-List2.scala11
7 files changed, 47 insertions, 0 deletions
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)
+}
+