Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ concurrency:

jobs:
build:
name: Build and Test
name: Test
strategy:
matrix:
os: [ubuntu-latest]
os: [ubuntu-22.04]
scala: [2.12, 2.13, 3]
java: [temurin@11]
project: [diffsonJVM, diffsonJS, diffsonNative]
Expand All @@ -39,6 +39,9 @@ jobs:
with:
fetch-depth: 0

- name: Setup sbt
uses: sbt/setup-sbt@v1

- name: Setup Java (temurin@11)
id: setup-java-temurin-11
if: matrix.java == 'temurin@11'
Expand All @@ -56,7 +59,7 @@ jobs:
run: sbt githubWorkflowCheck

- name: Check headers and formatting
if: matrix.java == 'temurin@11' && matrix.os == 'ubuntu-latest'
if: matrix.java == 'temurin@11' && matrix.os == 'ubuntu-22.04'
run: sbt 'project ${{ matrix.project }}' '++ ${{ matrix.scala }}' headerCheckAll scalafmtCheckAll 'project /' scalafmtSbtCheck

- name: scalaJSLink
Expand All @@ -71,11 +74,11 @@ jobs:
run: sbt 'project ${{ matrix.project }}' '++ ${{ matrix.scala }}' test

- name: Check binary compatibility
if: matrix.java == 'temurin@11' && matrix.os == 'ubuntu-latest'
if: matrix.java == 'temurin@11' && matrix.os == 'ubuntu-22.04'
run: sbt 'project ${{ matrix.project }}' '++ ${{ matrix.scala }}' mimaReportBinaryIssues

- name: Generate API documentation
if: matrix.java == 'temurin@11' && matrix.os == 'ubuntu-latest'
if: matrix.java == 'temurin@11' && matrix.os == 'ubuntu-22.04'
run: sbt 'project ${{ matrix.project }}' '++ ${{ matrix.scala }}' doc

- name: Make target directories
Expand All @@ -99,7 +102,7 @@ jobs:
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main')
strategy:
matrix:
os: [ubuntu-latest]
os: [ubuntu-22.04]
java: [temurin@11]
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -108,6 +111,9 @@ jobs:
with:
fetch-depth: 0

- name: Setup sbt
uses: sbt/setup-sbt@v1

- name: Setup Java (temurin@11)
id: setup-java-temurin-11
if: matrix.java == 'temurin@11'
Expand Down Expand Up @@ -237,10 +243,10 @@ jobs:

dependency-submission:
name: Submit Dependencies
if: github.event_name != 'pull_request'
if: github.event.repository.fork == false && github.event_name != 'pull_request'
strategy:
matrix:
os: [ubuntu-latest]
os: [ubuntu-22.04]
java: [temurin@11]
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -249,6 +255,9 @@ jobs:
with:
fetch-depth: 0

- name: Setup sbt
uses: sbt/setup-sbt@v1

- name: Setup Java (temurin@11)
id: setup-java-temurin-11
if: matrix.java == 'temurin@11'
Expand All @@ -272,7 +281,7 @@ jobs:
name: Validate Steward Config
strategy:
matrix:
os: [ubuntu-latest]
os: [ubuntu-22.04]
java: [temurin@11]
runs-on: ${{ matrix.os }}
steps:
Expand Down
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import com.typesafe.tools.mima.core._

val scala212 = "2.12.19"
val scala213 = "2.13.12"
val scala213 = "2.13.13"
val scala3 = "3.3.3"

val scalatestVersion = "3.2.18"
Expand All @@ -13,7 +13,7 @@ ThisBuild / crossScalaVersions := Seq(elems = scala212, scala213, scala3)

ThisBuild / tlFatalWarnings := false

ThisBuild / tlBaseVersion := "4.5"
ThisBuild / tlBaseVersion := "4.6"

ThisBuild / organization := "org.gnieh"
ThisBuild / organizationName := "Diffson Project"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright 2024 Diffson Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package diffson.circe

import diffson.jsonpatch.TestObjectDiff
import io.circe.Json

class CirceTestObjectDiff extends TestObjectDiff[Json]
9 changes: 6 additions & 3 deletions core/src/main/scala/diffson/jsonpatch/JsonDiff.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,14 @@ class JsonDiff[Json](diffArray: Boolean, rememberOld: Boolean)(implicit J: Jsony
case (fld, value1) :: fields1 =>
fields2.get(fld) match {
case Some(value2) =>
fieldsDiff(fields1, fields2 - fld, path).flatMap(d => diff(value1, value2, path / fld).map(_ ++ d))
Eval
.defer(fieldsDiff(fields1, fields2 - fld, path))
.flatMap(d => diff(value1, value2, path / fld).map(_ ++ d))
case None =>
// field is not in the second object, delete it
fieldsDiff(fields1, fields2, path).map(
_.prepend(Remove(path / fld, if (rememberOld) Some(value1) else None)))
Eval
.defer(fieldsDiff(fields1, fields2, path))
.map(_.prepend(Remove(path / fld, if (rememberOld) Some(value1) else None)))
}
case Nil =>
Eval.now(Chain.fromSeq(fields2.toList).map { case (fld, value) => Add(path / fld, value) })
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.9.9
sbt.version=1.11.6
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
addSbtPlugin("org.typelevel" % "sbt-typelevel" % "0.6.7")
addSbtPlugin("org.typelevel" % "sbt-typelevel" % "0.8.0")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.16.0")
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.17")
addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.7")
44 changes: 44 additions & 0 deletions testkit/shared/src/main/scala/diffson/TestObjectDiff.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2024 Diffson Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package diffson
package jsonpatch

import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
import diffson.jsonpatch.JsonDiff
import diffson.lcs.Patience

abstract class TestObjectDiff[J](implicit J: Jsony[J]) extends AnyFlatSpec with Matchers {

implicit val lcsalg: Patience[J] = new Patience[J]

val diff = new JsonDiff[J](false, false)

"a wide object diffed with an empty one" should "not cause stack overflows" in {
val json1 = J.makeObject((1 to 10000).map(i => s"key$i" -> J.Null).toMap)
val json2 = J.makeObject(Map.empty)

diff.diff(json1, json2)
}

"a wide object diffed with itself" should "not cause stack overflows" in {
val json1 = J.makeObject((1 to 10000).map(i => s"key$i" -> J.Null).toMap)

diff.diff(json1, json1)
}

}