Skip to content

Commit 62abe60

Browse files
committed
add test for ordinal and fromProduct
1 parent 5006b3e commit 62abe60

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

tests/run/i10997.scala

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
class ClassWrapper {
2+
3+
sealed trait Parent
4+
case class Foo(x: Int, y: Int, s: String) extends Parent
5+
case class Bar(x: Int, y: Int) extends Parent
6+
case object Qux extends Parent
7+
8+
def testcase(): Unit =
9+
10+
val mirrorParent = summon[deriving.Mirror.Of[Parent]]
11+
val mirrorFoo = summon[deriving.Mirror.Of[Foo]]
12+
val mirrorBar = summon[deriving.Mirror.Of[Bar]]
13+
val mirrorQux = summon[deriving.Mirror.Of[Qux.type]]
14+
15+
val fooShapedTuple: (Int, Int, String) = (23, 47, "ok")
16+
val barShapedTuple: (Int, Int) = (57, 71)
17+
val quxShapedTuple: EmptyTuple = EmptyTuple
18+
19+
val foo: Foo = mirrorFoo.fromProduct(fooShapedTuple)
20+
val bar: Bar = mirrorBar.fromProduct(barShapedTuple)
21+
val qux: Qux.type = mirrorQux.fromProduct(quxShapedTuple)
22+
23+
assert(foo == Foo(23, 47, "ok"))
24+
assert(bar == Bar(57, 71))
25+
assert(qux == Qux)
26+
27+
val fooOrd = mirrorParent.ordinal(foo)
28+
val barOrd = mirrorParent.ordinal(bar)
29+
val quxOrd = mirrorParent.ordinal(qux)
30+
31+
assert(fooOrd == 0)
32+
assert(barOrd == 1)
33+
assert(quxOrd == 2)
34+
}
35+
36+
@main def Test =
37+
ClassWrapper().testcase()

0 commit comments

Comments
 (0)