diff options
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/scala/cc/spray/json/StandardFormatsSpec.scala | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/test/scala/cc/spray/json/StandardFormatsSpec.scala b/src/test/scala/cc/spray/json/StandardFormatsSpec.scala index 00561e0..7c454ac 100644 --- a/src/test/scala/cc/spray/json/StandardFormatsSpec.scala +++ b/src/test/scala/cc/spray/json/StandardFormatsSpec.scala @@ -1,6 +1,7 @@ package cc.spray.json import org.specs.Specification +import scala.Right class StandardFormatsSpec extends Specification with StandardFormats with BasicFormats { @@ -18,6 +19,24 @@ class StandardFormatsSpec extends Specification with StandardFormats with BasicF JsString("Hello").fromJson[Option[String]] mustEqual Some("Hello") } } + + "The eitherFormat" should { + val a: Either[Int, String] = Left(42) + val b: Either[Int, String] = Right("Hello") + + "convert the left side of an Either value to Json" in { + a.toJson mustEqual JsNumber(42) + } + "convert the right side of an Either value to Json" in { + b.toJson mustEqual JsString("Hello") + } + "convert the left side of an Either value from Json" in { + JsNumber(42).fromJson[Either[Int, String]] mustEqual Left(42) + } + "convert the right side of an Either value from Json" in { + JsString("Hello").fromJson[Either[Int, String]] mustEqual Right("Hello") + } + } "The tuple1Format" should { "convert (42) to a JsNumber" in { |