-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upgrade deps and add Scala 3 support
* Upgrade all deps * Split sources in scala-2 and scala-3 for required compat changes * Mostly bincompat, but had to remove a few functions in Resources object
- Loading branch information
Showing
15 changed files
with
330 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,7 @@ target/ | |
.classpath | ||
tmp/ | ||
.bsp/ | ||
.metals/ | ||
.vscode/ | ||
.jvm/ | ||
*.semanticdb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
golden/src/main/scala-2/io/circe/testing/golden/GoldenCodecTestsCompanion.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright 2016 circe | ||
* | ||
* 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 io.circe.testing.golden | ||
|
||
import io.circe.Decoder | ||
import io.circe.Encoder | ||
import io.circe.Printer | ||
import org.scalacheck.Arbitrary | ||
|
||
import scala.reflect.runtime.universe.TypeTag | ||
|
||
trait GoldenCodecTestsCompanion { self: GoldenCodecTests.type => | ||
def apply[A: Decoder: Encoder: Arbitrary: TypeTag]: GoldenCodecTests[A] = | ||
fromLaws[A](ResourceFileGoldenCodecLaws[A]()) | ||
|
||
def apply[A: Decoder: Encoder: Arbitrary: TypeTag](printer: Printer): GoldenCodecTests[A] = | ||
fromLaws[A](ResourceFileGoldenCodecLaws[A](printer = printer)) | ||
|
||
def apply[A: Decoder: Encoder: Arbitrary: TypeTag](count: Int): GoldenCodecTests[A] = | ||
fromLaws[A](ResourceFileGoldenCodecLaws[A](count = count)) | ||
|
||
def apply[A: Decoder: Encoder: Arbitrary: TypeTag](count: Int, printer: Printer): GoldenCodecTests[A] = | ||
fromLaws[A](ResourceFileGoldenCodecLaws[A](count = count, printer = printer)) | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
golden/src/main/scala-2/io/circe/testing/golden/ResourceFileGoldenCodecLawsCompanion.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright 2016 circe | ||
* | ||
* 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 io.circe.testing.golden | ||
|
||
import io.circe.Decoder | ||
import io.circe.Encoder | ||
import io.circe.Printer | ||
import org.scalacheck.Arbitrary | ||
|
||
import scala.reflect.runtime.universe.TypeTag | ||
|
||
trait ResourceFileGoldenCodecLawsCompanion { self: ResourceFileGoldenCodecLaws.type => | ||
|
||
def apply[A]( | ||
size: Int = 100, | ||
count: Int = 1, | ||
printer: Printer = Printer.spaces2 | ||
)(implicit | ||
decodeA: Decoder[A], | ||
encodeA: Encoder[A], | ||
arbitraryA: Arbitrary[A], | ||
typeTagA: TypeTag[A] | ||
): GoldenCodecLaws[A] = | ||
self.apply[A]( | ||
Scala2Naming.inferName[A], | ||
Resources.inferRootDir(typeTagA.mirror.runtimeClass(typeTagA.tpe)), | ||
Scala2Naming.inferPackage[A], | ||
size, | ||
count, | ||
printer | ||
) | ||
} |
47 changes: 47 additions & 0 deletions
47
golden/src/main/scala-2/io/circe/testing/golden/Scala2Naming.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright 2016 circe | ||
* | ||
* 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 io.circe.testing.golden | ||
|
||
import scala.reflect.runtime.universe.Symbol | ||
import scala.reflect.runtime.universe.Type | ||
import scala.reflect.runtime.universe.TypeTag | ||
|
||
object Scala2Naming { | ||
|
||
/** | ||
* Attempt to guess the packaging of the type indicated by the provided type tag. | ||
*/ | ||
def inferPackage[A](implicit A: TypeTag[A]): List[String] = | ||
owners(A.tpe).collectFirst { case s if s.isPackage => s.fullName.split('.').toList }.getOrElse(List.empty) | ||
|
||
private def owners(tpe: Type): Iterator[Symbol] = | ||
Iterator.iterate(tpe.typeSymbol)(_.owner) | ||
|
||
/** | ||
* Attempt to guess the name of the type indicated by the provided type tag. | ||
*/ | ||
def inferName[A](implicit A: TypeTag[A]): String = inferNameForType(A.tpe) | ||
|
||
private def baseSymbols(tpe: Type): List[Symbol] = | ||
owners(tpe).takeWhile(!_.isPackage).toList.reverse | ||
|
||
private def inferNameForType(tpe: Type): String = { | ||
val baseNames = baseSymbols(tpe).map(_.name.decodedName.toString) | ||
|
||
(baseNames ::: tpe.typeArgs.map(inferNameForType)).mkString("_") | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
golden/src/main/scala-3/io/circe/testing/golden/GoldenCodecTestsCompanion.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2016 circe | ||
* | ||
* 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 io.circe.testing.golden | ||
|
||
import io.circe.Decoder | ||
import io.circe.Encoder | ||
import io.circe.Printer | ||
import org.scalacheck.Arbitrary | ||
|
||
import scala.reflect.ClassTag | ||
|
||
trait GoldenCodecTestsCompanion { self: GoldenCodecTests.type => | ||
inline def apply[A: Decoder: Encoder: Arbitrary: ClassTag]: GoldenCodecTests[A] = | ||
fromLaws[A](ResourceFileGoldenCodecLaws[A]()) | ||
|
||
inline def apply[A: Decoder: Encoder: Arbitrary: ClassTag](printer: Printer): GoldenCodecTests[A] = | ||
fromLaws[A](ResourceFileGoldenCodecLaws[A](printer = printer)) | ||
|
||
inline def apply[A: Decoder: Encoder: Arbitrary: ClassTag](count: Int): GoldenCodecTests[A] = | ||
fromLaws[A](ResourceFileGoldenCodecLaws[A](count = count)) | ||
|
||
inline def apply[A: Decoder: Encoder: Arbitrary: ClassTag](count: Int, printer: Printer): GoldenCodecTests[A] = | ||
fromLaws[A](ResourceFileGoldenCodecLaws[A](count = count, printer = printer)) | ||
} |
46 changes: 46 additions & 0 deletions
46
golden/src/main/scala-3/io/circe/testing/golden/ResourceFileGoldenCodecLawsCompanion.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright 2016 circe | ||
* | ||
* 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 io.circe.testing.golden | ||
|
||
import io.circe.Decoder | ||
import io.circe.Encoder | ||
import io.circe.Printer | ||
import org.scalacheck.Arbitrary | ||
|
||
import scala.reflect.ClassTag | ||
|
||
trait ResourceFileGoldenCodecLawsCompanion { self: ResourceFileGoldenCodecLaws.type => | ||
|
||
inline def apply[A]( | ||
size: Int = 100, | ||
count: Int = 1, | ||
printer: Printer = Printer.spaces2 | ||
)(using | ||
decodeA: Decoder[A], | ||
encodeA: Encoder[A], | ||
arbitraryA: Arbitrary[A], | ||
classT: ClassTag[A] | ||
): GoldenCodecLaws[A] = | ||
self.apply[A]( | ||
Scala3Naming.name[A], | ||
Resources.inferRootDir(classT.runtimeClass), | ||
Scala3Naming.pkg[A], | ||
size, | ||
count, | ||
printer | ||
) | ||
} |
Oops, something went wrong.