Skip to content

Commit ec90e15

Browse files
support scala 3 for circe
1 parent 899941c commit ec90e15

File tree

5 files changed

+47
-28
lines changed

5 files changed

+47
-28
lines changed

.scalafmt.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
version = "2.7.5"

build.sbt

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,19 @@ lazy val root = (project in file("."))
88
.aggregate(jsonassert, json4s, playJson, circe, argonaut, jsoniterScala)
99

1010
lazy val json4s = (project in file("json4s"))
11-
.settings(commonSettings)
11+
.settings(commonSettings)
1212

1313
lazy val jsonassert = (project in file("jsonassert"))
14-
.settings(commonSettings)
14+
.settings(commonSettings)
1515

1616
lazy val playJson = (project in file("play-json"))
1717
.settings(commonSettings)
1818

1919
lazy val circe = (project in file("circe"))
2020
.settings(commonSettings)
21+
.settings(
22+
crossScalaVersions += "3.0.0"
23+
)
2124

2225
lazy val argonaut = (project in file("argonaut"))
2326
.settings(commonSettings)
@@ -28,17 +31,26 @@ lazy val jsoniterScala = (project in file("jsoniter-scala"))
2831
lazy val commonSettings = Seq(
2932
organization := "com.stephenn",
3033
homepage := Some(url("https://github.com/stephennancekivell/scalatest-json")),
31-
scmInfo := Some(ScmInfo(url("https://github.com/stephennancekivell/scalatest-json"),
32-
"[email protected]:stephennancekivell/scalatest-json.git")),
34+
scmInfo := Some(
35+
ScmInfo(
36+
url("https://github.com/stephennancekivell/scalatest-json"),
37+
"[email protected]:stephennancekivell/scalatest-json.git"
38+
)
39+
),
3340
developers := List(
34-
Developer("stephennancekivell",
41+
Developer(
42+
"stephennancekivell",
3543
"Stephen Nancekivell",
3644
37-
url("https://stephenn.com")),
38-
Developer("baldram",
45+
url("https://stephenn.com")
46+
),
47+
Developer(
48+
"baldram",
3949
"Marcin Szałomski",
4050
41-
url("https://twitter.com/baldram"))),
51+
url("https://twitter.com/baldram")
52+
)
53+
),
4254
licenses += ("Apache-2.0", url("http://www.apache.org/licenses/LICENSE-2.0")),
4355
publishMavenStyle := true,
4456
publishTo := sonatypePublishTo.value,
@@ -47,14 +59,16 @@ lazy val commonSettings = Seq(
4759
crossScalaVersions := Seq("2.12.13", "2.13.6"),
4860
scalacOptions ++= Seq(
4961
"-deprecation",
50-
"-encoding", "UTF-8", // yes, this is 2 args
62+
"-encoding",
63+
"UTF-8", // yes, this is 2 args
5164
"-language:existentials",
5265
"-language:higherKinds",
5366
"-language:implicitConversions",
5467
"-unchecked",
55-
"-Xfatal-warnings",
56-
"-Xlint",
57-
"-Ywarn-numeric-widen",
58-
"-Ywarn-value-discard",
68+
"-Xfatal-warnings"
69+
// "-Xlint",
70+
// "-Ywarn-numeric-widen",
71+
// "-Ywarn-value-discard",
72+
// "-source:3.0-migration"
5973
)
6074
)

circe/src/main/scala/com/stephenn/scalatest/circe/JsonMatchers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ trait JsonMatchers {
6666
import io.circe._
6767
import io.circe.syntax._
6868

69-
implicit val lcs = new Patience[Json]
69+
implicit val lcs: Patience[Json] = new Patience[Json]
7070

7171
diff(left, right).asJson.toString
7272
}

circe/src/test/scala/com/stephenn/scalatest/circe/ExampleSpec.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,11 @@ class ExampleSpec extends AnyFunSpec with Matchers with JsonMatchers {
7474

7575
it("can compare json and a model") {
7676
case class Foo(sameField: String)
77-
implicit val encoder = Encoder.forProduct1("someField")(Foo.unapply)
78-
implicit val decoder = Decoder.forProduct1("someField")(Foo.apply)
77+
78+
implicit val encoder: Encoder[Foo] =
79+
Encoder.forProduct1("someField")(_.sameField)
80+
implicit val decoder: Decoder[Foo] =
81+
Decoder.forProduct1("someField")(Foo.apply)
7982

8083
val json = """
8184
|{

circe/src/test/scala/com/stephenn/scalatest/circe/JsonMatchersSpec.scala

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ class JsonMatchersSpec extends AnyFunSpec with Matchers {
88

99
describe("JsonMatchers") {
1010
it("should pass when json is the same") {
11-
Seq("{}" -> "{}", "[]" -> "[]").foreach {
12-
case (left, right) =>
13-
val matchResult = JsonMatchers.matchJson(right).apply(left)
14-
matchResult.matches shouldBe true
11+
Seq("{}" -> "{}", "[]" -> "[]").foreach { case (left, right) =>
12+
val matchResult = JsonMatchers.matchJson(right).apply(left)
13+
matchResult.matches shouldBe true
1514
}
1615
}
1716

@@ -23,10 +22,9 @@ class JsonMatchersSpec extends AnyFunSpec with Matchers {
2322
"{}" -> " { }",
2423
" [ ] " -> "[]",
2524
"""{"a":0, "b":1}""" -> """{"b":1,"a":0}"""
26-
).foreach {
27-
case (left, right) =>
28-
val matchResult = JsonMatchers.matchJson(right).apply(left)
29-
matchResult.matches shouldBe true
25+
).foreach { case (left, right) =>
26+
val matchResult = JsonMatchers.matchJson(right).apply(left)
27+
matchResult.matches shouldBe true
3028
}
3129
}
3230

@@ -83,8 +81,9 @@ class JsonMatchersSpec extends AnyFunSpec with Matchers {
8381

8482
describe("golden test") {
8583
case class Foo(a: String)
86-
implicit val encoder: Encoder[Foo] = Encoder.forProduct1("a")(Foo.unapply)
87-
implicit val decoder: Decoder[Foo] = Decoder.forProduct1("a")(Foo.apply)
84+
implicit val encoder: Encoder[Foo] =
85+
Encoder.forProduct1("a")(_.a)
86+
implicit val decoder: Decoder[Foo] = Decoder.forProduct1("a")(a => Foo(a))
8887

8988
it("should pass a golden test") {
9089
val result = JsonMatchers
@@ -121,9 +120,11 @@ class JsonMatchersSpec extends AnyFunSpec with Matchers {
121120

122121
it("should error if the json encoded value doesnt match the json") {
123122
case class Bar(a: String)
123+
case class B(a: String, b: String)
124+
124125
implicit val encoder: Encoder[Bar] =
125-
Encoder.forProduct1("encodedA")(Bar.unapply)
126-
implicit val decoder: Decoder[Bar] = Decoder.forProduct1("a")(Bar.apply)
126+
Encoder.forProduct1("encodedA")(_.a)
127+
implicit val decoder: Decoder[Bar] = Decoder.forProduct1("a")(a => Bar(a))
127128

128129
val result = JsonMatchers
129130
.matchJsonGolden(""" {"a":"value"} """.stripMargin)

0 commit comments

Comments
 (0)