diff --git a/build.sbt b/build.sbt index 9d5c3b5..60b4707 100644 --- a/build.sbt +++ b/build.sbt @@ -1,6 +1,6 @@ val jupyterScalaVersion = "0.3.0-M3" -val circeVersion = "0.4.1" +val circeVersion = "0.6.1" val plotlyVersion = "1.12.0" lazy val core = crossProject @@ -27,11 +27,11 @@ lazy val `circe-alt-generic` = crossProject .settings( name := "circe-alt-generic", libraryDependencies ++= Seq( - "io.circe" %%% "circe-core" % "0.4.1", - "io.circe" %%% "circe-parser" % "0.4.1", - "com.chuusai" %%% "shapeless" % "2.3.1", - "com.github.alexarchambault" %%% "scalacheck-shapeless_1.13" % "1.1.0-RC3" % "test", - "com.lihaoyi" %%% "utest" % "0.3.0" % "test" + "io.circe" %%% "circe-core" % circeVersion, + "io.circe" %%% "circe-parser" % circeVersion, + "com.chuusai" %%% "shapeless" % "2.3.2", + "com.github.alexarchambault" %%% "scalacheck-shapeless_1.13" % "1.1.4" % "test", + "com.lihaoyi" %%% "utest" % "0.4.4" % "test" ), testFrameworks += new TestFramework("utest.runner.Framework") ) @@ -58,7 +58,7 @@ lazy val render = crossProject .jsSettings( libraryDependencies ++= Seq( "io.circe" %%% "circe-scalajs" % circeVersion, - "org.scala-js" %%% "scalajs-dom" % "0.9.0" + "org.scala-js" %%% "scalajs-dom" % "0.9.1" ) ) @@ -75,7 +75,7 @@ lazy val demo = project test in Test := (), testOnly in Test := (), libraryDependencies ++= Seq( - "com.lihaoyi" %%% "scalatags" % "0.5.5" + "com.lihaoyi" %%% "scalatags" % "0.6.2" ), jsDependencies ++= Seq( ("org.webjars.bower" % "plotly.js" % plotlyVersion intransitive()) / "plotly.min.js" commonJSName "Plotly", @@ -173,7 +173,7 @@ lazy val tests = project name := "plotly-tests", libraryDependencies ++= Seq( "io.circe" %% "circe-literal" % circeVersion % "test", - "org.scalatest" %% "scalatest" % "3.0.0-M11" % "test", + "org.scalatest" %% "scalatest" % "3.0.1" % "test", "org.mozilla" % "rhino" % "1.7.7.1" % "test" ) ) diff --git a/circe-alt-generic/shared/src/main/scala/io/circe/altgeneric/derive/JsonProductCodec.scala b/circe-alt-generic/shared/src/main/scala/io/circe/altgeneric/derive/JsonProductCodec.scala index d01052a..07e38fc 100644 --- a/circe-alt-generic/shared/src/main/scala/io/circe/altgeneric/derive/JsonProductCodec.scala +++ b/circe-alt-generic/shared/src/main/scala/io/circe/altgeneric/derive/JsonProductCodec.scala @@ -1,7 +1,6 @@ package io.circe.altgeneric package derive -import cats.data.Xor import io.circe.{ ACursor, Decoder, HCursor, Json } abstract class JsonProductCodec { @@ -46,10 +45,10 @@ class JsonProductObjCodec extends JsonProductCodec { obj.mapObject((toJsonName(name) -> content) +: _) } - def decodeEmpty(cursor: HCursor): Decoder.Result[Unit] = Xor.right(()) + def decodeEmpty(cursor: HCursor): Decoder.Result[Unit] = Right(()) def decodeField[A](name: String, cursor: HCursor, decode: Decoder[A], default: Option[A]): Decoder.Result[(A, ACursor)] = { val c = cursor.downField(toJsonName(name)) - def result = c.as(decode).map((_, ACursor.ok(cursor))) + def result = c.as(decode).right.map((_, ACursor.ok(cursor))) default match { case None => result @@ -57,7 +56,7 @@ class JsonProductObjCodec extends JsonProductCodec { if (c.succeeded) result else - Xor.right((d, ACursor.ok(cursor))) + Right((d, ACursor.ok(cursor))) } } } diff --git a/circe-alt-generic/shared/src/main/scala/io/circe/altgeneric/derive/JsonSumCodec.scala b/circe-alt-generic/shared/src/main/scala/io/circe/altgeneric/derive/JsonSumCodec.scala index c5ae723..3485092 100644 --- a/circe-alt-generic/shared/src/main/scala/io/circe/altgeneric/derive/JsonSumCodec.scala +++ b/circe-alt-generic/shared/src/main/scala/io/circe/altgeneric/derive/JsonSumCodec.scala @@ -1,7 +1,6 @@ package io.circe.altgeneric package derive -import cats.data.Xor import io.circe._ abstract class JsonSumCodec { @@ -45,16 +44,16 @@ class JsonSumObjCodec extends JsonSumCodec { } def decodeEmpty(cursor: HCursor): Decoder.Result[Nothing] = - Xor.left(DecodingFailure( + Left(DecodingFailure( s"unrecognized type(s): ${cursor.fields.getOrElse(Nil).mkString(", ")}", cursor.history )) def decodeField[A](name: String, cursor: HCursor, decode: Decoder[A]): Decoder.Result[Either[ACursor, A]] = cursor.downField(toJsonName(name)).either match { - case Xor.Left(_) => - Xor.right(Left(ACursor.ok(cursor))) - case Xor.Right(content) => - decode(content).map(Right(_)) + case Left(_) => + Right(Left(ACursor.ok(cursor))) + case Right(content) => + decode(content).right.map(Right(_)) } } @@ -74,18 +73,21 @@ class JsonSumTypeFieldCodec extends JsonSumCodec { } def decodeEmpty(cursor: HCursor): Decoder.Result[Nothing] = - Xor.Left(DecodingFailure( + Left(DecodingFailure( cursor.downField(typeField).focus match { case None => "no type found" case Some(type0) => s"unrecognized type: $type0" }, cursor.history )) - def decodeField[A](name: String, cursor: HCursor, decode: Decoder[A]): Decoder.Result[Either[ACursor, A]] = - cursor.downField(typeField).as[String] match { - case Xor.Right(name0) if toTypeValue(name) == name0 => - decode(cursor).map(Right(_)) + def decodeField[A](name: String, cursor: HCursor, decode: Decoder[A]): Decoder.Result[Either[ACursor, A]] = { + val c = cursor.downField(typeField) + + c.as[String] match { + case Right(name0) if toTypeValue(name) == name0 => + c.delete.as(decode).right.map(Right(_)) case _ => - Xor.Right(Left(ACursor.ok(cursor))) + Right(Left(ACursor.ok(cursor))) } + } } diff --git a/circe-alt-generic/shared/src/main/scala/io/circe/altgeneric/derive/MkDecoder.scala b/circe-alt-generic/shared/src/main/scala/io/circe/altgeneric/derive/MkDecoder.scala index 2b6df17..90d6bb6 100644 --- a/circe-alt-generic/shared/src/main/scala/io/circe/altgeneric/derive/MkDecoder.scala +++ b/circe-alt-generic/shared/src/main/scala/io/circe/altgeneric/derive/MkDecoder.scala @@ -1,7 +1,6 @@ package io.circe.altgeneric package derive -import cats.data.Xor import shapeless._ import shapeless.labelled.{FieldType, field} import io.circe.Decoder @@ -85,6 +84,7 @@ object HListProductDecoder { Decoder.instance { c => productCodec .decodeEmpty(c) + .right .map(_ => HNil) } } @@ -100,10 +100,9 @@ object HListProductDecoder { Decoder.instance { c => for { - x <- productCodec.decodeField(key.value.name, c, headDecode.value, defaults.head) - (h, remaining) = x - t <- remaining.as(tailDecode0) - } yield field[K](h) :: t + x <- productCodec.decodeField(key.value.name, c, headDecode.value, defaults.head).right + t <- x._2.as(tailDecode0).right + } yield field[K](x._1) :: t } } } @@ -127,6 +126,7 @@ object CoproductSumDecoder { Decoder.instance { c => sumCodec .decodeEmpty(c) + .right .map(t => t: CNil) } } @@ -141,9 +141,9 @@ object CoproductSumDecoder { lazy val tailDecode0 = tailDecode(sumCodec) Decoder.instance { c => - sumCodec.decodeField(key.value.name, c, headDecode.value).flatMap { - case Left(tailCursor) => tailCursor.as(tailDecode0).map(Inr(_)) - case Right(h) => Xor.right(Inl(field[K](h))) + sumCodec.decodeField(key.value.name, c, headDecode.value).right.flatMap { + case Left(tailCursor) => tailCursor.as(tailDecode0).right.map(Inr(_)) + case Right(h) => Right(Inl(field[K](h))) } } } diff --git a/circe-alt-generic/shared/src/test/scala/io/circe/altgeneric/DefaultTests.scala b/circe-alt-generic/shared/src/test/scala/io/circe/altgeneric/DefaultTests.scala index f0bf0d6..7db4b16 100644 --- a/circe-alt-generic/shared/src/test/scala/io/circe/altgeneric/DefaultTests.scala +++ b/circe-alt-generic/shared/src/test/scala/io/circe/altgeneric/DefaultTests.scala @@ -1,6 +1,5 @@ package io.circe.altgeneric -import cats.data.Xor import io.circe.{ Decoder, Encoder, Json } import utest._ @@ -34,11 +33,11 @@ object DefaultTests extends TestSuite { assert(json1 == expectedJson1) val result0 = decoder.decodeJson(expectedJson0) - val expectedResult0 = Xor.right(value0) + val expectedResult0 = Right(value0) assert(result0 == expectedResult0) val result1 = decoder.decodeJson(expectedJson1) - val expectedResult1 = Xor.right(value1) + val expectedResult1 = Right(value1) assert(result1 == expectedResult1) } } diff --git a/circe-alt-generic/shared/src/test/scala/io/circe/altgeneric/PriorityTestsDefn.scala b/circe-alt-generic/shared/src/test/scala/io/circe/altgeneric/PriorityTestsDefn.scala index 3620c7d..2ac7bb8 100644 --- a/circe-alt-generic/shared/src/test/scala/io/circe/altgeneric/PriorityTestsDefn.scala +++ b/circe-alt-generic/shared/src/test/scala/io/circe/altgeneric/PriorityTestsDefn.scala @@ -10,7 +10,7 @@ object PriorityTestsDefn { object CC { implicit val decode: Decoder[CC] = new Decoder[CC] with Flag { def apply(c: HCursor) = - Decoder[(String, Int)].apply(c).map { case (s, i) => + Decoder[(String, Int)].apply(c).right.map { case (s, i) => CC(s, i) } } diff --git a/circe-alt-generic/shared/src/test/scala/io/circe/altgeneric/ShapelessTests.scala b/circe-alt-generic/shared/src/test/scala/io/circe/altgeneric/ShapelessTests.scala index 9a28ae1..8951bb5 100644 --- a/circe-alt-generic/shared/src/test/scala/io/circe/altgeneric/ShapelessTests.scala +++ b/circe-alt-generic/shared/src/test/scala/io/circe/altgeneric/ShapelessTests.scala @@ -4,7 +4,6 @@ import org.scalacheck.{ Arbitrary, Prop } import shapeless.test.illTyped import utest._ import Util._ -import cats.data.Xor import io.circe.{ Decoder, Encoder, Json, parser => Parse } import io.circe.syntax._ @@ -15,7 +14,7 @@ object ShapelessTests extends TestSuite { private def sameAfterBeforeSerialization[T: Arbitrary : Encoder : Decoder]: Unit = Prop.forAll { t: T => - toFromJson(t) == Xor.right(t) + toFromJson(t) == Right(t) }.validate import org.scalacheck.Shapeless._ @@ -55,10 +54,10 @@ object ShapelessTests extends TestSuite { } 'oiLoose - { - val json = Parse.parse("{}").toOption.get + val json = Parse.parse("{}").right.toOption.get // assert macro crashes if result is substituted by its value below val result = json.as[OI] - assert(result == Xor.right(OI(None))) + assert(result == Right(OI(None))) } 'base - { diff --git a/project/plugins.sbt b/project/plugins.sbt index 90b1ef7..dbc198d 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,4 +1,4 @@ -addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.0.0-M13") -addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.11") +addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.0.0-M14-9") +addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.13") addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.0.0") addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "0.1.9") diff --git a/render/shared/src/main/scala/plotly/Codecs.scala b/render/shared/src/main/scala/plotly/Codecs.scala index f34027c..b474a6e 100644 --- a/render/shared/src/main/scala/plotly/Codecs.scala +++ b/render/shared/src/main/scala/plotly/Codecs.scala @@ -2,8 +2,6 @@ package plotly import java.math.BigInteger -import cats.data.Xor - import io.circe.{ Error => _, _ } import io.circe.altgeneric._ import io.circe.altgeneric.derive._ @@ -42,7 +40,7 @@ object Codecs { underlying: Decoder[T] ): Decoder[W] = Decoder.instance { c => - c.as[T].map(t => + c.as[T].right.map(t => gen.from((t :: HNil).asInstanceOf[L]) // FIXME ) } @@ -69,20 +67,20 @@ object Codecs { def flagDecoder[T, F](type0: String, map: Map[String, F], build: Set[F] => T): Decoder[T] = Decoder.instance { c => - c.as[String].flatMap { s => + c.as[String].right.flatMap { s => val flags = if (s == "none") - Xor.right(Set.empty[F]) + Right(Set.empty[F]) else - s.split('+').foldLeft[Decoder.Result[Set[F]]](Xor.right(Set.empty[F])) { + s.split('+').foldLeft[Decoder.Result[Set[F]]](Right(Set.empty[F])) { case (acc, f) => for { - acc0 <- acc - f0 <- map.get(f).fold[Decoder.Result[F]](Xor.left(DecodingFailure(s"Unrecognized $type0: $f", c.history)))(Xor.right) + acc0 <- acc.right + f0 <- map.get(f).fold[Decoder.Result[F]](Left(DecodingFailure(s"Unrecognized $type0: $f", c.history)))(Right(_)).right } yield acc0 + f0 } - flags.map(build) + flags.right.map(build) } } @@ -114,10 +112,10 @@ object Codecs { val name = typeable.describe // TODO split in words c => - underlying(c).flatMap { s => + underlying(c).right.flatMap { s => map.get(s) match { - case None => Xor.left(DecodingFailure(s"Unrecognized $name: '$s'", c.history)) - case Some(m) => Xor.right(m) + case None => Left(DecodingFailure(s"Unrecognized $name: '$s'", c.history)) + case Some(m) => Right(m) } } } @@ -156,12 +154,12 @@ object Codecs { def decodeEmpty(cursor: HCursor): Decoder.Result[Nothing] = // FIXME Sometimes reports the wrong error (in case of two nested sum types) - Xor.left(DecodingFailure(s"unrecognized $name", cursor.history)) + Left(DecodingFailure(s"unrecognized $name", cursor.history)) def decodeField[A](name: String, cursor: HCursor, decode: Decoder[A]): Decoder.Result[Either[ACursor, A]] = - Xor.right { + Right { val o = decode(cursor) - o.toOption + o.right.toOption .toRight(ACursor.ok(cursor)) } } @@ -179,9 +177,9 @@ object Codecs { def decodeEmpty(cursor: HCursor): Decoder.Result[Unit] = if (cursor.focus == Json.obj()) - Xor.right(()) + Right(()) else - Xor.left(DecodingFailure( + Left(DecodingFailure( s"Found extra fields: ${cursor.fields.toSeq.flatten.mkString(", ")}", cursor.history )) @@ -189,7 +187,7 @@ object Codecs { def decodeField[A](name: String, cursor: HCursor, decode: Decoder[A], default: Option[A]): Decoder.Result[(A, ACursor)] = { val c = cursor.downField(toJsonName(name)) - def result = c.as(decode).map((_, if (c.succeeded) c.delete else cursor.acursor)) + def result = c.as(decode).right.map((_, if (c.succeeded) c.delete else cursor.acursor)) default match { case None => result @@ -197,7 +195,7 @@ object Codecs { if (c.succeeded) result else - Xor.right((d, ACursor.ok(cursor))) + Right((d, ACursor.ok(cursor))) } } } @@ -215,7 +213,7 @@ object Codecs { implicit val decodeRGBA: Decoder[Color.RGBA] = Decoder.instance { c => - c.as[String].flatMap { s => + c.as[String].right.flatMap { s => if (s.startsWith("rgba(") && s.endsWith(")")) s.stripPrefix("rgba(").stripSuffix(")").split(',').map(_.trim) match { case Array(rStr, gStr, bStr, alphaStr) => @@ -224,16 +222,16 @@ object Codecs { g <- Try(gStr.toInt).toOption b <- Try(bStr.toInt).toOption alpha <- Try(alphaStr.toDouble).toOption - } yield Xor.right(Color.RGBA(r, g, b, alpha)) + } yield Right(Color.RGBA(r, g, b, alpha)) res.getOrElse { - Xor.left(DecodingFailure(s"Unrecognized RGBA color: '$s'", c.history)) + Left(DecodingFailure(s"Unrecognized RGBA color: '$s'", c.history)) } case _ => - Xor.left(DecodingFailure(s"Unrecognized RGBA color: '$s'", c.history)) + Left(DecodingFailure(s"Unrecognized RGBA color: '$s'", c.history)) } else - Xor.left(DecodingFailure(s"Unrecognized RGBA color: '$s'", c.history)) + Left(DecodingFailure(s"Unrecognized RGBA color: '$s'", c.history)) } } @@ -249,10 +247,10 @@ object Codecs { .toMap c => - underlying(c).flatMap { s => + underlying(c).right.flatMap { s => map.get(s) match { - case None => Xor.left(DecodingFailure(s"Unrecognized color: '$s'", c.history)) - case Some(m) => Xor.right(m) + case None => Left(DecodingFailure(s"Unrecognized color: '$s'", c.history)) + case Some(m) => Right(m) } } } @@ -265,49 +263,50 @@ object Codecs { implicit val decodeRGB: Decoder[Color.RGB] = Decoder.instance { c => - val asString: Decoder.Result[Color.RGB] = c.as[String].flatMap { s => + val asString: Decoder.Result[Color.RGB] = c.as[String].right.flatMap { s => if (s.startsWith("rgb(") && s.endsWith(")")) s.stripPrefix("rgb(").stripSuffix(")").split(',').map(_.trim).map(s => Try(s.toInt).toOption) match { case Array(Some(r), Some(g), Some(b)) => - Xor.right(Color.RGB(r, g, b)) + Right(Color.RGB(r, g, b)) case _ => - Xor.left(DecodingFailure(s"Unrecognized RGB color: '$s'", c.history)) + Left(DecodingFailure(s"Unrecognized RGB color: '$s'", c.history)) } else - Xor.left(DecodingFailure(s"Unrecognized RGB color: '$s'", c.history)) + Left(DecodingFailure(s"Unrecognized RGB color: '$s'", c.history)) } - def asInt: Decoder.Result[Color.RGB] = c.as[Int].flatMap { + def asInt: Decoder.Result[Color.RGB] = c.as[Int].right.flatMap { case r if r >= 0 && r < 256 => - Xor.right(Color.RGB(r, 0, 0)) + Right(Color.RGB(r, 0, 0)) case _ => - Xor.left(DecodingFailure(s"Unrecognized RGB color: ${c.focus}", c.history)) + Left(DecodingFailure(s"Unrecognized RGB color: ${c.focus}", c.history)) } def parseHex(s: String, from: Int, until: Int) = new BigInteger(s.substring(from, until), 16).intValue() - def asHexa: Decoder.Result[Color.RGB] = c.as[String].flatMap { + def asHexa: Decoder.Result[Color.RGB] = c.as[String].right.flatMap { case HexaColor3(hex) => val r = parseHex(hex, 0, 1) val g = parseHex(hex, 1, 2) val b = parseHex(hex, 2, 3) - Xor.right(Color.RGB(r, g, b)) + Right(Color.RGB(r, g, b)) case HexaColor6(hex) => val r = parseHex(hex, 0, 2) val g = parseHex(hex, 2, 4) val b = parseHex(hex, 4, 6) - Xor.right(Color.RGB(r, g, b)) + Right(Color.RGB(r, g, b)) case other => - Xor.left(DecodingFailure(s"Unrecognized RGB color: $other", c.history)) + Left(DecodingFailure(s"Unrecognized RGB color: $other", c.history)) } asString + .right .toOption - .orElse(asInt.toOption) - .map(Xor.right) + .orElse(asInt.right.toOption) + .map(Right(_)) .getOrElse(asHexa) } @@ -338,16 +337,16 @@ object Codecs { implicit val decodeHSL: Decoder[Color.HSL] = Decoder.instance { c => - c.as[String].flatMap { s => + c.as[String].right.flatMap { s => if (s.startsWith("hsl(") && s.endsWith(")")) s.stripPrefix("hsl(").stripSuffix(")").split(',').map(_.trim).map(decodeNum) match { case Array(Some(h), Some(s), Some(l)) => - Xor.right(Color.HSL(h, s, l)) + Right(Color.HSL(h, s, l)) case _ => - Xor.left(DecodingFailure(s"Unrecognized HSL color: '$s'", c.history)) + Left(DecodingFailure(s"Unrecognized HSL color: '$s'", c.history)) } else - Xor.left(DecodingFailure(s"Unrecognized HSL color: '$s'", c.history)) + Left(DecodingFailure(s"Unrecognized HSL color: '$s'", c.history)) } } @@ -379,12 +378,12 @@ object Codecs { implicit val decodeLocalDateTime: Decoder[LocalDateTime] = Decoder.instance { c => - c.as[String].flatMap { s => + c.as[String].right.flatMap { s => LocalDateTime.parse(s) match { case Some(dt) => - Xor.right(dt) + Right(dt) case None => - Xor.left(DecodingFailure( + Left(DecodingFailure( s"Malformed date-time: '$s'", c.history )) @@ -406,19 +405,19 @@ object Codecs { implicit val decodeError: Decoder[Error] = Decoder.instance { c => c.downField("type").either match { - case Xor.Left(c0) => - Xor.left(DecodingFailure("No type found", c0.history)) - case Xor.Right(c1) => + case Left(c0) => + Left(DecodingFailure("No type found", c0.history)) + case Right(c1) => val c0 = c1.delete - c1.focus.as[String].flatMap { + c1.focus.as[String].right.flatMap { case "data" => - c0.as[Error.Data].map(e => e: Error) + c0.as[Error.Data].right.map(e => e: Error) case "percent" => - c0.as[Error.Percent].map(e => e: Error) + c0.as[Error.Percent].right.map(e => e: Error) case "constant" => - c0.as[Error.Constant].map(e => e: Error) + c0.as[Error.Constant].right.map(e => e: Error) case unrecognized => - Xor.left(DecodingFailure(s"Unrecognized type: $unrecognized", c.history)) + Left(DecodingFailure(s"Unrecognized type: $unrecognized", c.history)) } } } @@ -434,7 +433,7 @@ object Codecs { implicit lazy val decodeFont: Decoder[Font] = Decoder.instance { c => - wrappedFontDecoder(c) orElse derivedFontDecoder(c) + wrappedFontDecoder(c).right.toOption.fold(derivedFontDecoder(c))(Right(_)) } implicit val jsonCodecForTrace = JsonSumCodecFor[Trace]( @@ -445,12 +444,12 @@ object Codecs { val c = cursor.downField(typeField) c.as[String] match { - case Xor.Right(name0) if toTypeValue(name) == name0 => - c.delete.as(decode).map(Right(_)) - case Xor.Left(_) if name == "Scatter" => // assume scatter if no type found - cursor.as(decode).map(Right(_)) + case Right(name0) if toTypeValue(name) == name0 => + c.delete.as(decode).right.map(Right(_)) + case Left(_) if name == "Scatter" => // assume scatter if no type found + cursor.as(decode).right.map(Right(_)) case _ => - Xor.Right(Left(ACursor.ok(cursor))) + Right(Left(ACursor.ok(cursor))) } } } diff --git a/tests/src/test/scala/plotly/doc/DocumentationTests.scala b/tests/src/test/scala/plotly/doc/DocumentationTests.scala index e024579..0efdb86 100644 --- a/tests/src/test/scala/plotly/doc/DocumentationTests.scala +++ b/tests/src/test/scala/plotly/doc/DocumentationTests.scala @@ -6,8 +6,6 @@ import java.lang.{ Double => JDouble } import java.io.{ ByteArrayOutputStream, File, InputStream } import java.nio.file.Files -import cats.data.Xor - import io.circe.{ DecodingFailure, Json, parser => Parse } import io.circe.syntax._ @@ -54,16 +52,16 @@ object DocumentationTests { def resourceTrace(res: String): Trace = { val dataStr = load(res) - val result = Parse.parse(dataStr).flatMap(_.as[Trace]) - result.getOrElse { + val result = Parse.parse(dataStr).right.flatMap(_.as[Trace]) + result.right.getOrElse { throw new Exception(s"$res: $result") } } def resourceLayout(res: String): Layout = { val dataStr = load(res) - val result = Parse.parse(dataStr).flatMap(_.as[Layout]) - result.getOrElse { + val result = Parse.parse(dataStr).right.flatMap(_.as[Layout]) + result.right.getOrElse { throw new Exception(s"$res: $result") } } @@ -88,7 +86,7 @@ object DocumentationTests { def jsonRepr(obj: Object): Json = { val jsonStr = stringify(obj) - Parse.parse(jsonStr).leftMap { err => + Parse.parse(jsonStr).left.map { err => throw new Exception(s"Cannot parse JSON: $err\n$jsonStr") }.merge } @@ -167,7 +165,7 @@ object DocumentationTests { val decodeData0 = rawDataElems.map(json => json -> json.as[Trace]) val dataErrors = decodeData0.collect { - case (json, Xor.Left(DecodingFailure(err, h))) => + case (json, Left(DecodingFailure(err, h))) => (json, err, h) } @@ -179,17 +177,17 @@ object DocumentationTests { } val data = decodeData0.collect { - case (_, Xor.Right(data)) => data + case (_, Right(data)) => data } val decodeLayoutOpt = rawLayoutOpt.map(json => json -> json.as[Layout]) val layoutOpt = decodeLayoutOpt.map { - case (json, Xor.Left(DecodingFailure(err, h))) => + case (json, Left(DecodingFailure(err, h))) => Console.err.println(s"Decoding layout: $err ($h)\n${json.spaces2}\n") throw new Exception("Error decoding layout (see above messages)") - case (_, Xor.Right(layout)) => layout + case (_, Right(layout)) => layout } (data, layoutOpt) diff --git a/tests/src/test/scala/plotly/doc/SchemaTests.scala b/tests/src/test/scala/plotly/doc/SchemaTests.scala index 1a9c428..1cb24ee 100644 --- a/tests/src/test/scala/plotly/doc/SchemaTests.scala +++ b/tests/src/test/scala/plotly/doc/SchemaTests.scala @@ -6,8 +6,6 @@ import java.nio.file.Files import org.scalatest.{ FlatSpec, Matchers } -import cats.data.Xor - import io.circe.{ Decoder, Json, parser => Parser } import io.circe.altgeneric._ import io.circe.literal._ @@ -41,14 +39,14 @@ object SchemaTests { implicit val decode: Decoder[Attribute] = Decoder.instance { c => - val constantString = c.as[String].map[Attribute](ConstantString(_)) - def flag = c.as[Flag].map[Attribute](x => x) - def enumerated = c.as[Enumerated].map[Attribute](x => x) - def other = Xor.right(Other(c.focus)) - - constantString.toOption.map(Xor.right) - .orElse(flag.toOption.map(Xor.right)) - .orElse(enumerated.toOption.map(Xor.right)) + val constantString = c.as[String].right.map[Attribute](ConstantString(_)) + def flag = c.as[Flag].right.map[Attribute](x => x) + def enumerated = c.as[Enumerated].right.map[Attribute](x => x) + def other = Right(Other(c.focus)) + + constantString.right.toOption.map(Right(_)) + .orElse(flag.right.toOption.map(Right(_))) + .orElse(enumerated.right.toOption.map(Right(_))) .getOrElse(other) } } @@ -93,16 +91,16 @@ object SchemaTests { val schemaContent = new String(Files.readAllBytes(schemaFile.toPath), "UTF-8") val schemaJson = Parser.parse(schemaContent) match { - case Xor.Left(error) => + case Left(error) => throw new Exception(s"Cannot parse schema: $error") - case Xor.Right(json) => json + case Right(json) => json } schemaJson.as[SchemaFile] match { - case Xor.Left(error) => + case Left(error) => println(schemaJson.asObject.map(_.fields).getOrElse(Nil).mkString("\n")) throw new Exception(s"Cannot decode schema: $error") - case Xor.Right(schemaFile) => + case Right(schemaFile) => schemaFile.schema } } diff --git a/version.sbt b/version.sbt index 1be9a63..03a8b07 100644 --- a/version.sbt +++ b/version.sbt @@ -1 +1 @@ -version in ThisBuild := "0.1.1-SNAPSHOT" +version in ThisBuild := "0.2.0-SNAPSHOT"