Skip to content

Commit

Permalink
fmt and fix all
Browse files Browse the repository at this point in the history
  • Loading branch information
ThijsBroersen committed Nov 16, 2024
1 parent d041e60 commit 63f2e01
Show file tree
Hide file tree
Showing 36 changed files with 378 additions and 403 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package zio.json.golden

import java.io.{ File, IOException }
import java.nio.file.{ Path }
import zio.{ test => _, _ }
import zio.json._

import zio.stacktracer.TracingImplicits.disableAutoTrace
import zio.{ test => _, _ }

import java.nio.file.Files
import java.io.{ File, IOException }
import java.nio.file.{ Files, Path }

object filehelpers {

Expand Down
11 changes: 4 additions & 7 deletions zio-json-golden/src/main/scala/zio/json/golden/package.scala
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package zio.json

import scala.annotation.nowarn

import zio.Tag
import zio.{ test => _, _ }
import zio.json.ast._
import zio.json.golden.filehelpers._
import zio.stacktracer.TracingImplicits.disableAutoTrace
import zio.test._
import zio.test.diff._
import zio.test.diff.Diff._
import java.nio.file.{ Paths, Path, Files }
import zio.test.diff._
import zio.{ Tag, test => _, _ }

import zio.json.ast._
import java.nio.file.{ Files, Path, Paths }

package object golden {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package zio.json.interop

import eu.timepit.refined.api.{ Refined, Validate }
import eu.timepit.refined.{ refineV }
import eu.timepit.refined.refineV
import zio.json._

package object refined {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,11 @@ private[json] final class DeriveCodecMacros(val c: blackbox.Context) {
private[this] val EncoderClass = typeOf[JsonEncoder[_]].typeSymbol.asType
private[this] val CodecClass = typeOf[JsonCodec[_]].typeSymbol.asType

private[this] val macroName: Tree = {
private[this] val macroName: Tree =
c.prefix.tree match {
case Apply(Select(New(name), _), _) => name
case _ => c.abort(c.enclosingPosition, "Unexpected macro application")
}
}

private[this] val (codecStyle: JsonCodecStyle, codecType: JsonCodecType) = {
val style: JsonCodecStyle = macroName match {
Expand Down
6 changes: 2 additions & 4 deletions zio-json-yaml/src/main/scala/zio/json/yaml/YamlOptions.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package zio.json.yaml

import org.yaml.snakeyaml.DumperOptions.{ FlowStyle, LineBreak, NonPrintableStyle, ScalarStyle }
import org.yaml.snakeyaml.DumperOptions

import org.yaml.snakeyaml.DumperOptions.{ FlowStyle, LineBreak, NonPrintableStyle, ScalarStyle }
import zio.json.ast.Json

case class YamlOptions(
Expand All @@ -20,11 +19,10 @@ case class YamlOptions(
)

object YamlOptions {
private val defaultLineBreak: LineBreak = {
private val defaultLineBreak: LineBreak =
Set(LineBreak.MAC, LineBreak.WIN, LineBreak.UNIX)
.find(_.getString == System.lineSeparator())
.getOrElse(LineBreak.UNIX)
}

val default: YamlOptions = YamlOptions(
() => new DumperOptions(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package zio.json.yaml.internal

import org.yaml.snakeyaml.LoaderOptions
import org.yaml.snakeyaml.constructor.SafeConstructor
import org.yaml.snakeyaml.nodes.{ MappingNode, Node }
import org.yaml.snakeyaml.LoaderOptions

private[yaml] final class YamlValueConstruction extends SafeConstructor(new LoaderOptions()) {
def toJavaValue(node: Node): AnyRef =
Expand Down
2 changes: 1 addition & 1 deletion zio-json-yaml/src/main/scala/zio/json/yaml/package.scala
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package zio.json

import org.yaml.snakeyaml.DumperOptions.{ NonPrintableStyle, ScalarStyle }
import org.yaml.snakeyaml.Yaml
import org.yaml.snakeyaml.emitter.Emitter
import org.yaml.snakeyaml.error.YAMLException
import org.yaml.snakeyaml.nodes.{ ScalarNode, _ }
import org.yaml.snakeyaml.reader.StreamReader
import org.yaml.snakeyaml.resolver.Resolver
import org.yaml.snakeyaml.serializer._
import org.yaml.snakeyaml.Yaml
import zio.Chunk
import zio.json.ast.Json
import zio.json.yaml.internal.YamlValueConstruction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ class GoogleMapsAPIBenchmarks {

@Setup
def setup(): Unit = {
//Distance Matrix API call for top-10 by population cities in US:
//https://maps.googleapis.com/maps/api/distancematrix/json?origins=New+York|Los+Angeles|Chicago|Houston|Phoenix+AZ|Philadelphia|San+Antonio|San+Diego|Dallas|San+Jose&destinations=New+York|Los+Angeles|Chicago|Houston|Phoenix+AZ|Philadelphia|San+Antonio|San+Diego|Dallas|San+Jose
// Distance Matrix API call for top-10 by population cities in US:
// https://maps.googleapis.com/maps/api/distancematrix/json?origins=New+York|Los+Angeles|Chicago|Houston|Phoenix+AZ|Philadelphia|San+Antonio|San+Diego|Dallas|San+Jose&destinations=New+York|Los+Angeles|Chicago|Houston|Phoenix+AZ|Philadelphia|San+Antonio|San+Diego|Dallas|San+Jose
jsonString = getResourceAsString("google_maps_api_response.json")
jsonChars = asChars(jsonString)
jsonStringCompact = getResourceAsString(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ object Nested {
@Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
@Fork(value = 1)
class SyntheticBenchmarks {
//@Param(Array("100", "1000"))
// @Param(Array("100", "1000"))
var size: Int = 500
var jsonString: String = _
var jsonChars: CharSequence = _
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import org.openjdk.jmh.annotations._
@Fork(value = 1)
class SafeNumbersBenchInt {

//@Param(Array("100", "1000"))
// @Param(Array("100", "1000"))
var size: Int = 10000

// invalid input. e.g. out of range longs
Expand Down Expand Up @@ -69,7 +69,7 @@ class SafeNumbersBenchInt {
@Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
@Fork(value = 1)
class SafeNumbersBenchFloat {
//@Param(Array("100", "1000"))
// @Param(Array("100", "1000"))
var size: Int = 10000

var invalids: Array[String] = _
Expand Down Expand Up @@ -135,7 +135,7 @@ class SafeNumbersBenchFloat {
@Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
@Fork(value = 1)
class SafeNumbersBenchBigDecimal {
//@Param(Array("100", "1000"))
// @Param(Array("100", "1000"))
var size: Int = 10000

var invalids: Array[String] = _
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ trait JsonDecoderPlatformSpecific[A] { self: JsonDecoder[A] =>
}

/**
* Attempts to decode a stream of bytes using the user supplied Charset into a single value of type `A`, but may fail with
* a human-readable exception if the stream does not encode a value of this type.
* Attempts to decode a stream of bytes using the user supplied Charset into a single value of type `A`, but may fail
* with a human-readable exception if the stream does not encode a value of this type.
*
* Note: This method may not consume the full string.
*
* @see [[decodeJsonStream]] For a `Char` stream variant
* @see
* [[decodeJsonStream]] For a `Char` stream variant
*/
final def decodeJsonStreamInput[R](
stream: ZStream[R, Throwable, Byte],
Expand All @@ -41,12 +42,13 @@ trait JsonDecoderPlatformSpecific[A] { self: JsonDecoder[A] =>
}

/**
* Attempts to decode a stream of characters into a single value of type `A`, but may fail with
* a human-readable exception if the stream does not encode a value of this type.
* Attempts to decode a stream of characters into a single value of type `A`, but may fail with a human-readable
* exception if the stream does not encode a value of this type.
*
* Note: This method may not consume the full string.
*
* @see also [[decodeJsonStreamInput]]
* @see
* also [[decodeJsonStreamInput]]
*/
final def decodeJsonStream[R](stream: ZStream[R, Throwable, Char]): ZIO[R, Throwable, A] =
ZIO.scoped[R](stream.toReader.flatMap(readAll))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import java.nio.file.Paths

object DecoderPlatformSpecificSpec extends ZIOSpecDefault {

val spec =
val spec: Spec[Annotations with Live with Sized with TestConfig, Throwable] =
suite("Decoder")(
test("excessively nested structures") {
// JVM specific: getResourceAsString not yet supported
Expand Down Expand Up @@ -273,7 +273,7 @@ object DecoderPlatformSpecificSpec extends ZIOSpecDefault {
)
)

def testAst(label: String) =
def testAst(label: String): Spec[Any, Throwable] =
test(label) {
getResourceAsStringM(s"jawn/$label.json").flatMap { input =>
val expected = jawn.JParser.parseFromString(input).toEither.map(fromJawn)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import zio.Chunk
import zio.json.ast.Json
import zio.stream.{ ZSink, ZStream }
import zio.test.Assertion._
import zio.test.{ ZIOSpecDefault, assert, _ }
import zio.test.{ Spec, ZIOSpecDefault, assert, _ }

import java.io.IOException
import java.nio.file.Files

object EncoderPlatformSpecificSpec extends ZIOSpecDefault {
import testzio.json.DecoderSpec.logEvent._

val spec =
val spec: Spec[Any, Throwable] =
suite("Encoder")(
suite("roundtrip")(
testRoundTrip[DistanceMatrix]("google_maps_api_response"),
Expand Down
6 changes: 3 additions & 3 deletions zio-json/jvm/src/test/scala/zio/json/TestUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ object TestUtils {
def getResourceAsString(res: String): String = {
val is = getClass.getClassLoader.getResourceAsStream(res)
try {
val baos = new java.io.ByteArrayOutputStream()
val data = Array.ofDim[Byte](2048)
var len: Int = 0
val baos = new java.io.ByteArrayOutputStream()
val data = Array.ofDim[Byte](2048)
var len: Int = 0
def read(): Int = { len = is.read(data); len }
while (read() != -1)
baos.write(data, 0, len)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package testzio.json.internal

import testzio.json.Gens._
import zio.Scope
import zio.json.internal._
import zio.test.Assertion._
import zio.test._

object SafeNumbersSpec extends ZIOSpecDefault {
val spec =
val spec: Spec[Environment with TestEnvironment with Scope, Any] =
suite("SafeNumbers")(
test("valid big decimals") {
check(genBigDecimal)(i => assert(SafeNumbers.bigDecimal(i.toString, 2048))(isSome(equalTo(i))))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,16 @@ object StringMatrixSpec extends ZIOSpecDefault {
}
)

val genNonEmptyString =
val genNonEmptyString: Gen[Any, String] =
Gen.alphaNumericString.filter(_.nonEmpty)

val genTestStrings =
val genTestStrings: Gen[Any, List[String]] =
for {
n <- Gen.int(1, 63)
xs <- Gen.setOfN(n)(genNonEmptyString)
} yield xs.toList

val genTestStringsAndAliases =
val genTestStringsAndAliases: Gen[Any, (List[String], List[(String, Int)])] =
for {
xsn <- Gen.int(1, 63)
xs <- Gen.setOfN(xsn)(genNonEmptyString)
Expand Down
Loading

0 comments on commit 63f2e01

Please sign in to comment.