Skip to content

Commit

Permalink
Run all possible test for all Scala 3 (#709) (#721)
Browse files Browse the repository at this point in the history
  • Loading branch information
987Nabil authored Aug 9, 2024
1 parent 5a276f7 commit eb71680
Show file tree
Hide file tree
Showing 40 changed files with 282 additions and 260 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import zio.test.Gen

object PlatformSpecificGen {

val platformSpecificStandardTypes: Gen[Any, StandardType[_]] = Gen.fromIterable(
val platformSpecificStandardTypes: Gen[Any, StandardType[Any]] = Gen.fromIterable(
List.empty
)

def platformSpecificStandardTypeAndGen(standardTypeGen: StandardType[_]): StandardTypeAndGen[_] =
def platformSpecificStandardTypeAndGen(standardTypeGen: StandardType[Any]): StandardTypeAndGen[Any] =
standardTypeGen match {
case _ => StandardType.UnitType -> Gen.unit: StandardTypeAndGen[_]
case _ => StandardType.UnitType.asInstanceOf[StandardType[Any]] -> Gen.unit
}

val platformSpecificSchemasAndGens: List[SchemaTest[_]] = List.empty
val platformSpecificSchemasAndGens: List[SchemaTest[Any]] = List.empty
}
24 changes: 0 additions & 24 deletions tests/jvm/src/test/scala-2/zio/schema/PlatformSpecificGen.scala

This file was deleted.

24 changes: 24 additions & 0 deletions tests/jvm/src/test/scala/zio/schema/PlatformSpecificGen.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package zio.schema

import zio.schema.SchemaGen.SchemaTest
import zio.schema.StandardTypeGen.StandardTypeAndGen
import zio.test.Gen

object PlatformSpecificGen {

val platformSpecificStandardTypes: Gen[Any, StandardType[Any]] = Gen.fromIterable(
List(
StandardType.CurrencyType
).map(_.asInstanceOf[StandardType[Any]])
)

def platformSpecificStandardTypeAndGen(standardTypeGen: StandardType[Any]): StandardTypeAndGen[Any] =
standardTypeGen match {
case typ if typ.isInstanceOf[StandardType.CurrencyType.type] => typ -> Gen.currency
case _ => StandardType.UnitType.asInstanceOf[StandardType[Any]] -> Gen.unit
}

val platformSpecificSchemasAndGens: List[SchemaTest[Any]] = List(
SchemaTest("Currency", StandardType.CurrencyType.asInstanceOf[StandardType[Any]], Gen.currency)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import zio.test.Gen

object PlatformSpecificGen {

val platformSpecificStandardTypes: Gen[Any, StandardType[_]] = Gen.fromIterable(
val platformSpecificStandardTypes: Gen[Any, StandardType[Any]] = Gen.fromIterable(
List.empty
)

def platformSpecificStandardTypeAndGen(standardTypeGen: StandardType[_]): StandardTypeAndGen[_] =
def platformSpecificStandardTypeAndGen(standardTypeGen: StandardType[Any]): StandardTypeAndGen[Any] =
standardTypeGen match {
case _ => StandardType.UnitType -> Gen.unit: StandardTypeAndGen[_]
case _ => StandardType.UnitType.asInstanceOf[StandardType[Any]] -> Gen.unit
}

val platformSpecificSchemasAndGens: List[SchemaTest[_]] = List.empty
val platformSpecificSchemasAndGens: List[SchemaTest[Any]] = List.empty
}
87 changes: 0 additions & 87 deletions tests/shared/src/test/scala-2/zio/schema/StandardTypeGen.scala

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import zio.schema.SchemaGen.Json.schema
import zio.test._

object AccessorBuilderSpec extends ZIOSpecDefault {
import TestAccessorBuilder._
import Assertion._
import TestAccessorBuilder._

private val builder: TestAccessorBuilder = new TestAccessorBuilder

Expand Down Expand Up @@ -70,15 +70,12 @@ object AccessorBuilderSpec extends ZIOSpecDefault {

val accessor = tupleSchema.makeAccessors(builder)

assert(
accessor match {
case (Lens(r1, f1), Lens(r2, f2)) =>
r1 == r2 && r2 == tupleSchema.toRecord &&
f1.name == "_1" && f1.schema == leftSchema &&
f2.name == "_2" && f2.schema == rightSchema
case _ => false
}
)(isTrue)
assertTrue(accessor match {
case (Lens(r1, f1), Lens(r2, f2)) =>
r1 == r2 && r2 == tupleSchema.toRecord &&
f1.name == "_1" && f1.schema == leftSchema &&
f2.name == "_2" && f2.schema == rightSchema
})
}
},
test("either") {
Expand Down Expand Up @@ -122,8 +119,6 @@ object AccessorBuilderSpec extends ZIOSpecDefault {
accessor match {
case (Lens(r1, f1), Lens(r2, f2), Lens(r3, f3)) =>
r1 == schema && r2 == schema && r3 == schema && f1 == schema.field1 && f2 == schema.field2 && f3 == schema.field3
case _ => false

}
)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ object DynamicValueGen {
case Schema.Either(left, right, _) =>
Gen.oneOf(anyDynamicLeftValueOfSchema(left), anyDynamicRightValueOfSchema(right))
case Schema.Fallback(left, right, _, _) =>
Gen.oneOf(anyDynamicLeftValueOfSchema(left), anyDynamicRightValueOfSchema(right), anyDynamicBothValueOfSchema(left, right))
Gen.oneOf[Sized, DynamicValue](
anyDynamicLeftValueOfSchema(left.asInstanceOf[Schema[Any]]),
anyDynamicRightValueOfSchema(right.asInstanceOf[Schema[Any]]),
anyDynamicBothValueOfSchema(left.asInstanceOf[Schema[Any]], right.asInstanceOf[Schema[Any]])
)
case Schema.Transform(schema, _, _, _, _) => anyDynamicValueOfSchema(schema)
case Schema.Fail(message, _) => Gen.const(DynamicValue.Error(message))
case l @ Schema.Lazy(_) => anyDynamicValueOfSchema(l.schema)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ object OrderingSpec extends ZIOSpecDefault {
assert(schemaOrdering.compare(l, r))(equalTo(standardType.compare(l, r)))
}

case class StructureTestCase(name: String, increasingPairGen: Gen[Sized, SchemaAndPair[_]])
case class StructureTestCase(name: String, increasingPairGen: Gen[Sized, SchemaAndPair[Any]])

private val structureTestCases =
Seq(
Expand All @@ -72,11 +72,11 @@ object OrderingSpec extends ZIOSpecDefault {
assert(schema.ordering.compare(l, r))(isLessThan(0))
}))

def genAnyOrderedPairOption: Gen[Sized, SchemaAndPair[Option[_]]] =
def genAnyOrderedPairOption: Gen[Sized, SchemaAndPair[Any]] =
for {
schema <- anySchema
(l, r) <- genOrderedPairOption(schema)
} yield (Schema.Optional(schema), l, r).asInstanceOf[SchemaAndPair[Option[_]]]
} yield (Schema.Optional(schema), l, r).asInstanceOf[SchemaAndPair[Any]]

def genOrderedPairOption[A](schema: Schema[A]): Gen[Sized, (Option[A], Option[A])] =
Gen.oneOf(
Expand All @@ -88,12 +88,12 @@ object OrderingSpec extends ZIOSpecDefault {
} yield (None, Some(a))
)

def genAnyOrderedPairEither: Gen[Sized, SchemaAndPair[Either[_, _]]] =
def genAnyOrderedPairEither: Gen[Sized, SchemaAndPair[Any]] =
for {
leftSchema <- anySchema
rightSchema <- anySchema
(l, r) <- genOrderedPairEither(leftSchema, rightSchema)
} yield (Schema.Either(leftSchema, rightSchema), l, r).asInstanceOf[SchemaAndPair[Either[_, _]]]
} yield (Schema.Either(leftSchema, rightSchema), l, r).asInstanceOf[SchemaAndPair[Any]]

def genOrderedPairEither[A, B](
lSchema: Schema[A],
Expand All @@ -111,12 +111,12 @@ object OrderingSpec extends ZIOSpecDefault {
} yield (Left(l), Right(r))
)

def genAnyOrderedPairTuple: Gen[Sized, SchemaAndPair[_]] =
def genAnyOrderedPairTuple: Gen[Sized, SchemaAndPair[Any]] =
for {
xSchema <- anySchema
ySchema <- anySchema
(l, r) <- genOrderedPairTuple(xSchema, ySchema)
} yield (Schema.Tuple2(xSchema, ySchema), l, r).asInstanceOf[SchemaAndPair[Either[_, _]]]
} yield (Schema.Tuple2(xSchema, ySchema), l, r).asInstanceOf[SchemaAndPair[Any]]

def genOrderedPairTuple[A, B](
xSchema: Schema[A],
Expand All @@ -134,17 +134,17 @@ object OrderingSpec extends ZIOSpecDefault {
} yield ((x, smallY), (x, largeY))
)

def genAnyOrderedPairChunks: Gen[Sized, SchemaAndPair[_]] =
def genAnyOrderedPairChunks: Gen[Sized, SchemaAndPair[Any]] =
anySchema.flatMap(genOrderedPairChunk(_))

def genOrderedPairChunk[A](schema: Schema[A]): Gen[Sized, SchemaAndPair[_]] =
def genOrderedPairChunk[A](schema: Schema[A]): Gen[Sized, SchemaAndPair[Any]] =
for {
init <- Gen.chunkOf(genFromSchema(schema))
rems <- Gen.oneOf(
genChunkPairWithOrderedFirstElement(schema),
genChunkPairWithOnlyFirstEmpty(schema)
)
} yield (Schema.chunk(schema), init ++ rems._1, init ++ rems._2)
} yield (Schema.chunk(schema), init ++ rems._1, init ++ rems._2).asInstanceOf[SchemaAndPair[Any]]

def genChunkPairWithOrderedFirstElement[A](
schema: Schema[A]
Expand All @@ -161,20 +161,22 @@ object OrderingSpec extends ZIOSpecDefault {
rem <- Gen.chunkOf(genFromSchema(schema))
} yield (Chunk(), init +: rem)

def genAnyOrderedPairTransform: Gen[Sized, SchemaAndPair[_]] =
Gen.oneOf(
anySchema.flatMap(genOrderedPairIdentityTransform(_)),
anySchema.flatMap(genOrderedPairDecodeTransform(_))
)
def genAnyOrderedPairTransform: Gen[Sized, SchemaAndPair[Any]] =
Gen
.oneOf(
anySchema.flatMap(genOrderedPairIdentityTransform(_)),
anySchema.flatMap(genOrderedPairDecodeTransform(_))
)
.asInstanceOf[Gen[Sized, SchemaAndPair[Any]]]

def genOrderedPairIdentityTransform[A](schema: Schema[A]): Gen[Sized, SchemaAndPair[_]] =
def genOrderedPairIdentityTransform[A](schema: Schema[A]): Gen[Sized, SchemaAndPair[Any]] =
for {
(small, large) <- genOrderedPair(schema)
} yield (schema.transformOrFail({ (a: A) =>
Right(a)
}, { (a: A) =>
Right(a)
}), small, large)
}), small, large).asInstanceOf[SchemaAndPair[Any]]

