Skip to content

Commit

Permalink
Merge pull request #301 from gnieh/fix/275/remember-simple
Browse files Browse the repository at this point in the history
Fix simple diff with remember
  • Loading branch information
satabin authored Sep 27, 2022
2 parents 9057278 + c3244f8 commit 6f09a28
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
8 changes: 7 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import com.typesafe.tools.mima.core._

val scala212 = "2.12.17"
val scala213 = "2.13.9"
val scala3 = "3.2.0"
Expand All @@ -13,7 +15,7 @@ ThisBuild / tlSonatypeUseLegacyHost := true

ThisBuild / tlFatalWarnings := false

ThisBuild / tlBaseVersion := "4.1"
ThisBuild / tlBaseVersion := "4.2"

ThisBuild / organization := "org.gnieh"
ThisBuild / startYear := Some(2022)
Expand Down Expand Up @@ -41,6 +43,10 @@ lazy val core = crossProject(JSPlatform, JVMPlatform, NativePlatform)
"org.typelevel" %%% "cats-core" % "2.8.0",
"org.scalatest" %%% "scalatest" % scalatestVersion % Test,
"org.scalacheck" %%% "scalacheck" % scalacheckVersion % Test
),
mimaBinaryIssueFilters ++= List(
ProblemFilters.exclude[DirectMissingMethodProblem](
"diffson.jsonpatch.package#simplediff#remembering.JsonDiffDiff")
)
)

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/diffson/jsonpatch/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ package object jsonpatch {
def lcs(seq1: List[Json], seq2: List[Json], low1: Int, high1: Int, low2: Int, high2: Int): List[(Int, Int)] = Nil
}
object remembering {
implicit def JsonDiffDiff[Json: Jsony: Lcs]: Diff[Json, JsonPatch[Json]] =
implicit def JsonDiffDiff[Json: Jsony]: Diff[Json, JsonPatch[Json]] =
new JsonDiff[Json](false, true)
}
implicit def JsonDiffDiff[Json: Jsony]: Diff[Json, JsonPatch[Json]] =
Expand Down
13 changes: 8 additions & 5 deletions testkit/shared/src/main/scala/diffson/TestSimpleDiff.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,10 @@ package jsonpatch
import simplediff._
import jsonpointer._

import cats._
import cats.implicits._

import org.scalatest._
import org.scalatest.flatspec.AnyFlatSpec

import scala.util.Try

import scala.language.implicitConversions
import org.scalatest.matchers.should.Matchers

abstract class TestSimpleDiff[Json](implicit val Json: Jsony[Json])
Expand Down Expand Up @@ -156,4 +151,12 @@ abstract class TestSimpleDiff[Json](implicit val Json: Jsony[Json])
diff(json1, json2) should be(JsonPatch[Json](Replace(Pointer("b"), "test": Json)))
}

"a remembering diff" should "remember old values" in {
import diffson.jsonpatch.simplediff.remembering._
val json1 = parseJson("""{"a": 1, "b": false}""")
val json2 = parseJson("""{"a": 1, "b": "test"}""")

diff(json1, json2) should be(JsonPatch[Json](Replace(Pointer("b"), "test": Json, Some(false: Json))))
}

}

0 comments on commit 6f09a28

Please sign in to comment.