Skip to content

Commit

Permalink
Drop Scala 2.11
Browse files Browse the repository at this point in the history
  • Loading branch information
travisbrown committed Jul 2, 2019
1 parent 557c513 commit 880ba34
Show file tree
Hide file tree
Showing 15 changed files with 48 additions and 59 deletions.
9 changes: 2 additions & 7 deletions .travis.yml
Expand Up @@ -2,7 +2,6 @@ dist: xenial
language: scala language: scala


scala: scala:
- 2.11.12
- 2.13.0 - 2.13.0
- 2.12.8 - 2.12.8


Expand All @@ -26,14 +25,10 @@ script:
- sbt ++$TRAVIS_SCALA_VERSION clean coverage validateJVM benchmark/test; - sbt ++$TRAVIS_SCALA_VERSION clean coverage validateJVM benchmark/test;
- sbt ++$TRAVIS_SCALA_VERSION benchmark/test; - sbt ++$TRAVIS_SCALA_VERSION benchmark/test;
- if [[ "$TRAVIS_SCALA_VERSION" != 2.13.* ]]; - if [[ "$TRAVIS_SCALA_VERSION" != 2.13.* ]];
then
sbt ++$TRAVIS_SCALA_VERSION coverageReport && codecov;
else echo "Skipping code coverage reporting on 2.13";
fi
- if [[ "$TRAVIS_SCALA_VERSION" == 2.12.* ]];
then then
sbt ++$TRAVIS_SCALA_VERSION docs/makeMicrosite; sbt ++$TRAVIS_SCALA_VERSION docs/makeMicrosite;
else echo "Skipping docs on 2.11 and 2.13"; sbt ++$TRAVIS_SCALA_VERSION coverageReport && codecov;
else echo "Skipping code coverage reporting and docs on 2.13";
fi fi
- if [[ "$TRAVIS_SCALA_VERSION" == 2.13.* ]]; - if [[ "$TRAVIS_SCALA_VERSION" == 2.13.* ]];
then then
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -3,7 +3,7 @@
[![Build status](https://img.shields.io/travis/circe/circe/master.svg)](https://travis-ci.org/circe/circe) [![Build status](https://img.shields.io/travis/circe/circe/master.svg)](https://travis-ci.org/circe/circe)
[![Coverage status](https://img.shields.io/codecov/c/github/circe/circe/master.svg)](https://codecov.io/github/circe/circe) [![Coverage status](https://img.shields.io/codecov/c/github/circe/circe/master.svg)](https://codecov.io/github/circe/circe)
[![Gitter](https://img.shields.io/badge/gitter-join%20chat-green.svg)](https://gitter.im/circe/circe) [![Gitter](https://img.shields.io/badge/gitter-join%20chat-green.svg)](https://gitter.im/circe/circe)
[![Maven Central](https://img.shields.io/maven-central/v/io.circe/circe-core_2.12.svg)](https://maven-badges.herokuapp.com/maven-central/io.circe/circe-core_2.12) [![Maven Central](https://img.shields.io/maven-central/v/io.circe/circe-core_2.13.svg)](https://maven-badges.herokuapp.com/maven-central/io.circe/circe-core_2.13)


circe is a JSON library for Scala (and [Scala.js][scala-js]). circe is a JSON library for Scala (and [Scala.js][scala-js]).


Expand Down
4 changes: 0 additions & 4 deletions build.sbt
Expand Up @@ -524,10 +524,6 @@ lazy val benchmark = circeModule("benchmark", mima = None)
scalacOptions ~= { scalacOptions ~= {
_.filterNot(Set("-Yno-predef")) _.filterNot(Set("-Yno-predef"))
}, },
scalacOptions ++= (CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 11)) => Seq("-Xexperimental")
case _ => Nil
}),
libraryDependencies ++= Seq( libraryDependencies ++= Seq(
"org.scalatest" %% "scalatest" % scalaTestVersion % Test "org.scalatest" %% "scalatest" % scalaTestVersion % Test
) )
Expand Down
2 changes: 1 addition & 1 deletion docs/src/main/tut/cursors.md
Expand Up @@ -52,7 +52,7 @@ val baz2: Decoder.Result[Double] =
cursor.downField("values").get[Double]("baz") cursor.downField("values").get[Double]("baz")
val secondQux: Decoder.Result[String] = val secondQux: Decoder.Result[String] =
cursor.downField("values").downField("qux").downArray.right.as[String] cursor.downField("values").downField("qux").downArray.as[String]
``` ```


## Transforming data ## Transforming data
Expand Down
2 changes: 1 addition & 1 deletion docs/src/main/tut/index.md
Expand Up @@ -7,7 +7,7 @@ section: "home"
[![Build status](https://img.shields.io/travis/circe/circe/master.svg)](https://travis-ci.org/circe/circe) [![Build status](https://img.shields.io/travis/circe/circe/master.svg)](https://travis-ci.org/circe/circe)
[![Coverage status](https://img.shields.io/codecov/c/github/circe/circe/master.svg)](https://codecov.io/github/circe/circe) [![Coverage status](https://img.shields.io/codecov/c/github/circe/circe/master.svg)](https://codecov.io/github/circe/circe)
[![Gitter](https://img.shields.io/badge/gitter-join%20chat-green.svg)](https://gitter.im/circe/circe) [![Gitter](https://img.shields.io/badge/gitter-join%20chat-green.svg)](https://gitter.im/circe/circe)
[![Maven Central](https://img.shields.io/maven-central/v/io.circe/circe-core_2.11.svg)](https://maven-badges.herokuapp.com/maven-central/io.circe/circe-core_2.11) [![Maven Central](https://img.shields.io/maven-central/v/io.circe/circe-core_2.13.svg)](https://maven-badges.herokuapp.com/maven-central/io.circe/circe-core_2.13)


circe (pronounced SUR-see, or KEER-kee in classical Greek, or CHEER-chay in Ecclesiastical Latin) is circe (pronounced SUR-see, or KEER-kee in classical Greek, or CHEER-chay in Ecclesiastical Latin) is
a JSON library for Scala (and [Scala.js][scala-js]). a JSON library for Scala (and [Scala.js][scala-js]).
Expand Down
2 changes: 1 addition & 1 deletion docs/src/main/tut/quickstart.md
@@ -1,6 +1,6 @@
## Quick start ## Quick start


circe is published to [Maven Central][maven-central] and cross-built for Scala 2.11, 2.12, and 2.13.0-M5, circe is published to [Maven Central][maven-central] and cross-built for Scala 2.12 and 2.13,
so you can just add the following to your build: so you can just add the following to your build:


```scala ```scala
Expand Down
Expand Up @@ -21,11 +21,11 @@ class GenericDerivationBenchmark {


private[this] val nonDerivedDecoder: Decoder[Foo] = new Decoder[Foo] { private[this] val nonDerivedDecoder: Decoder[Foo] = new Decoder[Foo] {
def apply(c: HCursor): Decoder.Result[Foo] = for { def apply(c: HCursor): Decoder.Result[Foo] = for {
s <- c.get[String]("s").right s <- c.get[String]("s")
d <- c.get[Double]("d").right d <- c.get[Double]("d")
i <- c.get[Int]("i").right i <- c.get[Int]("i")
l <- c.get[Long]("l").right l <- c.get[Long]("l")
bs <- c.get[List[Boolean]]("bs").right bs <- c.get[List[Boolean]]("bs")
} yield Foo(s, d, i, l, bs) } yield Foo(s, d, i, l, bs)
} }


Expand Down
Expand Up @@ -38,7 +38,7 @@ class RefinedSuite extends CirceSuite {
val refinedList = refineV[Size[Greater[Nat._3]]](list) val refinedList = refineV[Size[Greater[Nat._3]]](list)
val expected: Either[String, Json] = Right(list.asJson) val expected: Either[String, Json] = Right(list.asJson)


assert(expected === refinedList.right.map(_.asJson)) assert(expected === refinedList.map(_.asJson))
} }


"A refined decoder" should "refuse to decode wrong values" in { "A refined decoder" should "refuse to decode wrong values" in {
Expand Down Expand Up @@ -84,7 +84,7 @@ object RefinedFieldsSuite {
lr <- Arbitrary.arbitrary[List[Int]] lr <- Arbitrary.arbitrary[List[Int]]
} yield RefinedFields( } yield RefinedFields(
RefType[Refined].unsafeWrap(i), RefType[Refined].unsafeWrap(i),
RefType[Refined].unsafeWrap(sh + st), RefType[Refined].unsafeWrap(s"$sh$st"),
RefType[Refined].unsafeWrap(l0 :: l1 :: l2 :: lr) RefType[Refined].unsafeWrap(l0 :: l1 :: l2 :: lr)
) )
) )
Expand All @@ -106,7 +106,7 @@ class RefinedFieldsSuite extends CirceSuite {
RefinedFields( RefinedFields(
refineMV(3), refineMV(3),
refineMV("ab"), refineMV("ab"),
refineV[Size[Greater[Nat._2]]](List(1, 2, 3, 4)).right.get refineV[Size[Greater[Nat._2]]](List(1, 2, 3, 4)).toOption.get
) )
) )


Expand Down
Expand Up @@ -46,7 +46,7 @@ class ScodecSuite extends CirceSuite with Matchers with BitVectorMatchers {
trait BitVectorMatchers { trait BitVectorMatchers {
class FailFor(input: String) extends Matcher[Decoder[BitVector]] { class FailFor(input: String) extends Matcher[Decoder[BitVector]] {
override def apply(decoder: Decoder[BitVector]): MatchResult = { override def apply(decoder: Decoder[BitVector]): MatchResult = {
val json = parse(input).right.get val Right(json) = parse(input)
MatchResult(decoder.decodeJson(json).isLeft, s"Has not failed for $input", s"Failed for $input") MatchResult(decoder.decodeJson(json).isLeft, s"Has not failed for $input", s"Failed for $input")
} }
} }
Expand All @@ -55,12 +55,12 @@ trait BitVectorMatchers {


class DecodeTo(input: String, expectedBitVector: BitVector) extends Matcher[Decoder[BitVector]] { class DecodeTo(input: String, expectedBitVector: BitVector) extends Matcher[Decoder[BitVector]] {
override def apply(decoder: Decoder[BitVector]): MatchResult = { override def apply(decoder: Decoder[BitVector]): MatchResult = {
val json = parse(input).right.get val Right(json) = parse(input)


val decoded = decoder.decodeJson(json) val decoded = decoder.decodeJson(json)
val expected = Right(expectedBitVector) val expected = Right(expectedBitVector)
MatchResult( MatchResult(
decoded.right.get == expectedBitVector, decoded == Right(expectedBitVector),
s"Decoded to [$decoded], expected: [$expected]", s"Decoded to [$decoded], expected: [$expected]",
s"Decoded to [$expected]" s"Decoded to [$expected]"
) )
Expand Down
Expand Up @@ -14,8 +14,8 @@ trait LabelledCoproductInstances extends LowPriorityLabelledCoproductInstances {
): Decoder[FieldType[K, V] :+: R] = new Decoder[FieldType[K, V] :+: R] { ): Decoder[FieldType[K, V] :+: R] = new Decoder[FieldType[K, V] :+: R] {
def apply(c: HCursor): Decoder.Result[FieldType[K, V] :+: R] = def apply(c: HCursor): Decoder.Result[FieldType[K, V] :+: R] =
Decoder.resultSemigroupK.combineK( Decoder.resultSemigroupK.combineK(
c.get[V](witK.value.name).right.map(v => Inl(field[K](v))), c.get[V](witK.value.name).map(v => Inl(field[K](v))),
decodeR(c).right.map(Inr(_)) decodeR(c).map(Inr(_))
) )
} }


Expand Down Expand Up @@ -52,9 +52,8 @@ private[shapes] trait LowPriorityLabelledCoproductInstances extends CoproductIns
.fold[Decoder.Result[String]]( .fold[Decoder.Result[String]](
Left(DecodingFailure("Record", c.history)) Left(DecodingFailure("Record", c.history))
)(Right(_)) )(Right(_))
.right .flatMap(c.get[V](_).map(v => Inl(field[K](v)))),
.flatMap(c.get[V](_).right.map(v => Inl(field[K](v)))), decodeR(c).map(Inr(_))
decodeR(c).right.map(Inr(_))
) )
} }


Expand Down
Expand Up @@ -68,7 +68,6 @@ private[shapes] trait LowPriorityLabelledHListInstances extends HListInstances {
.fold[Decoder.Result[String]]( .fold[Decoder.Result[String]](
Left(DecodingFailure("Record", c.history)) Left(DecodingFailure("Record", c.history))
)(Right(_)) )(Right(_))
.right
.flatMap(c.get[V](_)), .flatMap(c.get[V](_)),
decodeT(c) decodeT(c)
)((h, t) => field[K](h) :: t) )((h, t) => field[K](h) :: t)
Expand Down
Expand Up @@ -14,7 +14,7 @@ trait PrinterLaws[A] {
def encode: Encoder[A] def encode: Encoder[A]


def printerRoundTrip(printer: Printer, parser: Parser, a: A): IsEq[Option[A]] = def printerRoundTrip(printer: Printer, parser: Parser, a: A): IsEq[Option[A]] =
parser.decode(printer.pretty(encode(a)))(decode).right.toOption <-> Some(a) parser.decode(printer.pretty(encode(a)))(decode).toOption <-> Some(a)
} }


object PrinterLaws { object PrinterLaws {
Expand Down
Expand Up @@ -127,7 +127,7 @@ class StdLibCodecSuite extends CirceSuite with ArrayFactoryInstance {
val maybeList = jsonArr.as[List[Int]] val maybeList = jsonArr.as[List[Int]]
assert(maybeList.isRight) assert(maybeList.isRight)


val list = maybeList.right.getOrElse(???) val Right(list) = maybeList
assert(list.length == size) assert(list.length == size)
assert(list.forall(_ == 1)) assert(list.forall(_ == 1))
} }
Expand Down
20 changes: 10 additions & 10 deletions modules/tests/shared/src/test/scala/io/circe/DecoderSuite.scala
Expand Up @@ -210,7 +210,7 @@ class DecoderSuite extends CirceSuite with LargeNumberDecoderTests with TableDri
"instanceTry" should "provide instances that succeed or fail appropriately" in forAll { (json: Json) => "instanceTry" should "provide instances that succeed or fail appropriately" in forAll { (json: Json) =>
val exception = new Exception("Not an Int") val exception = new Exception("Not an Int")
val expected = json.hcursor.as[Int].leftMap(_ => DecodingFailure.fromThrowable(exception, Nil)) val expected = json.hcursor.as[Int].leftMap(_ => DecodingFailure.fromThrowable(exception, Nil))
val instance = Decoder.instanceTry(c => Try(c.as[Int].right.getOrElse(throw exception))) val instance = Decoder.instanceTry(c => Try(c.as[Int].getOrElse(throw exception)))


assert(instance.decodeJson(json) === expected) assert(instance.decodeJson(json) === expected)
} }
Expand Down Expand Up @@ -423,7 +423,7 @@ class DecoderSuite extends CirceSuite with LargeNumberDecoderTests with TableDri
val message = "Not positive!" val message = "Not positive!"


val decodePositiveInt: Decoder[Int] = val decodePositiveInt: Decoder[Int] =
Decoder[Int].validate(_.as[Int].right.exists(_ > 0), message) Decoder[Int].validate(_.as[Int].exists(_ > 0), message)


val expected = if (i > 0) Right(i) else Left(DecodingFailure(message, Nil)) val expected = if (i > 0) Right(i) else Left(DecodingFailure(message, Nil))


Expand All @@ -434,7 +434,7 @@ class DecoderSuite extends CirceSuite with LargeNumberDecoderTests with TableDri
val message = "Not positive!" val message = "Not positive!"


val decodePositiveInt: Decoder[Int] = val decodePositiveInt: Decoder[Int] =
Decoder[Int].validate(_.as[Int].right.exists(_ > 0), message) Decoder[Int].validate(_.as[Int].exists(_ > 0), message)


val expected = if (i > 0) Validated.valid(i) else Validated.invalidNel(DecodingFailure(message, Nil)) val expected = if (i > 0) Validated.valid(i) else Validated.invalidNel(DecodingFailure(message, Nil))


Expand Down Expand Up @@ -476,7 +476,7 @@ class DecoderSuite extends CirceSuite with LargeNumberDecoderTests with TableDri


val Right(fooJson) = parse("""{"x":42, "y": "meaning"}""") val Right(fooJson) = parse("""{"x":42, "y": "meaning"}""")


assert(decoder.decodeJson(fooJson).left.get.message === "x,y") assert(decoder.decodeJson(fooJson).swap.exists(_.message === "x,y"))
} }


it should "not fail when the passed errors function returns an empty list" in { it should "not fail when the passed errors function returns an empty list" in {
Expand Down Expand Up @@ -515,13 +515,13 @@ class DecoderSuite extends CirceSuite with LargeNumberDecoderTests with TableDri
it should "fail when there are leftover fields" in { it should "fail when there are leftover fields" in {
val json = Json.obj("a" -> "1".asJson, "b" -> "2".asJson, "c" -> "3".asJson, "d" -> "4".asJson) val json = Json.obj("a" -> "1".asJson, "b" -> "2".asJson, "c" -> "3".asJson, "d" -> "4".asJson)


assert(stateful.decodeJson(json).left.get.message === "Leftover keys: c, d") assert(stateful.decodeJson(json).swap.exists(_.message === "Leftover keys: c, d"))
} }


it should "fail normally when a field is missing" in { it should "fail normally when a field is missing" in {
val json = Json.obj("a" -> "1".asJson) val json = Json.obj("a" -> "1".asJson)


assert(stateful.decodeJson(json).left.get.message === "Attempt to decode value on failed cursor") assert(stateful.decodeJson(json).swap.exists(_.message === "Attempt to decode value on failed cursor"))
} }


private[this] val statefulOpt = { private[this] val statefulOpt = {
Expand Down Expand Up @@ -549,25 +549,25 @@ class DecoderSuite extends CirceSuite with LargeNumberDecoderTests with TableDri
it should "fail when there are leftover fields and an optional field is missing" in { it should "fail when there are leftover fields and an optional field is missing" in {
val json = Json.obj("b" -> "2".asJson, "c" -> "3".asJson, "d" -> "4".asJson) val json = Json.obj("b" -> "2".asJson, "c" -> "3".asJson, "d" -> "4".asJson)


assert(statefulOpt.decodeJson(json).left.get.message === "Leftover keys: c, d") assert(statefulOpt.decodeJson(json).swap.exists(_.message === "Leftover keys: c, d"))
} }


it should "fail when there are leftover fields and an optional field is present" in { it should "fail when there are leftover fields and an optional field is present" in {
val json = Json.obj("a" -> "1".asJson, "b" -> "2".asJson, "c" -> "3".asJson, "d" -> "4".asJson) val json = Json.obj("a" -> "1".asJson, "b" -> "2".asJson, "c" -> "3".asJson, "d" -> "4".asJson)


assert(statefulOpt.decodeJson(json).left.get.message === "Leftover keys: c, d") assert(statefulOpt.decodeJson(json).swap.exists(_.message === "Leftover keys: c, d"))
} }


it should "fail normally when a field is missing and an optional field is present" in { it should "fail normally when a field is missing and an optional field is present" in {
val json = Json.obj("a" -> "1".asJson) val json = Json.obj("a" -> "1".asJson)


assert(statefulOpt.decodeJson(json).left.get.message === "Attempt to decode value on failed cursor") assert(statefulOpt.decodeJson(json).swap.exists(_.message === "Attempt to decode value on failed cursor"))
} }


it should "fail normally when a field is missing and an optional field is missing" in { it should "fail normally when a field is missing and an optional field is missing" in {
val json = Json.obj() val json = Json.obj()


assert(statefulOpt.decodeJson(json).left.get.message === "Attempt to decode value on failed cursor") assert(statefulOpt.decodeJson(json).swap.exists(_.message === "Attempt to decode value on failed cursor"))
} }


checkLaws("Codec[WrappedOptionalField]", CodecTests[WrappedOptionalField].codec) checkLaws("Codec[WrappedOptionalField]", CodecTests[WrappedOptionalField].codec)
Expand Down
Expand Up @@ -139,8 +139,8 @@ class JavaTimeCodecSuite extends CirceSuite {


assert(decodingResult.isLeft) assert(decodingResult.isLeft)
// The middle part of the message depends on the type of zone. // The middle part of the message depends on the type of zone.
assert(decodingResult.left.get.message.contains("ZoneId (Invalid")) assert(decodingResult.swap.exists(_.message.contains("ZoneId (Invalid")))
assert(decodingResult.left.get.message.contains(s", invalid format: $s)")) assert(decodingResult.swap.exists(_.message.contains(s", invalid format: $s)")))
} }
) )
} }
Expand All @@ -149,90 +149,90 @@ class JavaTimeCodecSuite extends CirceSuite {
val decodingResult = Decoder[Instant].apply(invalidJson.hcursor) val decodingResult = Decoder[Instant].apply(invalidJson.hcursor)


assert(decodingResult.isLeft) assert(decodingResult.isLeft)
assert(decodingResult.left.get.message.contains(parseExceptionMessage)) assert(decodingResult.swap.exists(_.message.contains(parseExceptionMessage)))
} }


"Decoder[LocalDateTime]" should "fail on invalid values" in { "Decoder[LocalDateTime]" should "fail on invalid values" in {
val decodingResult = Decoder[LocalDateTime].apply(invalidJson.hcursor) val decodingResult = Decoder[LocalDateTime].apply(invalidJson.hcursor)


assert(decodingResult.isLeft) assert(decodingResult.isLeft)
assert(decodingResult.left.get.message.contains(parseExceptionMessage)) assert(decodingResult.swap.exists(_.message.contains(parseExceptionMessage)))
} }


"Decoder[ZonedDateTime]" should "fail on invalid values" in { "Decoder[ZonedDateTime]" should "fail on invalid values" in {
val decodingResult = Decoder[ZonedDateTime].apply(invalidJson.hcursor) val decodingResult = Decoder[ZonedDateTime].apply(invalidJson.hcursor)


assert(decodingResult.isLeft) assert(decodingResult.isLeft)
assert(decodingResult.left.get.message.contains(parseExceptionMessage)) assert(decodingResult.swap.exists(_.message.contains(parseExceptionMessage)))
} }


"Decoder[OffsetDateTime]" should "fail on invalid values" in { "Decoder[OffsetDateTime]" should "fail on invalid values" in {
val decodingResult = Decoder[OffsetDateTime].apply(invalidJson.hcursor) val decodingResult = Decoder[OffsetDateTime].apply(invalidJson.hcursor)


assert(decodingResult.isLeft) assert(decodingResult.isLeft)
assert(decodingResult.left.get.message.contains(parseExceptionMessage)) assert(decodingResult.swap.exists(_.message.contains(parseExceptionMessage)))
} }


"Decoder[LocalDate]" should "fail on invalid values" in { "Decoder[LocalDate]" should "fail on invalid values" in {
val decodingResult = Decoder[LocalDate].apply(invalidJson.hcursor) val decodingResult = Decoder[LocalDate].apply(invalidJson.hcursor)


assert(decodingResult.isLeft) assert(decodingResult.isLeft)
assert(decodingResult.left.get.message.contains(parseExceptionMessage)) assert(decodingResult.swap.exists(_.message.contains(parseExceptionMessage)))
} }


"Decoder[LocalTime]" should "fail on invalid values" in { "Decoder[LocalTime]" should "fail on invalid values" in {
val decodingResult = Decoder[LocalTime].apply(invalidJson.hcursor) val decodingResult = Decoder[LocalTime].apply(invalidJson.hcursor)


assert(decodingResult.isLeft) assert(decodingResult.isLeft)
assert(decodingResult.left.get.message.contains(parseExceptionMessage)) assert(decodingResult.swap.exists(_.message.contains(parseExceptionMessage)))
} }


"Decoder[MonthDay]" should "fail on invalid values" in { "Decoder[MonthDay]" should "fail on invalid values" in {
val decodingResult = Decoder[MonthDay].apply(invalidJson.hcursor) val decodingResult = Decoder[MonthDay].apply(invalidJson.hcursor)


assert(decodingResult.isLeft) assert(decodingResult.isLeft)
assert(decodingResult.left.get.message.contains(parseExceptionMessage)) assert(decodingResult.swap.exists(_.message.contains(parseExceptionMessage)))
} }


"Decoder[OffsetTime]" should "fail on invalid values" in { "Decoder[OffsetTime]" should "fail on invalid values" in {
val decodingResult = Decoder[OffsetTime].apply(invalidJson.hcursor) val decodingResult = Decoder[OffsetTime].apply(invalidJson.hcursor)


assert(decodingResult.isLeft) assert(decodingResult.isLeft)
assert(decodingResult.left.get.message.contains(parseExceptionMessage)) assert(decodingResult.swap.exists(_.message.contains(parseExceptionMessage)))
} }


"Decoder[Period]" should "fail on invalid values" in { "Decoder[Period]" should "fail on invalid values" in {
val decodingResult = Decoder[Period].apply(invalidJson.hcursor) val decodingResult = Decoder[Period].apply(invalidJson.hcursor)


assert(decodingResult.isLeft) assert(decodingResult.isLeft)
assert(decodingResult.left.get.message.contains(s"Text '$invalidText' cannot be parsed to a Period")) assert(decodingResult.swap.exists(_.message.contains(s"Text '$invalidText' cannot be parsed to a Period")))
} }


"Decoder[Year]" should "fail on invalid values" in { "Decoder[Year]" should "fail on invalid values" in {
val decodingResult = Decoder[Year].apply(invalidJson.hcursor) val decodingResult = Decoder[Year].apply(invalidJson.hcursor)


assert(decodingResult.isLeft) assert(decodingResult.isLeft)
assert(decodingResult.left.get.message.contains(parseExceptionMessage)) assert(decodingResult.swap.exists(_.message.contains(parseExceptionMessage)))
} }


"Decoder[YearMonth]" should "fail on invalid values" in { "Decoder[YearMonth]" should "fail on invalid values" in {
val decodingResult = Decoder[YearMonth].apply(invalidJson.hcursor) val decodingResult = Decoder[YearMonth].apply(invalidJson.hcursor)


assert(decodingResult.isLeft) assert(decodingResult.isLeft)
assert(decodingResult.left.get.message.contains(parseExceptionMessage)) assert(decodingResult.swap.exists(_.message.contains(parseExceptionMessage)))
} }


"Decoder[Duration]" should "fail on invalid values" in { "Decoder[Duration]" should "fail on invalid values" in {
val decodingResult = Decoder[Duration].apply(invalidJson.hcursor) val decodingResult = Decoder[Duration].apply(invalidJson.hcursor)


assert(decodingResult.isLeft) assert(decodingResult.isLeft)
assert(decodingResult.left.get.message.contains(s"Text '$invalidText' cannot be parsed to a Duration")) assert(decodingResult.swap.exists(_.message.contains(s"Text '$invalidText' cannot be parsed to a Duration")))
} }


"Decoder[ZoneOffset]" should "fail on invalid values" in { "Decoder[ZoneOffset]" should "fail on invalid values" in {
val decodingResult = Decoder[ZoneOffset].apply(invalidJson.hcursor) val decodingResult = Decoder[ZoneOffset].apply(invalidJson.hcursor)


assert(decodingResult.isLeft) assert(decodingResult.isLeft)
assert(decodingResult.left.get.message.contains("ZoneOffset (Invalid ID for ZoneOffset, ")) assert(decodingResult.swap.exists(_.message.contains("ZoneOffset (Invalid ID for ZoneOffset, ")))
} }
} }

0 comments on commit 880ba34

Please sign in to comment.