Skip to content

Commit 5bf9d2b

Browse files
Add tests
- t7296 & case-class-23 are moved out of pending - 1938 tests productElement > 23
1 parent 944e677 commit 5bf9d2b

6 files changed

+111
-0
lines changed
File renamed without changes.

tests/run/1938.scala

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
case class Large(
2+
e1: Int,
3+
e2: Int,
4+
e3: Int,
5+
e4: Int,
6+
e5: Int,
7+
e6: Int,
8+
e7: Int,
9+
e8: Int,
10+
e9: Int,
11+
e10: Int,
12+
e11: Int,
13+
e12: Int,
14+
e13: Int,
15+
e14: Int,
16+
e15: Int,
17+
e16: Int,
18+
e17: Int,
19+
e18: Int,
20+
e19: Int,
21+
e20: Int,
22+
e21: Int,
23+
e22: Int,
24+
e23: Int
25+
)
26+
27+
object Test {
28+
def main(args: Array[String]): Unit = {
29+
val l = Large(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23)
30+
31+
assert(l.productArity == 23)
32+
33+
assert(l.productElement(0) == 1)
34+
assert(l.productElement(1) == 2)
35+
assert(l.productElement(21) == 22)
36+
assert(l.productElement(22) == 23)
37+
38+
try {
39+
l.productElement(23)
40+
???
41+
} catch {
42+
case e: IndexOutOfBoundsException => assert(e.getMessage == "23")
43+
}
44+
}
45+
}
File renamed without changes.
File renamed without changes.

tests/run/double-pattern-type.scala

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
case class C1(i: String, s: Int) { def isEmpty = false; def get = ("EMPTY", -1) }
2+
case class C2(i: String, s: String) { def isEmpty = false; def get = (-1, -2, -3) }
3+
4+
object Test {
5+
def main(args: Array[String]): Unit = {
6+
// When both Product and name based patterns with same arity are available,
7+
// we follow scalac and silently use the Product one:
8+
9+
val c1 = C1("s", 0)
10+
c1 match {
11+
case C1(a, b) =>
12+
assert(a == "s")
13+
assert(b == 0)
14+
}
15+
16+
// When the size differ, both are patterns become usable:
17+
18+
val c2 = C2("a", "b")
19+
c2 match {
20+
case C2(a, b) =>
21+
assert(a == "a")
22+
assert(b == "b")
23+
}
24+
25+
c2 match {
26+
case C2(a, b, c) =>
27+
assert(a == -1)
28+
assert(b == -2)
29+
assert(c == -3)
30+
}
31+
32+
// Interestingly things also compile with a single pattern, in which case
33+
// the tuple returned by get is binded to `a`:
34+
35+
c2 match {
36+
case C2(a) =>
37+
assert(a == (-1, -2, -3))
38+
}
39+
}
40+
}

tests/run/zero-arity-case-class.scala

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
case class Foo()
2+
3+
object Test {
4+
def main(args: Array[String]): Unit = {
5+
assert(Foo.unapply(Foo()) == true)
6+
7+
// unapply generate by scalac are `_ != null`,
8+
// dotty returns true in all cases
9+
assert(Foo.unapply(null) == true)
10+
11+
Foo() match {
12+
case Foo() => ()
13+
case _ => ???
14+
}
15+
16+
Foo() match {
17+
case _: Foo => ()
18+
case _ => ???
19+
}
20+
21+
(Foo(): Any) match {
22+
case Foo() => ()
23+
case _ => ???
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)