def genOrderedPairDecodeTransform[A](
schema: Schema[A]
Expand All @@ -189,14 +191,14 @@ object OrderingSpec extends ZIOSpecDefault {
largeEncoded = encode(large).toOption.get
} yield (schema.transformOrFail(encode, decode), smallEncodedOrError, largeEncoded)

def genAnyOrderedPairRecord: Gen[Sized, SchemaAndPair[_]] =
def genAnyOrderedPairRecord: Gen[Sized, SchemaAndPair[Any]] =
for {
name <- Gen.string(Gen.alphaChar).map(TypeId.parse)
schema <- anyStructure(anyTree(1)).map(fieldSet => {
Schema.GenericRecord(name, fieldSet)
})
pair <- genOrderedPairRecord(schema)
} yield pair
} yield pair.asInstanceOf[SchemaAndPair[Any]]

def genOrderedPairRecord[A](schema: Schema.Record[A]): Gen[Sized, SchemaAndPair[A]] = {
val fields: Chunk[Schema.Field[A, _]] = schema.fields
Expand Down Expand Up @@ -257,13 +259,15 @@ object OrderingSpec extends ZIOSpecDefault {
} yield (field.name, dx, dy) +: rem
}

def genAnyOrderedPairEnum: Gen[Sized, SchemaAndPair[_]] =
anyEnumSchema.flatMap(schema => {
Gen.oneOf(
genOrderedPairEnumSameCase(schema),
genOrderedPairEnumDiffCase(schema)
)
})
def genAnyOrderedPairEnum: Gen[Sized, SchemaAndPair[Any]] =
anyEnumSchema
.flatMap(schema => {
Gen.oneOf(
genOrderedPairEnumSameCase(schema),
genOrderedPairEnumDiffCase(schema)
)
})
.asInstanceOf[Gen[Sized, SchemaAndPair[Any]]]

def genOrderedPairEnumSameCase[A](schema: Schema.Enum[A]): Gen[Sized, SchemaAndPair[A]] =
for {
Expand Down Expand Up @@ -305,7 +309,7 @@ object OrderingSpec extends ZIOSpecDefault {
.anyDynamicValueOfSchema(schema)
.map(d => schema.fromDynamic(d).toOption.get)

def genAnyOrderedPair: Gen[Sized, SchemaAndPair[_]] =
def genAnyOrderedPair: Gen[Sized, SchemaAndPair[Any]] =
for {
schema <- anySchema
(x, y) <- genOrderedPair(schema)
Expand All @@ -326,7 +330,7 @@ object OrderingSpec extends ZIOSpecDefault {
DynamicValue.fromSchemaAndValue(schema, large.asInstanceOf[A])
)

def genAnyOrderedTriplet: Gen[Sized, SchemaAndTriplet[_]] =
def genAnyOrderedTriplet: Gen[Sized, SchemaAndTriplet[Any]] =
for {
schema <- anySchema
(x, y, z) <- genOrderedTriplet(schema)
Expand Down
Loading

0 comments on commit eb71680

Please sign in to comment.