Skip to content

Commit

Permalink
apply formatting from prePR
Browse files Browse the repository at this point in the history
  • Loading branch information
esarbe committed Jan 19, 2024
1 parent 08c757e commit 8bd051d
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 35 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ jobs:

- name: Make target directories
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main')
run: mkdir -p circe/jvm/target playJson/native/target testkit/native/target testkit/js/target core/.native/target playJson/jvm/target core/.js/target circe/js/target core/.jvm/target circe/native/target playJson/js/target testkit/jvm/target sprayJson/.jvm/target project/target
run: mkdir -p ujson/jvm/target circe/jvm/target playJson/native/target testkit/native/target testkit/js/target core/.native/target playJson/jvm/target ujson/js/target core/.js/target circe/js/target core/.jvm/target circe/native/target ujson/native/target playJson/js/target testkit/jvm/target sprayJson/.jvm/target project/target

- name: Compress target directories
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main')
run: tar cf targets.tar circe/jvm/target playJson/native/target testkit/native/target testkit/js/target core/.native/target playJson/jvm/target core/.js/target circe/js/target core/.jvm/target circe/native/target playJson/js/target testkit/jvm/target sprayJson/.jvm/target project/target
run: tar cf targets.tar ujson/jvm/target circe/jvm/target playJson/native/target testkit/native/target testkit/js/target core/.native/target playJson/jvm/target ujson/js/target core/.js/target circe/js/target core/.jvm/target circe/native/target ujson/native/target playJson/js/target testkit/jvm/target sprayJson/.jvm/target project/target

- name: Upload target directories
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main')
Expand Down
3 changes: 1 addition & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,11 @@ lazy val ujson = crossProject(JSPlatform, JVMPlatform, NativePlatform)
name := "diffson-ujson",
libraryDependencies ++= Seq(
"com.lihaoyi" %%% "ujson" % ujsonVersion,
"com.lihaoyi" %%% "upickle" % ujsonVersion,
"com.lihaoyi" %%% "upickle" % ujsonVersion
)
)
.dependsOn(core, testkit % Test)


lazy val benchmarks = crossProject(JVMPlatform)
.crossType(CrossType.Pure)
.in(file("benchmarks"))
Expand Down
19 changes: 18 additions & 1 deletion ujson/shared/src/main/scala/diffson/ujson/FieldMissing.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
package diffson.ujson
/*
* Copyright 2022 Raphael Bosshard
*
* 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 ujson

case class FieldMissing(fieldName: String)
extends Exception(s"Expected field `$fieldName`, but it is missing")
33 changes: 17 additions & 16 deletions ujson/shared/src/main/scala/diffson/ujson/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ import cats.implicits._
import diffson.jsonmergepatch.JsonMergePatch
import diffson.jsonpatch._
import diffson.jsonpointer.Pointer
import _root_.ujson as lihaoyUjson
import lihaoyUjson.{Value, Arr, Obj, Str}
import _root_.ujson.{Value, Arr, Obj, Str}
import upickle.default._

import scala.util.Try

package object ujson {
implicit val jsonyUjson: Jsony[Value] = new Jsony[Value] {

implicit val jsonyUjson: Jsony[Value] = new Jsony[Value] {

def Null: Value = _root_.ujson.Null

Expand Down Expand Up @@ -64,49 +63,49 @@ package object ujson {
Obj(
"op" -> Str("add"),
"path" -> Str(path.show),
"value" -> value,
"value" -> value
)
case Remove(path, Some(old)) =>
Obj(
"op" -> Str("remove"),
"path" -> Str(path.show),
"old" -> old,
"old" -> old
)
case Remove(path, None) =>
Obj(
"op" -> Str("remove"),
"path" -> Str(path.show),
"path" -> Str(path.show)
)
case Replace(path, value, Some(old)) =>
Obj(
"op" -> Str("replace"),
"path" -> Str(path.show),
"value" -> value,
"old" -> old,
"old" -> old
)
case Replace(path, value, None) =>
Obj(
"op" -> Str("replace"),
"path" -> Str(path.show),
"value" -> value,
"value" -> value
)
case Move(from, path) =>
Obj(
"op" -> Str("move"),
"from" -> Str(from.show),
"path" -> Str(path.show),
"path" -> Str(path.show)
)
case Copy(from, path) =>
Obj(
"op" -> Str("copy"),
"from" -> Str(from.show),
"path" -> Str(path.show),
"path" -> Str(path.show)
)
case Test(path, value) =>
Obj(
"op" -> Str("test"),
"path" -> Str(path.show),
"value" -> value,
"value" -> value
)
}

Expand All @@ -116,19 +115,21 @@ package object ujson {
private def decodeOperation(value: Value): Operation[Value] = {
def readPointer(value: Value, path: String = "path"): Pointer = {
val serializedPointer =
value.objOpt.flatMap(_.get(path))
value.objOpt
.flatMap(_.get(path))
.getOrElse(throw FieldMissing(path))

read[Pointer](serializedPointer)
}

val op =
value
.objOpt.flatMap(_.get("op").flatMap(_.strOpt))
value.objOpt
.flatMap(_.get("op").flatMap(_.strOpt))
.getOrElse(throw FieldMissing("op"))

def getField(key: String) = {
value.objOpt.flatMap(_.get(key))
value.objOpt
.flatMap(_.get(key))
.getOrElse(throw FieldMissing(key))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@

package diffson
package ujson
import _root_.ujson._

import _root_.ujson._
import jsonmergepatch._

class UjsonJsonJsonMergeDiff
extends TestJsonMergeDiff[Value] with UjsonTestProtocol
class UjsonJsonJsonMergeDiff extends TestJsonMergeDiff[Value] with UjsonTestProtocol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package diffson
package ujson

import jsonpatch._
import _root_.ujson as lihaoyUjson
import _root_.ujson.Value

class UjsonTestArrayDiff
extends TestArrayDiff[lihaoyUjson.Value] with UjsonTestProtocol
class UjsonTestArrayDiff extends TestArrayDiff[Value] with UjsonTestProtocol
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@ package ujson
import jsonmergepatch._
import _root_.ujson._

class UjsonTestJsonMergePatch
extends TestJsonMergePatch[Value] with UjsonTestProtocol
class UjsonTestJsonMergePatch extends TestJsonMergePatch[Value] with UjsonTestProtocol
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
package diffson
package ujson

import _root_.ujson.{Arr, Bool, Str, Value}
import _root_.ujson.{Arr, Bool, Str, Value}
import cats.Eq
import diffson.jsonmergepatch.*
import diffson.jsonpatch.*
import upickle.default.*
import diffson.jsonmergepatch._
import diffson.jsonpatch._
import upickle.default._

trait UjsonTestProtocol extends TestProtocol[Value] {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@ package ujson

import _root_.ujson._

class UjsonTestSerialization
extends TestSerialization[Value] with UjsonTestProtocol
class UjsonTestSerialization extends TestSerialization[Value] with UjsonTestProtocol

0 comments on commit 8bd051d

Please sign in to comment.