Skip to content

Commit 0f97d1c

Browse files
OlivierBlanvillainallanrenucci
authored andcommitted
Fix ShowTests: Add Show[Some[T]]
1 parent d6bae54 commit 0f97d1c

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

library/src/dotty/Show.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ object Show extends LowPrioShow {
1616
* any `T`, we default to `T#toString`.
1717
*/
1818
implicit class ShowValue[V](val v: V) extends AnyVal {
19-
def show(implicit ev: Show[V] = defaultShow): String =
19+
def show(implicit ev: Show[V]): String =
2020
ev.show(v)
2121
}
2222

@@ -71,6 +71,10 @@ object Show extends LowPrioShow {
7171
}
7272
}
7373

74+
implicit def showSome[T](implicit st: Show[T]): Show[Some[T]] = new Show[Some[T]] {
75+
def show(ot: Some[T]): String = "Some("+ st.show(ot.get) + ")"
76+
}
77+
7478
implicit def showMap[K,V](implicit sk: Show[K], sv: Show[V]): Show[Map[K,V]] = new Show[Map[K,V]] {
7579
def show(m: Map[K, V]) =
7680
"Map(" + m.map { case (k, v) => sk.show(k) + " -> " + sv.show(v) } .mkString (", ") + ")"

library/test/dotty/ShowTests.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,13 @@ class ShowTests {
6262

6363
@Test def withoutShow = {
6464
case class Car(model: String, manufacturer: String, year: Int)
65-
6665
assertEquals("Car(Mustang,Ford,1967)", Car("Mustang", "Ford", 1967).show)
6766
assertEquals("Map()", Map[Nothing, Nothing]().show)
67+
assertEquals("List()", List().show)
6868
}
6969

7070
@Test def partialShow = {
7171
case object Foo
72-
7372
assertEquals("Map(Foo -> \"Hello\")", Map(Foo -> "Hello").show)
7473
}
7574
}

0 commit comments

Comments
 (0)