From cbe720d97300035fcb66bb3e45c364293455401c Mon Sep 17 00:00:00 2001 From: Lucas Satabin Date: Thu, 9 May 2019 20:05:28 +0200 Subject: [PATCH] Add support for scala 2.13.0 Closes #96 --- .travis.yml | 2 +- README.markdown | 6 +- build.sbt | 33 ++++++----- .../scala/diffson/circe/TestProtocol.scala | 4 +- .../scala/diffson/jsonpointer/package.scala | 4 +- .../src/main/scala/diffson/lcs/Patience.scala | 5 +- core/src/test/scala/diffson/TestLcs.scala | 3 +- .../scala/diffson/TestPatienceBigArray.scala | 3 +- project/plugins.sbt | 6 +- .../src/main/scala/diffson/TestJsonDiff.scala | 3 +- .../scala/diffson/TestJsonMergeDiff.scala | 3 +- .../scala/diffson/TestJsonMergePatch.scala | 3 +- .../main/scala/diffson/TestJsonPatch.scala | 55 ++++++++++--------- .../main/scala/diffson/TestJsonPointer.scala | 3 +- .../scala/diffson/TestSerialization.scala | 3 +- .../main/scala/diffson/TestSimpleDiff.scala | 3 +- 16 files changed, 77 insertions(+), 62 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4b9b9d3..9996d43 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,7 +16,7 @@ script: scala: - 2.11.12 - 2.12.8 -# - 2.13.0-M5 + - 2.13.0 before_install: - pip install --user codecov diff --git a/README.markdown b/README.markdown index e8a6f8c..b498750 100644 --- a/README.markdown +++ b/README.markdown @@ -1,4 +1,4 @@ -Gnieh Diffson [![Build Status](https://travis-ci.org/gnieh/diffson.png)](https://travis-ci.org/gnieh/diffson) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/9892e2c968974ecb951d21969adbadaa)](https://www.codacy.com/app/satabin/diffson?utm_source=github.com&utm_medium=referral&utm_content=gnieh/diffson&utm_campaign=Badge_Grade) [![Code Coverage](https://codecov.io/github/gnieh/diffson/coverage.svg?branch=master)](https://codecov.io/github/gnieh/diffson?branch=master) [![Maven Central](https://img.shields.io/maven-central/v/org.gnieh/diffson-core_2.11.svg)](https://maven-badges.herokuapp.com/maven-central/org.gnieh/diffson-core_2.11) [![Scaladoc](https://javadoc.io/badge/org.gnieh/diffson-core_2.12.svg)](https://javadoc.io/doc/org.gnieh/diffson-core_2.12) +Gnieh Diffson [![Build Status](https://travis-ci.org/gnieh/diffson.png)](https://travis-ci.org/gnieh/diffson) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/9892e2c968974ecb951d21969adbadaa)](https://www.codacy.com/app/satabin/diffson?utm_source=github.com&utm_medium=referral&utm_content=gnieh/diffson&utm_campaign=Badge_Grade) [![Code Coverage](https://codecov.io/github/gnieh/diffson/coverage.svg?branch=master)](https://codecov.io/github/gnieh/diffson?branch=master) [![Maven Central](https://img.shields.io/maven-central/v/org.gnieh/diffson-core_2.12.svg)](https://maven-badges.herokuapp.com/maven-central/org.gnieh/diffson-core_2.12) [![Scaladoc](https://javadoc.io/badge/org.gnieh/diffson-core_2.12.svg)](https://javadoc.io/doc/org.gnieh/diffson-core_2.12) ============= [![Join the chat at https://gitter.im/gnieh/diffson](https://badges.gitter.im/gnieh/diffson.svg)](https://gitter.im/gnieh/diffson?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) @@ -37,9 +37,9 @@ where `jsonLib` is either: - `play-json` - `circe` -These versions are built for Scala 2.11 and 2.12. +These versions are built for Scala 2.12 and 2.13. -Scala.JS is also supported for both Scala 2.11 and 2.12. To use it, add this dependency to your build file: +Scala.JS is also supported for both Scala 2.12 and 2.13. To use it, add this dependency to your build file: ```scala libraryDependencies += "org.gnieh" %%% f"diffson-$jsonLib" % "4.0.0-M3" ``` diff --git a/build.sbt b/build.sbt index ad69d75..d89b029 100644 --- a/build.sbt +++ b/build.sbt @@ -1,13 +1,12 @@ import scalariform.formatter.preferences._ import sbtcrossproject.CrossPlugin.autoImport.{crossProject, CrossType} -val scala211 = "2.11.12" val scala212 = "2.12.8" -val scala213 = "2.13.0-M5" +val scala213 = "2.13.0" lazy val commonSettings = Seq( organization := "org.gnieh", - scalaVersion := scala212, + scalaVersion := scala213, version := "4.0.0-M3", description := "Json diff/patch library", licenses += ("The Apache Software License, Version 2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0.txt")), @@ -26,10 +25,10 @@ lazy val commonSettings = Seq( compilerPlugin("org.scalamacros" % "paradise" % "2.1.1" cross CrossVersion.full) ) case _ => - // if scala 2.13.0-M4 or later, macro annotations merged into scala-reflect + // if scala 2.13.0 or later, macro annotations merged into scala-reflect Nil }), - addCompilerPlugin("org.spire-math" % "kind-projector" % "0.9.10" cross CrossVersion.binary), + addCompilerPlugin("org.typelevel" % "kind-projector" % "0.10.3" cross CrossVersion.binary), scalariformAutoformat := true, scalariformPreferences := { scalariformPreferences.value @@ -63,10 +62,11 @@ lazy val core = crossProject(JSPlatform, JVMPlatform) .settings(commonSettings: _*) .settings( name := "diffson-core", - crossScalaVersions := Seq(scala211, scala212/*, scala213*/), + crossScalaVersions := Seq(scala212, scala213), libraryDependencies ++= Seq( - "org.typelevel" %%% "cats-core" % "1.6.0", - "io.estatico" %%% "newtype" % "0.4.2", + "org.scala-lang.modules" %%% "scala-collection-compat" % "2.1.1", + "org.typelevel" %%% "cats-core" % "2.0.0-M4", + "io.estatico" %%% "newtype" % "0.4.3", "org.scalatest" %%% "scalatest" % "3.1.0-SNAP13" % Test, "org.scalacheck" %%% "scalacheck" % "1.14.0" % Test )) @@ -78,7 +78,7 @@ lazy val testkit = crossProject(JSPlatform, JVMPlatform) .settings(commonSettings: _*) .settings( name := "diffson-testkit", - crossScalaVersions := Seq(scala211, scala212/*, scala213*/), + crossScalaVersions := Seq(scala212, scala213), libraryDependencies ++= Seq( "org.scalatest" %%% "scalatest" % "3.1.0-SNAP13", "org.scalacheck" %%% "scalacheck" % "1.14.0")) @@ -90,7 +90,7 @@ lazy val sprayJson = project.in(file("sprayJson")) .settings(commonSettings: _*) .settings( name := "diffson-spray-json", - crossScalaVersions := Seq(scala211, scala212), + crossScalaVersions := Seq(scala212, scala213), libraryDependencies += "io.spray" %% "spray-json" % "1.3.5") .dependsOn(core.jvm, testkit.jvm % Test) @@ -100,12 +100,12 @@ lazy val playJson = crossProject(JSPlatform, JVMPlatform) .settings(commonSettings: _*) .settings( name := "diffson-play-json", - libraryDependencies += "com.typesafe.play" %%% "play-json" % "2.7.4", - crossScalaVersions := Seq(scala211, scala212)) + libraryDependencies += "com.typesafe.play" %%% "play-json" % "2.8.0-M4", + crossScalaVersions := Seq(scala212, scala213)) .jsSettings(coverageEnabled := false) .dependsOn(core, testkit % Test) -val circeVersion = "0.11.1" +val circeVersion = "0.12.0-M4" lazy val circe = crossProject(JSPlatform, JVMPlatform) .crossType(CrossType.Full).in(file("circe")) .enablePlugins(ScoverageSbtPlugin) @@ -117,8 +117,11 @@ lazy val circe = crossProject(JSPlatform, JVMPlatform) "io.circe" %%% "circe-parser" % circeVersion, "io.circe" %%% "circe-generic" % circeVersion % Test ), - crossScalaVersions := Seq(scala211, scala212)) - .jsSettings(coverageEnabled := false) + crossScalaVersions := Seq(scala212, scala213)) + .jsSettings( + coverageEnabled := false, + libraryDependencies += "io.circe" %%% "not-java-time" % "0.2.0" + ) .dependsOn(core, testkit % Test) lazy val publishSettings = Seq( diff --git a/circe/shared/src/test/scala/diffson/circe/TestProtocol.scala b/circe/shared/src/test/scala/diffson/circe/TestProtocol.scala index f9d5562..e98fe96 100644 --- a/circe/shared/src/test/scala/diffson/circe/TestProtocol.scala +++ b/circe/shared/src/test/scala/diffson/circe/TestProtocol.scala @@ -15,14 +15,14 @@ import scala.language.implicitConversions trait CirceTestProtocol extends TestProtocol[Json] { implicit def intSeqMarshaller(is: Seq[Int]) = is.asJson - implicit def intSeqUnmarshaller(json: Json) = json.as[Seq[Int]].right.get + implicit def intSeqUnmarshaller(json: Json) = json.as[Seq[Int]].fold(throw _, identity) implicit def boolMarshaller(b: Boolean) = Json.fromBoolean(b) implicit def intMarshaller(i: Int) = Json.fromInt(i) implicit def stringMarshaller(s: String) = Json.fromString(s) implicit def jsonEq = Json.eqJson def parseJson(s: String): Json = - parse(s).right.get + parse(s).fold(throw _, identity) def parsePatch(s: String): JsonPatch[Json] = parse(s).flatMap(_.as[JsonPatch[Json]]).toTry.get def parsePatch(json: Json): JsonPatch[Json] = diff --git a/core/src/main/scala/diffson/jsonpointer/package.scala b/core/src/main/scala/diffson/jsonpointer/package.scala index bdb2f6e..8d8c474 100644 --- a/core/src/main/scala/diffson/jsonpointer/package.scala +++ b/core/src/main/scala/diffson/jsonpointer/package.scala @@ -24,6 +24,8 @@ import io.estatico.newtype.macros.newtype import scala.util.Try import scala.language.{ implicitConversions, higherKinds } +import scala.collection.compat._ +import scala.collection.compat.immutable.ArraySeq package object jsonpointer { @@ -92,7 +94,7 @@ package object jsonpointer { // transform the occurrences of '~1' into occurrences of '/' // transform the occurrences of '~0' into occurrences of '~' .map(_.replace("~1", "/").replace("~0", "~")) - F.pure(Pointer(elems: _*)) + F.pure(Pointer(ArraySeq.unsafeWrapArray(elems): _*)) } } } diff --git a/core/src/main/scala/diffson/lcs/Patience.scala b/core/src/main/scala/diffson/lcs/Patience.scala index ad1a829..0afee84 100644 --- a/core/src/main/scala/diffson/lcs/Patience.scala +++ b/core/src/main/scala/diffson/lcs/Patience.scala @@ -21,6 +21,7 @@ import cats.implicits._ import scala.annotation.tailrec import scala.collection.SortedMap import scala.collection.immutable.TreeMap +import scala.collection.compat._ /** Implementation of the patience algorithm [1] to compute the longest common subsequence * @@ -99,7 +100,7 @@ class Patience[T: Eq](withFallback: Boolean = true) extends Lcs[T] { val chainCont = { // we have to find a previous stack // don't know how efficient `until` is... - stacks.until(idx).lastOption.flatMap(_._2.headOption) + stacks.rangeUntil(idx).lastOption.flatMap(_._2.headOption) } (stacks - idx).updated(idx1, Stacked(idx1, idx2, chainCont) :: oldStack) } @@ -163,7 +164,7 @@ class Patience[T: Eq](withFallback: Boolean = true) extends Lcs[T] { var lastPos1 = low1 - 1 var lastPos2 = low2 - 1 var answer = acc - for ((p1, p2) <- longest(uniqueCommons(seq1.view(low1, high1).toList, seq2.view(low2, high2).toList))) { + for ((p1, p2) <- longest(uniqueCommons(seq1.view.slice(low1, high1).toList, seq2.view.slice(low2, high2).toList))) { // recurse between lines which are unique in each sequence val pos1 = p1 + low1 val pos2 = p2 + low2 diff --git a/core/src/test/scala/diffson/TestLcs.scala b/core/src/test/scala/diffson/TestLcs.scala index 5b8dc09..44e8e82 100644 --- a/core/src/test/scala/diffson/TestLcs.scala +++ b/core/src/test/scala/diffson/TestLcs.scala @@ -1,8 +1,9 @@ package diffson.lcs import org.scalatest._ +import org.scalatest.flatspec.AnyFlatSpec -abstract class TestLcs extends FlatSpec with Matchers { +abstract class TestLcs extends AnyFlatSpec with Matchers { val lcsImpl: Lcs[Char] diff --git a/core/src/test/scala/diffson/TestPatienceBigArray.scala b/core/src/test/scala/diffson/TestPatienceBigArray.scala index a7f16da..312e84c 100644 --- a/core/src/test/scala/diffson/TestPatienceBigArray.scala +++ b/core/src/test/scala/diffson/TestPatienceBigArray.scala @@ -3,8 +3,9 @@ package diffson.lcs import cats.implicits._ import org.scalatest._ +import org.scalatest.flatspec.AnyFlatSpec -class TestPatienceBigArray extends FlatSpec with Matchers { +class TestPatienceBigArray extends AnyFlatSpec with Matchers { val lcsImpl = new Patience[Int].savedHashes diff --git a/project/plugins.sbt b/project/plugins.sbt index 33cf5a4..d0187f9 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,11 +1,11 @@ -addSbtPlugin("org.scalariform" % "sbt-scalariform" % "1.8.2") +addSbtPlugin("org.scalariform" % "sbt-scalariform" % "1.8.3") -addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.5.1") +addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.6.0") addSbtPlugin("com.eed3si9n" % "sbt-unidoc" % "0.4.2") addSbtPlugin("com.codacy" % "sbt-codacy-coverage" % "1.3.15") -addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "0.6.0") +addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "0.6.1") addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.28") diff --git a/testkit/shared/src/main/scala/diffson/TestJsonDiff.scala b/testkit/shared/src/main/scala/diffson/TestJsonDiff.scala index 1c8d335..86daec8 100644 --- a/testkit/shared/src/main/scala/diffson/TestJsonDiff.scala +++ b/testkit/shared/src/main/scala/diffson/TestJsonDiff.scala @@ -8,12 +8,13 @@ import cats._ import cats.implicits._ import org.scalatest._ +import org.scalatest.flatspec.AnyFlatSpec import scala.util.Try import scala.language.implicitConversions -abstract class TestJsonDiff[Json](implicit Json: Jsony[Json]) extends FlatSpec with Matchers with TestProtocol[Json] { +abstract class TestJsonDiff[Json](implicit Json: Jsony[Json]) extends AnyFlatSpec with Matchers with TestProtocol[Json] { implicit val lcsalg = new lcs.Patience[Json] diff --git a/testkit/shared/src/main/scala/diffson/TestJsonMergeDiff.scala b/testkit/shared/src/main/scala/diffson/TestJsonMergeDiff.scala index 32ac097..038928c 100644 --- a/testkit/shared/src/main/scala/diffson/TestJsonMergeDiff.scala +++ b/testkit/shared/src/main/scala/diffson/TestJsonMergeDiff.scala @@ -4,10 +4,11 @@ package jsonmergepatch import cats._ import org.scalatest._ +import org.scalatest.flatspec.AnyFlatSpec import scala.language.implicitConversions -abstract class TestJsonMergeDiff[Json](implicit Json: Jsony[Json]) extends FlatSpec with Matchers with TestProtocol[Json] { +abstract class TestJsonMergeDiff[Json](implicit Json: Jsony[Json]) extends AnyFlatSpec with Matchers with TestProtocol[Json] { "a diff" should "be empty if created between two equal objects" in { val json = parseJson("""{"a": true}""") diff --git a/testkit/shared/src/main/scala/diffson/TestJsonMergePatch.scala b/testkit/shared/src/main/scala/diffson/TestJsonMergePatch.scala index 2d2428e..f2d61fb 100644 --- a/testkit/shared/src/main/scala/diffson/TestJsonMergePatch.scala +++ b/testkit/shared/src/main/scala/diffson/TestJsonMergePatch.scala @@ -4,10 +4,11 @@ package jsonmergepatch import cats.implicits._ import org.scalatest._ +import org.scalatest.flatspec.AnyFlatSpec import scala.util.Try -abstract class TestJsonMergePatch[Json](implicit Json: Jsony[Json]) extends FlatSpec with Matchers with TestProtocol[Json] { +abstract class TestJsonMergePatch[Json](implicit Json: Jsony[Json]) extends AnyFlatSpec with Matchers with TestProtocol[Json] { val samples = List( ("""{"a":"b"}""", """{"a":"c"}""", """{"a":"c"}"""), diff --git a/testkit/shared/src/main/scala/diffson/TestJsonPatch.scala b/testkit/shared/src/main/scala/diffson/TestJsonPatch.scala index 345e9f5..83a8387 100644 --- a/testkit/shared/src/main/scala/diffson/TestJsonPatch.scala +++ b/testkit/shared/src/main/scala/diffson/TestJsonPatch.scala @@ -6,161 +6,162 @@ import jsonpointer._ import cats.implicits._ import org.scalatest._ +import org.scalatest.flatspec.AnyFlatSpec import scala.util.Try import scala.language.implicitConversions -abstract class TestJsonPatch[Json](implicit Json: Jsony[Json]) extends FlatSpec +abstract class TestJsonPatch[Json](implicit Json: Jsony[Json]) extends AnyFlatSpec with Matchers with TestProtocol[Json] { "applying an 'add' operation" should "add the field to the object if it does not exist" in { val op = Add[Json](parsePointer("/lbl"), 17) - op(parseJson("{}")).get should be(parseJson("{ \"lbl\": 17 } ")) + op[Try](parseJson("{}")).get should be(parseJson("{ \"lbl\": 17 } ")) } "applying an 'add' operation to /foo/" should "add a value with an empty string as the key" in { val op = Add[Json](parsePointer("/foo/"), 17) - op(parseJson("{ \"foo\": {} }")).get should be(parseJson("{ \"foo\": {\"\": 17 } }")) + op[Try](parseJson("{ \"foo\": {} }")).get should be(parseJson("{ \"foo\": {\"\": 17 } }")) } it should "replace the value if the pointer is the root" in { val op = Add[Json](parsePointer(""), 17) - op(parseJson("[1, 2, 3, 4]")).get should be(17: Json) + op[Try](parseJson("[1, 2, 3, 4]")).get should be(17: Json) } it should "replace the field value if it does exist" in { val op = Add[Json](parsePointer("/lbl"), 17) - op(parseJson("{ \"lbl\": true }")).get should be(parseJson("{ \"lbl\": 17 } ")) + op[Try](parseJson("{ \"lbl\": true }")).get should be(parseJson("{ \"lbl\": 17 } ")) } it should "add an element to the array at the given index" in { val op1 = Add[Json](parsePointer("/1"), 17) - op1(parseJson("[1, 2, 3]")).get should be(parseJson("[1, 17, 2, 3]")) + op1[Try](parseJson("[1, 2, 3]")).get should be(parseJson("[1, 17, 2, 3]")) val op2 = Add[Json](parsePointer("/0"), 17) - op2(parseJson("[1, 2, 3]")).get should be(parseJson("[17, 1, 2, 3]")) + op2[Try](parseJson("[1, 2, 3]")).get should be(parseJson("[17, 1, 2, 3]")) } it should "add an element at the end of the array if the last element is '-'" in { val op = Add[Json](parsePointer("/-"), 17) - op(parseJson("[1, 2, 3]")).get should be(parseJson("[1, 2, 3, 17]")) + op[Try](parseJson("[1, 2, 3]")).get should be(parseJson("[1, 2, 3, 17]")) } it should "create a nested field if needed" in { val op = Add[Json](parsePointer("/lbl/lbl"), 17) - op(parseJson("{ \"lbl\": {} }")).get should be(parseJson("{ \"lbl\": { \"lbl\": 17 } }")) + op[Try](parseJson("{ \"lbl\": {} }")).get should be(parseJson("{ \"lbl\": { \"lbl\": 17 } }")) } it should "throw an error if some element is missing in the middle of the path" in { a[PatchException] should be thrownBy { val op = Add[Json](parsePointer("/lbl/lbl"), 17) - op(parseJson("{}")).get + op[Try](parseJson("{}")).get } } it should "throw an error if adding an element out of the array boundaries" in { a[PatchException] should be thrownBy { val op = Add[Json](parsePointer("/178"), 17) - op(parseJson("[1, 2]")).get + op[Try](parseJson("[1, 2]")).get } } "removing a label of an object" should "result in the object being amputed from this label" in { val op = Remove[Json](parsePointer("/lbl")) - op(parseJson("{ \"lbl\": 17, \"toto\": true }")).get should be(parseJson("{ \"toto\": true }")) + op[Try](parseJson("{ \"lbl\": 17, \"toto\": true }")).get should be(parseJson("{ \"toto\": true }")) } "removing an element of an array" should "result in the array being amputed from this element" in { val op = Remove[Json](parsePointer("/2")) - op(parseJson("[1, 2, 3, 4, 5]")).get should be(parseJson("[1, 2, 4, 5]")) + op[Try](parseJson("[1, 2, 3, 4, 5]")).get should be(parseJson("[1, 2, 4, 5]")) } "removing the '-' element of an array" should "result in an error being thrown" in { a[PatchException] should be thrownBy { val op = Remove[Json](parsePointer("/-")) - op(parseJson("[1, 2, 3, 4]")).get + op[Try](parseJson("[1, 2, 3, 4]")).get } } "removing an element out of the array boundaries" should "result in an error being thrown" in { a[PatchException] should be thrownBy { val op = Remove[Json](parsePointer("/20")) - op(parseJson("[1, 2, 3, 4]")).get + op[Try](parseJson("[1, 2, 3, 4]")).get } } "removing an unknown label from an object" should "result in an error being thrown" in { a[PatchException] should be thrownBy { val op = Remove[Json](parsePointer("/toto")) - op(parseJson("{}")).get + op[Try](parseJson("{}")).get } } "removing the root" should "result in an error being thrown" in { a[PatchException] should be thrownBy { val op = Remove[Json](parsePointer("/")) - op(parseJson("{}")).get + op[Try](parseJson("{}")).get } } "replacing an element in an object" should "result in this element being replaced" in { val op = Replace[Json](parsePointer("/lbl/lbl"), 17) - op(parseJson("""{"lbl": {"lbl": true, "gruik": 1}, "toto": 3}""")).get should be(parseJson("""{"lbl": {"lbl": 17, "gruik": 1}, "toto": 3}""")) + op[Try](parseJson("""{"lbl": {"lbl": true, "gruik": 1}, "toto": 3}""")).get should be(parseJson("""{"lbl": {"lbl": 17, "gruik": 1}, "toto": 3}""")) } "replacing an element in an array" should "result in this element being replaced" in { val op = Replace[Json](parsePointer("/3"), 17) - op(parseJson("[true, false, true, true, true]")).get should be(parseJson("[true, false, true, 17,true]")) + op[Try](parseJson("[true, false, true, true, true]")).get should be(parseJson("[true, false, true, 17,true]")) } "replacing the root" should "result in the value being completely replaced" in { val op = Replace[Json](parsePointer(""), 17) - op(parseJson("[1, 2, 3]")).get should be(17: Json) + op[Try](parseJson("[1, 2, 3]")).get should be(17: Json) } "replacing a non existing element in an object" should "result in an error being thrown" in { a[PatchException] should be thrownBy { val op = Replace[Json](parsePointer("/1/lbl"), 17) - op(parseJson("[1, {}, true]")).get + op[Try](parseJson("[1, {}, true]")).get } } "replacing the '-' element of an array" should "result in an error being thrown" in { a[PatchException] should be thrownBy { val op = Replace[Json](parsePointer("/-"), 17) - op(parseJson("[1, 2, 3, 4]")).get + op[Try](parseJson("[1, 2, 3, 4]")).get } } "replacing an element out of the array boundaries" should "result in an error being thrown" in { a[PatchException] should be thrownBy { val op = Replace[Json](parsePointer("/20"), 17) - op(parseJson("[1, 2, 3, 4]")).get + op[Try](parseJson("[1, 2, 3, 4]")).get } a[PatchException] should be thrownBy { val op = Replace[Json](parsePointer("/array/3/sub1"), 17) - op(parseJson("{\"array\":[\"bar1\",\"bar2\",{\"sub1\":\"bar3\"}]}")).get + op[Try](parseJson("{\"array\":[\"bar1\",\"bar2\",{\"sub1\":\"bar3\"}]}")).get } } "moving a value from an object to an array" should "result in the value being added to the array and removed from the object" in { val op = Move(parsePointer("/0/lbl"), parsePointer("/1/1")) - op(parseJson("[{ \"lbl\": 17, \"toto\": true }, [1, 2], \"plop\"]")).get should be( + op[Try](parseJson("[{ \"lbl\": 17, \"toto\": true }, [1, 2], \"plop\"]")).get should be( parseJson("[{ \"toto\": true }, [1, 17, 2], \"plop\"]")) } "moving a value in a sub element" should "result in an error being thrown" in { a[PatchException] should be thrownBy { val op = Move(parsePointer("/0"), parsePointer("/0/toto")) - op(parseJson("0")).get + op[Try](parseJson("0")).get } } "moving the root" should "result in an error being thrown" in { a[PatchException] should be thrownBy { val op = Move(parsePointer(""), parsePointer("/toto")) - op(parseJson("0")).get + op[Try](parseJson("0")).get } } } diff --git a/testkit/shared/src/main/scala/diffson/TestJsonPointer.scala b/testkit/shared/src/main/scala/diffson/TestJsonPointer.scala index 7ee0b87..588d335 100644 --- a/testkit/shared/src/main/scala/diffson/TestJsonPointer.scala +++ b/testkit/shared/src/main/scala/diffson/TestJsonPointer.scala @@ -4,12 +4,13 @@ package jsonpointer import cats.implicits._ import org.scalatest._ +import org.scalatest.flatspec.AnyFlatSpec import scala.util.Try import scala.language.implicitConversions -abstract class TestJsonPointer[Json](implicit Json: Jsony[Json]) extends FlatSpec with Matchers with TestProtocol[Json] { +abstract class TestJsonPointer[Json](implicit Json: Jsony[Json]) extends AnyFlatSpec with Matchers with TestProtocol[Json] { "an empty string" should "be parsed as an empty pointer" in { parsePointer("") should be(Pointer.Root) diff --git a/testkit/shared/src/main/scala/diffson/TestSerialization.scala b/testkit/shared/src/main/scala/diffson/TestSerialization.scala index ef6828b..4f54dae 100644 --- a/testkit/shared/src/main/scala/diffson/TestSerialization.scala +++ b/testkit/shared/src/main/scala/diffson/TestSerialization.scala @@ -5,8 +5,9 @@ import jsonpointer._ import jsonmergepatch._ import org.scalatest._ +import org.scalatest.flatspec.AnyFlatSpec -abstract class TestSerialization[Json](implicit Json: Jsony[Json]) extends FlatSpec with TestProtocol[Json] with Matchers { +abstract class TestSerialization[Json](implicit Json: Jsony[Json]) extends AnyFlatSpec with TestProtocol[Json] with Matchers { val patch = """[{ | "op":"replace", diff --git a/testkit/shared/src/main/scala/diffson/TestSimpleDiff.scala b/testkit/shared/src/main/scala/diffson/TestSimpleDiff.scala index 6777108..584afb4 100644 --- a/testkit/shared/src/main/scala/diffson/TestSimpleDiff.scala +++ b/testkit/shared/src/main/scala/diffson/TestSimpleDiff.scala @@ -8,12 +8,13 @@ import cats._ import cats.implicits._ import org.scalatest._ +import org.scalatest.flatspec.AnyFlatSpec import scala.util.Try import scala.language.implicitConversions -abstract class TestSimpleDiff[Json](implicit val Json: Jsony[Json]) extends FlatSpec with Matchers with TestProtocol[Json] { +abstract class TestSimpleDiff[Json](implicit val Json: Jsony[Json]) extends AnyFlatSpec with Matchers with TestProtocol[Json] { "a diff" should "be empty if created between two equal values" in { val json = parseJson("true")