Skip to content

Commit

Permalink
FromFromInput (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
russellremple authored May 15, 2021
1 parent c6aff3d commit 995efc9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.rallyhealth.weepickle.v1

import com.rallyhealth.weejson.v1.jackson.{FromJson, ToJson}
import com.rallyhealth.weepickle.v1.WeePickle.{FromScala, ToScala}
import com.rallyhealth.weepickle.v1.core.FromInput
import com.rallyhealth.weepickle.v1.implicits.dropDefault
import utest._

Expand Down Expand Up @@ -111,3 +112,27 @@ object OptionTopDropDefaultTests extends TestSuite {
}
}

// Exercises com.rallyhealth.weepickle.v1.LowPriorityImplicits.FromFromInput
object FromInputStringTests extends TestSuite {

case class A(d: String)
implicit val pickler = WeePickle.macroFromTo[A]

override val tests: Tests = Tests {
test("write default FromInput")(
{
val fromInput: FromInput = FromScala(A(null))
FromScala(fromInput).transform(ToJson.string)
} ==> """{"d":null}""")
test("write non-default FromInput")(
{
val fromInput: FromInput = FromScala(A("omg"))
FromScala(fromInput).transform(ToJson.string)
} ==> """{"d":"omg"}""")
test("write null FromInput")(
{
val fromInput: FromInput = FromScala(A(null))
FromScala(fromInput).transform(ToJson.string)
} ==> """{"d":null}""")
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package com.rallyhealth.weepickle.v1

import com.rallyhealth.weepickle.v1.core.{FromInput, Visitor}

import java.time.ZonedDateTime
import java.util.concurrent.ConcurrentHashMap

abstract class LowPriorityImplicits
extends AttributeTagged {

implicit val FromFromInput = new From[FromInput] {
override def transform0[Out](in: FromInput, out: Visitor[_, Out]): Out = in.transform(out)
}

implicit val FromZonedDateTime: From[ZonedDateTime] = FromString.comap[ZonedDateTime](_.toString)
implicit val ToZonedDateTime: To[ZonedDateTime] = new MapStringTo(s => ZonedDateTime.parse(s.toString))

Expand Down

0 comments on commit 995efc9

Please sign in to comment.