Skip to content

Commit

Permalink
add example test
Browse files Browse the repository at this point in the history
  • Loading branch information
lihaoyi committed Jul 5, 2024
1 parent 8995e63 commit 226fe34
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion upickle/test/src/upickle/example/ExampleTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ object Simple {
object Thing{
implicit val rw: RW[Thing] = macroRW
}
case class OptionThing(myFieldA: Option[Int] = None, myFieldB: Option[String] = None)
object OptionThing{
implicit val rw: RW[OptionThing] = macroRW
}
case class Big(i: Int, b: Boolean, str: String, c: Char, t: Thing)
object Big{
implicit val rw: RW[Big] = macroRW
Expand Down Expand Up @@ -239,8 +243,16 @@ object ExampleTests extends TestSuite {
| "myFieldB": ""
| }
|}""".stripMargin
}
}

test("caseClassOption"){
import upickle._
write(OptionThing(Some(1), Some("gg"))) ==> """{"myFieldA":1,"myFieldB":"gg"}"""
read[OptionThing]("""{"myFieldA":1,"myFieldB":"gg"}""") ==> OptionThing(Some(1), Some("gg"))

write(OptionThing(Some(1), None)) ==> """{"myFieldA":1}"""
read[OptionThing]("""{"myFieldA":1}""") ==> OptionThing(Some(1), None)
}

test("sealed"){
write(IntThing(1)) ==> """{"$type":"upickle.example.Sealed.IntThing","i":1}"""
Expand Down

0 comments on commit 226fe34

Please sign in to comment.