forked from zio/zio-schema
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial support for opaque types in Deriver (zio#517)
* Initial support for opaque types in Deriver * Generate readme * Fix 2.12 * Fix * 2.12 fix * Missing file * Cleanup * Removed prints
- Loading branch information
Showing
11 changed files
with
437 additions
and
301 deletions.
There are no files selected for viewing
593 changes: 307 additions & 286 deletions
593
zio-schema-derivation/shared/src/main/scala-3/zio/schema/Derive.scala
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
8 changes: 8 additions & 0 deletions
8
zio-schema-derivation/shared/src/test/scala-2.12/zio/schema/VersionSpecificDeriveSpec.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,8 @@ | ||
package zio.schema | ||
|
||
import zio.test._ | ||
|
||
trait VersionSpecificDeriveSpec extends ZIOSpecDefault { | ||
|
||
def versionSpecificSuite: Spec[Any, Nothing] = Spec.labeled("Scala 2.12 specific tests", Spec.empty) | ||
} |
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
8 changes: 8 additions & 0 deletions
8
zio-schema-derivation/shared/src/test/scala-2.13/zio/schema/VersionSpecificDeriveSpec.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,8 @@ | ||
package zio.schema | ||
|
||
import zio.test._ | ||
|
||
trait VersionSpecificDeriveSpec extends ZIOSpecDefault { | ||
|
||
def versionSpecificSuite: Spec[Any, Nothing] = Spec.labeled("Scala 2.13 specific tests", Spec.empty) | ||
} |
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
69 changes: 69 additions & 0 deletions
69
zio-schema-derivation/shared/src/test/scala-3/zio/schema/VersionSpecificDeriveSpec.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,69 @@ | ||
package zio.schema | ||
|
||
import zio.* | ||
import zio.test.* | ||
import zio.test.Assertion.* | ||
import scala.reflect.ClassTag | ||
|
||
trait VersionSpecificDeriveSpec extends ZIOSpecDefault { | ||
import VersionSpecificDeriveSpec.* | ||
|
||
def versionSpecificSuite = | ||
suite("Scala 3 specific tests")( | ||
test("Opaque types") { | ||
val deriver = new Deriver[TC] { | ||
override def deriveRecord[A](record: Schema.Record[A], fields: => Chunk[Deriver.WrappedF[TC, _]], summoned: => Option[TC[A]]): TC[A] = ??? | ||
|
||
override def deriveEnum[A](`enum`: Schema.Enum[A], cases: => Chunk[Deriver.WrappedF[TC, _]], summoned: => Option[TC[A]]): TC[A] = ??? | ||
|
||
override def derivePrimitive[A](st: StandardType[A], summoned: => Option[TC[A]]): TC[A] = ??? | ||
|
||
override def derivePrimitiveAlias[A: ClassTag, U](st: StandardType[U], summoned: => Option[TC[A]]): TC[A] = { | ||
if (st == StandardType.StringType) { | ||
new TC[A] { | ||
def name(a: A): String = a.asInstanceOf[String] | ||
} | ||
} else { | ||
??? | ||
} | ||
} | ||
|
||
override def deriveOption[A](option: Schema.Optional[A], inner: => TC[A], summoned: => Option[TC[Option[A]]]): TC[Option[A]] = ??? | ||
|
||
override def deriveSequence[C[_], A](sequence: Schema.Sequence[C[A], A, _], inner: => TC[A], summoned: => Option[TC[C[A]]]): TC[C[A]] = ??? | ||
|
||
override def deriveMap[K, V](map: Schema.Map[K, V], key: => TC[K], value: => TC[V], summoned: => Option[TC[Map[K, V]]]): TC[Map[K, V]] = ??? | ||
|
||
override def deriveTransformedRecord[A, B]( | ||
record: Schema.Record[A], | ||
transform: Schema.Transform[A, B, _], | ||
fields: => Chunk[Deriver.WrappedF[TC, _]], | ||
summoned: => Option[TC[B]] | ||
): TC[B] = ??? | ||
} | ||
|
||
given TC[AnotherObject.MyId] = deriver.derive | ||
|
||
def show[A](a: A)(using ev: TC[A]): String = | ||
ev.name(a) | ||
|
||
assert(show(AnotherObject.MyId("abc")))(equalTo("abc")) | ||
} | ||
) | ||
} | ||
|
||
object VersionSpecificDeriveSpec { | ||
object AnotherObject { | ||
opaque type MyId = String | ||
|
||
object MyId { | ||
def apply(s: String): MyId = s | ||
|
||
given(using ev: Schema[String]): Schema[MyId] = ev | ||
} | ||
} | ||
|
||
trait TC[A] { | ||
def name(a: A): String | ||
} | ||
} |
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