Skip to content
Permalink
Browse files

Drop Scala 2.11

  • Loading branch information...
travisbrown committed Jun 19, 2019
1 parent 557c513 commit 880ba34551dad85cf99ff3254dbb1c8d6dd12237
@@ -2,7 +2,6 @@ dist: xenial
language: scala

scala:
- 2.11.12
- 2.13.0
- 2.12.8

@@ -26,14 +25,10 @@ script:
- sbt ++$TRAVIS_SCALA_VERSION clean coverage validateJVM benchmark/test;
- sbt ++$TRAVIS_SCALA_VERSION benchmark/test;
- 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
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
- if [[ "$TRAVIS_SCALA_VERSION" == 2.13.* ]];
then
@@ -3,7 +3,7 @@
[![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)
[![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]).

@@ -524,10 +524,6 @@ lazy val benchmark = circeModule("benchmark", mima = None)
scalacOptions ~= {
_.filterNot(Set("-Yno-predef"))
},
scalacOptions ++= (CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 11)) => Seq("-Xexperimental")
case _ => Nil
}),
libraryDependencies ++= Seq(
"org.scalatest" %% "scalatest" % scalaTestVersion % Test
)
@@ -52,7 +52,7 @@ val baz2: Decoder.Result[Double] =
cursor.downField("values").get[Double]("baz")
val secondQux: Decoder.Result[String] =
cursor.downField("values").downField("qux").downArray.right.as[String]
cursor.downField("values").downField("qux").downArray.as[String]
```

## Transforming data
@@ -7,7 +7,7 @@ section: "home"
[![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)
[![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
a JSON library for Scala (and [Scala.js][scala-js]).
@@ -1,6 +1,6 @@
## 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:

```scala
@@ -21,11 +21,11 @@ class GenericDerivationBenchmark {

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

@@ -38,7 +38,7 @@ class RefinedSuite extends CirceSuite {
val refinedList = refineV[Size[Greater[Nat._3]]](list)
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 {
@@ -84,7 +84,7 @@ object RefinedFieldsSuite {
lr <- Arbitrary.arbitrary[List[Int]]
} yield RefinedFields(
RefType[Refined].unsafeWrap(i),
RefType[Refined].unsafeWrap(sh + st),
RefType[Refined].unsafeWrap(s"$sh$st"),
RefType[Refined].unsafeWrap(l0 :: l1 :: l2 :: lr)
)
)
@@ -106,7 +106,7 @@ class RefinedFieldsSuite extends CirceSuite {
RefinedFields(
refineMV(3),
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
)
)

@@ -46,7 +46,7 @@ class ScodecSuite extends CirceSuite with Matchers with BitVectorMatchers {
trait BitVectorMatchers {
class FailFor(input: String) extends Matcher[Decoder[BitVector]] {
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")
}
}
@@ -55,12 +55,12 @@ trait BitVectorMatchers {

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

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

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

@@ -68,7 +68,6 @@ private[shapes] trait LowPriorityLabelledHListInstances extends HListInstances {
.fold[Decoder.Result[String]](
Left(DecodingFailure("Record", c.history))
)(Right(_))
.right
.flatMap(c.get[V](_)),
decodeT(c)
)((h, t) => field[K](h) :: t)
@@ -14,7 +14,7 @@ trait PrinterLaws[A] {
def encode: Encoder[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 {
@@ -127,7 +127,7 @@ class StdLibCodecSuite extends CirceSuite with ArrayFactoryInstance {
val maybeList = jsonArr.as[List[Int]]
assert(maybeList.isRight)

val list = maybeList.right.getOrElse(???)
val Right(list) = maybeList
assert(list.length == size)
assert(list.forall(_ == 1))
}
@@ -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) =>
val exception = new Exception("Not an Int")
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)
}
@@ -423,7 +423,7 @@ class DecoderSuite extends CirceSuite with LargeNumberDecoderTests with TableDri
val message = "Not positive!"

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))

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

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))

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

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 {
@@ -515,13 +515,13 @@ class DecoderSuite extends CirceSuite with LargeNumberDecoderTests with TableDri
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)

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 {
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 = {
@@ -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 {
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 {
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 {
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 {
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)
@@ -139,8 +139,8 @@ class JavaTimeCodecSuite extends CirceSuite {

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

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 {
val decodingResult = Decoder[LocalDateTime].apply(invalidJson.hcursor)

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 {
val decodingResult = Decoder[ZonedDateTime].apply(invalidJson.hcursor)

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 {
val decodingResult = Decoder[OffsetDateTime].apply(invalidJson.hcursor)

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 {
val decodingResult = Decoder[LocalDate].apply(invalidJson.hcursor)

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 {
val decodingResult = Decoder[LocalTime].apply(invalidJson.hcursor)

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 {
val decodingResult = Decoder[MonthDay].apply(invalidJson.hcursor)

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 {
val decodingResult = Decoder[OffsetTime].apply(invalidJson.hcursor)

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 {
val decodingResult = Decoder[Period].apply(invalidJson.hcursor)

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 {
val decodingResult = Decoder[Year].apply(invalidJson.hcursor)

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 {
val decodingResult = Decoder[YearMonth].apply(invalidJson.hcursor)

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 {
val decodingResult = Decoder[Duration].apply(invalidJson.hcursor)

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 {
val decodingResult = Decoder[ZoneOffset].apply(invalidJson.hcursor)

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.
You can’t perform that action at this time.