-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #75 from eed3si9n/wip/fix-llist-roundtrip
Fixes LListFormats
- Loading branch information
Showing
7 changed files
with
109 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
support/scalajson/src/test/scala/sjsonnew/support/scalajson/unsafe/LListFormatSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package sjsonnew | ||
package support.scalajson.unsafe | ||
|
||
import shaded.scalajson.ast.unsafe._ | ||
|
||
import org.scalatest.FlatSpec | ||
|
||
import BasicJsonProtocol._ | ||
|
||
final class LListFormatSpec extends FlatSpec { | ||
case class Foo(xs: Seq[String]) | ||
|
||
implicit val isoLList: IsoLList[Foo] = LList.isoCurried( | ||
(a: Foo) => "xs" -> a.xs :*: LNil | ||
) { case (_, xs) :*: LNil => Foo(xs) } | ||
|
||
val foo = Foo(Nil) | ||
val fooLList = "xs" -> List.empty[String] :*: LNil | ||
val fooJson = JObject(JField("$fields", JArray(JString("xs")))) | ||
val fooJsonStr = """{"$fields":["xs"]}""" | ||
|
||
it should "Foo -> LList" in assert((isoLList to foo) === fooLList) | ||
it should "Foo -> JSON" in assert(foo.toJson === fooJson) | ||
it should "Foo -> JSON string" in assert(foo.toJsonStr === fooJsonStr) | ||
it should "JSON string -> JSON" in assert(fooJsonStr.toJson === fooJson) | ||
it should "JSON string -> Foo" in assert(fooJsonStr.fromJsonStr[Foo] === foo) | ||
it should "round trip" in assertRoundTrip(foo) | ||
it should "round trip pretty" in assertPrettyRoundTrip(foo) | ||
|
||
private def assertRoundTrip[A: JsonWriter : JsonReader](x: A) = assert(x === x.jsonRoundTrip) | ||
private def assertPrettyRoundTrip[A: JsonWriter : JsonReader](x: A) = assert(x === x.jsonPrettyRoundTrip) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters