diff --git a/tests/js/src/test/scala-2/zio/schema/PlatformSpecificGen.scala b/tests/js/src/test/scala/zio/schema/PlatformSpecificGen.scala similarity index 50% rename from tests/js/src/test/scala-2/zio/schema/PlatformSpecificGen.scala rename to tests/js/src/test/scala/zio/schema/PlatformSpecificGen.scala index 941b41d24..490027d60 100644 --- a/tests/js/src/test/scala-2/zio/schema/PlatformSpecificGen.scala +++ b/tests/js/src/test/scala/zio/schema/PlatformSpecificGen.scala @@ -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 } diff --git a/tests/jvm/src/test/scala-2/zio/schema/PlatformSpecificGen.scala b/tests/jvm/src/test/scala-2/zio/schema/PlatformSpecificGen.scala deleted file mode 100644 index ceeb2381c..000000000 --- a/tests/jvm/src/test/scala-2/zio/schema/PlatformSpecificGen.scala +++ /dev/null @@ -1,24 +0,0 @@ -package zio.schema - -import zio.schema.SchemaGen.SchemaTest -import zio.schema.StandardTypeGen.StandardTypeAndGen -import zio.test.Gen - -object PlatformSpecificGen { - - val platformSpecificStandardTypes: Gen[Any, StandardType[_]] = Gen.fromIterable( - List( - StandardType.CurrencyType - ) - ) - - def platformSpecificStandardTypeAndGen(standardTypeGen: StandardType[_]): StandardTypeAndGen[_] = - standardTypeGen match { - case typ: StandardType.CurrencyType.type => typ -> Gen.currency - case _ => StandardType.UnitType -> Gen.unit: StandardTypeAndGen[_] - } - - val platformSpecificSchemasAndGens: List[SchemaTest[_]] = List( - SchemaTest("Currency", StandardType.CurrencyType, Gen.currency) - ) -} diff --git a/tests/jvm/src/test/scala/zio/schema/PlatformSpecificGen.scala b/tests/jvm/src/test/scala/zio/schema/PlatformSpecificGen.scala new file mode 100644 index 000000000..97da5edb9 --- /dev/null +++ b/tests/jvm/src/test/scala/zio/schema/PlatformSpecificGen.scala @@ -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) + ) +} diff --git a/tests/native/src/test/scala-2/zio/schema/PlatformSpecificGen.scala b/tests/native/src/test/scala/zio/schema/PlatformSpecificGen.scala similarity index 50% rename from tests/native/src/test/scala-2/zio/schema/PlatformSpecificGen.scala rename to tests/native/src/test/scala/zio/schema/PlatformSpecificGen.scala index 941b41d24..490027d60 100644 --- a/tests/native/src/test/scala-2/zio/schema/PlatformSpecificGen.scala +++ b/tests/native/src/test/scala/zio/schema/PlatformSpecificGen.scala @@ -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 } diff --git a/tests/shared/src/test/scala-2/zio/schema/StandardTypeGen.scala b/tests/shared/src/test/scala-2/zio/schema/StandardTypeGen.scala deleted file mode 100644 index 98a5570be..000000000 --- a/tests/shared/src/test/scala-2/zio/schema/StandardTypeGen.scala +++ /dev/null @@ -1,87 +0,0 @@ -package zio.schema - -import java.math.{ BigDecimal => JBigDecimal, BigInteger => JBigInt } - -import zio.schema.PlatformSpecificGen.{ platformSpecificStandardTypeAndGen, platformSpecificStandardTypes } -import zio.test.{ Gen, Sized } - -object StandardTypeGen { - - //IMPORTANT! - Updating the following list without updating the schema primitive case set in zio.schema.DynamicValue.schema will trigger a set of very obscure test failures - val anyStandardType: Gen[Any, StandardType[_]] = Gen.fromIterable( - List( - StandardType.StringType, - StandardType.BoolType, - StandardType.ShortType, - StandardType.IntType, - StandardType.LongType, - StandardType.FloatType, - StandardType.DoubleType, - StandardType.BinaryType, - StandardType.BigDecimalType, - StandardType.BigIntegerType, - StandardType.CharType, - StandardType.UUIDType, - StandardType.DayOfWeekType, - StandardType.DurationType, - StandardType.InstantType, - StandardType.LocalDateType, - StandardType.LocalDateTimeType, - StandardType.LocalTimeType, - StandardType.MonthType, - StandardType.MonthDayType, - StandardType.OffsetDateTimeType, - StandardType.OffsetTimeType, - StandardType.PeriodType, - StandardType.YearType, - StandardType.YearMonthType, - StandardType.ZonedDateTimeType, - StandardType.ZoneIdType, - StandardType.ZoneOffsetType - ) - ) ++ platformSpecificStandardTypes - - val javaBigInt: Gen[Any, JBigInt] = - Gen.bigInt(JBigInt.valueOf(Long.MinValue), JBigInt.valueOf(Long.MaxValue)).map { sBigInt => - new JBigInt(sBigInt.toByteArray) - } - - val javaBigDecimal: Gen[Any, JBigDecimal] = - Gen.bigDecimal(JBigDecimal.valueOf(Long.MinValue), JBigDecimal.valueOf(Long.MaxValue)).map(_.bigDecimal) - - type StandardTypeAndGen[A] = (StandardType[A], Gen[Sized, A]) - - val anyStandardTypeAndGen: Gen[Any, StandardTypeAndGen[_]] = { - anyStandardType.map { - case typ: StandardType.StringType.type => typ -> Gen.string - case typ: StandardType.BoolType.type => typ -> Gen.boolean - case typ: StandardType.ShortType.type => typ -> Gen.short - case typ: StandardType.IntType.type => typ -> Gen.int - case typ: StandardType.LongType.type => typ -> Gen.long - case typ: StandardType.FloatType.type => typ -> Gen.float - case typ: StandardType.DoubleType.type => typ -> Gen.double - case typ: StandardType.BinaryType.type => typ -> Gen.chunkOf(Gen.byte) - case typ: StandardType.CharType.type => typ -> Gen.asciiChar - case typ: StandardType.UUIDType.type => typ -> Gen.uuid - case typ: StandardType.BigDecimalType.type => typ -> javaBigDecimal - case typ: StandardType.BigIntegerType.type => typ -> javaBigInt - case typ: StandardType.DayOfWeekType.type => typ -> JavaTimeGen.anyDayOfWeek - case typ: StandardType.DurationType.type => typ -> JavaTimeGen.anyDuration - case typ: StandardType.InstantType.type => typ -> JavaTimeGen.anyInstant - case typ: StandardType.LocalDateType.type => typ -> JavaTimeGen.anyLocalDate - case typ: StandardType.LocalDateTimeType.type => typ -> JavaTimeGen.anyLocalDateTime - case typ: StandardType.LocalTimeType.type => typ -> JavaTimeGen.anyLocalTime - case typ: StandardType.MonthType.type => typ -> JavaTimeGen.anyMonth - case typ: StandardType.MonthDayType.type => typ -> JavaTimeGen.anyMonthDay - case typ: StandardType.OffsetDateTimeType.type => typ -> JavaTimeGen.anyOffsetDateTime - case typ: StandardType.OffsetTimeType.type => typ -> JavaTimeGen.anyOffsetTime - case typ: StandardType.PeriodType.type => typ -> JavaTimeGen.anyPeriod - case typ: StandardType.YearType.type => typ -> JavaTimeGen.anyYear - case typ: StandardType.YearMonthType.type => typ -> JavaTimeGen.anyYearMonth - case typ: StandardType.ZonedDateTimeType.type => typ -> JavaTimeGen.anyZonedDateTime - case typ: StandardType.ZoneIdType.type => typ -> JavaTimeGen.anyZoneId - case typ: StandardType.ZoneOffsetType.type => typ -> JavaTimeGen.anyZoneOffset - case typ => platformSpecificStandardTypeAndGen(typ) - } - } -} diff --git a/tests/shared/src/test/scala-2/zio/schema/AccessorBuilderSpec.scala b/tests/shared/src/test/scala/zio/schema/AccessorBuilderSpec.scala similarity index 92% rename from tests/shared/src/test/scala-2/zio/schema/AccessorBuilderSpec.scala rename to tests/shared/src/test/scala/zio/schema/AccessorBuilderSpec.scala index 867d7ff29..771e609db 100644 --- a/tests/shared/src/test/scala-2/zio/schema/AccessorBuilderSpec.scala +++ b/tests/shared/src/test/scala/zio/schema/AccessorBuilderSpec.scala @@ -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 @@ -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") { @@ -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 - } ) }, diff --git a/tests/shared/src/test/scala-2/zio/schema/DynamicValueGen.scala b/tests/shared/src/test/scala/zio/schema/DynamicValueGen.scala similarity index 98% rename from tests/shared/src/test/scala-2/zio/schema/DynamicValueGen.scala rename to tests/shared/src/test/scala/zio/schema/DynamicValueGen.scala index d5a5e73d4..d17941483 100644 --- a/tests/shared/src/test/scala-2/zio/schema/DynamicValueGen.scala +++ b/tests/shared/src/test/scala/zio/schema/DynamicValueGen.scala @@ -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) diff --git a/tests/shared/src/test/scala-2/zio/schema/DynamicValueSpec.scala b/tests/shared/src/test/scala/zio/schema/DynamicValueSpec.scala similarity index 100% rename from tests/shared/src/test/scala-2/zio/schema/DynamicValueSpec.scala rename to tests/shared/src/test/scala/zio/schema/DynamicValueSpec.scala diff --git a/tests/shared/src/test/scala-2/zio/schema/MetaSchemaSpec.scala b/tests/shared/src/test/scala/zio/schema/MetaSchemaSpec.scala similarity index 100% rename from tests/shared/src/test/scala-2/zio/schema/MetaSchemaSpec.scala rename to tests/shared/src/test/scala/zio/schema/MetaSchemaSpec.scala diff --git a/tests/shared/src/test/scala-2/zio/schema/OrderingSpec.scala b/tests/shared/src/test/scala/zio/schema/OrderingSpec.scala similarity index 90% rename from tests/shared/src/test/scala-2/zio/schema/OrderingSpec.scala rename to tests/shared/src/test/scala/zio/schema/OrderingSpec.scala index 2e33499d3..8e2edbbbe 100644 --- a/tests/shared/src/test/scala-2/zio/schema/OrderingSpec.scala +++ b/tests/shared/src/test/scala/zio/schema/OrderingSpec.scala @@ -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( @@ -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( @@ -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], @@ -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], @@ -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] @@ -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] @@ -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 @@ -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 { @@ -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) @@ -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) diff --git a/tests/shared/src/test/scala-2/zio/schema/PatchSpec.scala b/tests/shared/src/test/scala/zio/schema/PatchSpec.scala similarity index 99% rename from tests/shared/src/test/scala-2/zio/schema/PatchSpec.scala rename to tests/shared/src/test/scala/zio/schema/PatchSpec.scala index 07701496e..c04e4272d 100644 --- a/tests/shared/src/test/scala-2/zio/schema/PatchSpec.scala +++ b/tests/shared/src/test/scala/zio/schema/PatchSpec.scala @@ -148,7 +148,7 @@ object PatchSpec extends ZIOSpecDefault { } val finalTestName = renamingFuncOption.fold(name)(renamingFunc => renamingFunc(name)) standardType match { - case _ @StandardType.MonthDayType => + case s if s.isInstanceOf[StandardType.MonthDayType.type] => test(finalTestName) { patchingFunc(finalSchema) } @@ TestAspect.ignore // TODO Leap years! diff --git a/tests/shared/src/test/scala-2/zio/schema/SchemaGen.scala b/tests/shared/src/test/scala/zio/schema/SchemaGen.scala similarity index 82% rename from tests/shared/src/test/scala-2/zio/schema/SchemaGen.scala rename to tests/shared/src/test/scala/zio/schema/SchemaGen.scala index 46405ce2c..41f5c6116 100644 --- a/tests/shared/src/test/scala-2/zio/schema/SchemaGen.scala +++ b/tests/shared/src/test/scala/zio/schema/SchemaGen.scala @@ -50,8 +50,8 @@ object SchemaGen { .map(_.toSeq) def anyEnumeration( - schemaGen: Gen[Sized, Schema[_]] - ): Gen[Sized, ListMap[String, Schema[_]]] = + schemaGen: Gen[Sized, Schema[Any]] + ): Gen[Sized, ListMap[String, Schema[Any]]] = Gen .setOfBounded(1, 3)( anyLabel.zip(schemaGen) @@ -61,19 +61,19 @@ object SchemaGen { def anyEnumeration[A](schema: Schema[A]): Gen[Sized, ListMap[String, Schema[A]]] = Gen.setOfBounded(1, 3)(anyLabel.map(_ -> schema)).map(ListMap.empty ++ _) - val anyPrimitive: Gen[Any, Schema.Primitive[_]] = + val anyPrimitive: Gen[Any, Schema.Primitive[Any]] = StandardTypeGen.anyStandardType.map(Schema.Primitive(_, Chunk.empty)) type PrimitiveAndGen[A] = (Schema.Primitive[A], Gen[Sized, A]) - val anyPrimitiveAndGen: Gen[Any, PrimitiveAndGen[_]] = + val anyPrimitiveAndGen: Gen[Any, PrimitiveAndGen[Any]] = StandardTypeGen.anyStandardTypeAndGen.map { case (standardType, gen) => Schema.Primitive(standardType, Chunk.empty) -> gen } type PrimitiveAndValue[A] = (Schema.Primitive[A], A) - val anyPrimitiveAndValue: Gen[Sized, PrimitiveAndValue[_]] = + val anyPrimitiveAndValue: Gen[Sized, PrimitiveAndValue[Any]] = for { (schema, gen) <- anyPrimitiveAndGen value <- gen @@ -86,20 +86,20 @@ object SchemaGen { type OptionalAndGen[A] = (Schema.Optional[A], Gen[Sized, Option[A]]) - val anyOptionalAndGen: Gen[Sized, OptionalAndGen[_]] = + val anyOptionalAndGen: Gen[Sized, OptionalAndGen[Any]] = anyPrimitiveAndGen.map { case (schema, gen) => Schema.Optional(schema) -> Gen.option(gen) } type OptionalAndValue[A] = (Schema.Optional[A], Option[A]) - val anyOptionalAndValue: Gen[Sized, OptionalAndValue[_]] = + val anyOptionalAndValue: Gen[Sized, OptionalAndValue[Any]] = for { (schema, gen) <- anyOptionalAndGen value <- gen } yield schema -> value - val anyEither: Gen[Sized, Schema.Either[_, _]] = + val anyEither: Gen[Sized, Schema.Either[Any, Any]] = for { left <- anyPrimitive right <- anyPrimitive @@ -107,7 +107,7 @@ object SchemaGen { type EitherAndGen[A, B] = (Schema.Either[A, B], Gen[Sized, scala.util.Either[A, B]]) - val anyEitherAndGen: Gen[Sized, EitherAndGen[_, _]] = + val anyEitherAndGen: Gen[Sized, EitherAndGen[Any, Any]] = for { (leftSchema, leftGen) <- anyPrimitiveAndGen (rightSchema, rightGen) <- anyPrimitiveAndGen @@ -115,13 +115,13 @@ object SchemaGen { type EitherAndValue[A, B] = (Schema.Either[A, B], scala.util.Either[A, B]) - val anyEitherAndValue: Gen[Sized, EitherAndValue[_, _]] = + val anyEitherAndValue: Gen[Sized, EitherAndValue[Any, Any]] = for { (schema, gen) <- anyEitherAndGen value <- gen } yield (schema, value) - def anyFallback(fullDecode: Boolean): Gen[Sized, Schema.Fallback[_, _]] = + def anyFallback(fullDecode: Boolean): Gen[Sized, Schema.Fallback[Any, Any]] = for { left <- anyPrimitive right <- anyPrimitive @@ -129,7 +129,7 @@ object SchemaGen { type FallbackAndGen[A, B] = (Schema.Fallback[A, B], Gen[Sized, Fallback[A, B]]) - def anyFallbackAndGen(fullDecode: Boolean): Gen[Sized, FallbackAndGen[_, _]] = + def anyFallbackAndGen(fullDecode: Boolean): Gen[Sized, FallbackAndGen[Any, Any]] = for { (leftSchema, leftGen) <- anyPrimitiveAndGen (rightSchema, rightGen) <- anyPrimitiveAndGen @@ -142,20 +142,20 @@ object SchemaGen { type FallbackAndValue[A, B] = (Schema.Fallback[A, B], Fallback[A, B]) - def anyFallbackAndValue(fullDecode: Boolean): Gen[Sized, FallbackAndValue[_, _]] = + def anyFallbackAndValue(fullDecode: Boolean): Gen[Sized, FallbackAndValue[Any, Any]] = for { (schema, gen) <- anyFallbackAndGen(fullDecode) value <- gen } yield (schema, value) - lazy val anyTuple: Gen[Sized, Schema.Tuple2[_, _]] = + lazy val anyTuple: Gen[Sized, Schema.Tuple2[Any, Any]] = anySchema.zipWith(anySchema) { (a, b) => Schema.Tuple2(a, b) } type TupleAndGen[A, B] = (Schema.Tuple2[A, B], Gen[Sized, (A, B)]) - val anyTupleAndGen: Gen[Sized, TupleAndGen[_, _]] = + val anyTupleAndGen: Gen[Sized, TupleAndGen[Any, Any]] = for { (schemaA, genA) <- anyPrimitiveAndGen (schemaB, genB) <- anyPrimitiveAndGen @@ -163,7 +163,7 @@ object SchemaGen { type TupleAndValue[A, B] = (Schema.Tuple2[A, B], (A, B)) - val anyTupleAndValue: Gen[Sized, TupleAndValue[_, _]] = + val anyTupleAndValue: Gen[Sized, TupleAndValue[Any, Any]] = for { (schema, gen) <- anyTupleAndGen (valueA, valueB) <- gen @@ -174,7 +174,7 @@ object SchemaGen { type SequenceAndGen[A] = (Schema[Chunk[A]], Gen[Sized, Chunk[A]]) - val anySequenceAndGen: Gen[Sized, SequenceAndGen[_]] = + val anySequenceAndGen: Gen[Sized, SequenceAndGen[Any]] = anyPrimitiveAndGen.map { case (schema, gen) => Schema.chunk(schema) -> Gen.chunkOf(gen) @@ -182,13 +182,13 @@ object SchemaGen { type SequenceAndValue[A] = (Schema[Chunk[A]], Chunk[A]) - val anySequenceAndValue: Gen[Sized, SequenceAndValue[_]] = + val anySequenceAndValue: Gen[Sized, SequenceAndValue[Any]] = for { (schema, gen) <- anySequenceAndGen value <- gen } yield schema -> value - def toCaseSet(cases: ListMap[String, Schema[_]]): CaseSet.Aux[Any] = + def toCaseSet(cases: ListMap[String, Schema[Any]]): CaseSet.Aux[Any] = cases.foldRight[CaseSet.Aux[Any]](CaseSet.Empty[Any]()) { case ((id, codec), acc) => val _case = Schema.Case[Any, Any]( @@ -202,13 +202,13 @@ object SchemaGen { CaseSet.Cons(_case, acc) } - lazy val anyMap: Gen[Sized, Schema.Map[_, _]] = + lazy val anyMap: Gen[Sized, Schema.Map[Any, Any]] = anySchema.zipWith(anySchema) { (a, b) => Schema.Map(a, b, Chunk.empty) } type MapAndGen[K, V] = (Schema.Map[K, V], Gen[Sized, Map[K, V]]) - val anyMapAndGen: Gen[Sized, MapAndGen[_, _]] = + val anyMapAndGen: Gen[Sized, MapAndGen[Any, Any]] = for { (schemaK, genK) <- anyPrimitiveAndGen (schemaV, genV) <- anyPrimitiveAndGen @@ -218,7 +218,7 @@ object SchemaGen { type MapAndValue[K, V] = (Schema.Map[K, V], Map[K, V]) - val anyMapAndValue: Gen[Sized, MapAndValue[_, _]] = + val anyMapAndValue: Gen[Sized, MapAndValue[Any, Any]] = for { (schema, gen) <- anyMapAndGen map <- gen @@ -226,7 +226,7 @@ object SchemaGen { type SetAndGen[A] = (Schema.Set[A], Gen[Sized, scala.collection.immutable.Set[A]]) - val anySetAndGen: Gen[Sized, SetAndGen[_]] = + val anySetAndGen: Gen[Sized, SetAndGen[Any]] = anyPrimitiveAndGen.map { case (schema, gen) => Schema.Set(schema, Chunk.empty) -> Gen.setOf(gen) @@ -234,7 +234,7 @@ object SchemaGen { type SetAndValue[A] = (Schema.Set[A], scala.collection.immutable.Set[A]) - val anySetAndValue: Gen[Sized, SetAndValue[_]] = + val anySetAndValue: Gen[Sized, SetAndValue[Any]] = for { (schema, gen) <- anySetAndGen value <- gen @@ -327,16 +327,16 @@ object SchemaGen { type SequenceTransform[A] = Schema.Transform[Chunk[A], List[A], String] - val anySequenceTransform: Gen[Sized, SequenceTransform[_]] = { + val anySequenceTransform: Gen[Sized, SequenceTransform[Any]] = { anySequence.map(schema => transformSequence(schema)) } type SequenceTransformAndGen[A] = (SequenceTransform[A], Gen[Sized, List[A]]) - val anySequenceTransformAndGen: Gen[Sized, SequenceTransformAndGen[_]] = + val anySequenceTransformAndGen: Gen[Sized, SequenceTransformAndGen[Any]] = anyPrimitiveAndGen.map { case (schema, gen) => - transformSequence(Schema.chunk(schema)) -> Gen.listOf(gen) + transformSequence[Any](Schema.chunk(schema)) -> Gen.listOf(gen) } // TODO: Add some random Left values. @@ -351,7 +351,7 @@ object SchemaGen { type SequenceTransformAndValue[A] = (SequenceTransform[A], List[A]) - val anySequenceTransformAndValue: Gen[Sized, SequenceTransformAndValue[_]] = + val anySequenceTransformAndValue: Gen[Sized, SequenceTransformAndValue[Any]] = for { (schema, gen) <- anySequenceTransformAndGen value <- gen @@ -359,14 +359,14 @@ object SchemaGen { type RecordTransform[A] = Schema.Transform[ListMap[String, _], A, String] - val anyRecordTransform: Gen[Sized, RecordTransform[_]] = { + val anyRecordTransform: Gen[Sized, RecordTransform[Any]] = { anyRecord.map(schema => transformRecord(schema)) } type RecordTransformAndGen[A] = (RecordTransform[A], Gen[Sized, A]) // TODO: How do we generate a value of a type that we know nothing about? - val anyRecordTransformAndGen: Gen[Sized, RecordTransformAndGen[_]] = + val anyRecordTransformAndGen: Gen[Sized, RecordTransformAndGen[Any]] = Gen.empty // anyRecordAndGen.map { // case (schema, gen) => transformRecord(schema) -> gen @@ -384,7 +384,7 @@ object SchemaGen { type RecordTransformAndValue[A] = (RecordTransform[A], A) - val anyRecordTransformAndValue: Gen[Sized, RecordTransformAndValue[_]] = + val anyRecordTransformAndValue: Gen[Sized, RecordTransformAndValue[Any]] = for { (schema, gen) <- anyRecordTransformAndGen value <- gen @@ -392,21 +392,21 @@ object SchemaGen { type EnumerationTransform[A] = Schema.Transform[Any, A, String] - val anyEnumerationTransform: Gen[Sized, EnumerationTransform[_]] = { + val anyEnumerationTransform: Gen[Sized, EnumerationTransform[Any]] = { anyEnumeration.map(schema => transformEnumeration(schema)) } type EnumerationTransformAndGen[A] = (EnumerationTransform[A], Gen[Sized, A]) // TODO: How do we generate a value of a type that we know nothing about? - val anyEnumerationTransformAndGen: Gen[Sized, EnumerationTransformAndGen[_]] = + val anyEnumerationTransformAndGen: Gen[Sized, EnumerationTransformAndGen[Any]] = Gen.empty // anyEnumerationAndGen.map { // case (schema, gen) => transformEnumeration(schema) -> gen // } // TODO: Dynamically generate a sealed trait and case/value classes. - def transformEnumeration[A](schema: Schema[Any]): EnumerationTransform[_] = + def transformEnumeration[A](schema: Schema[Any]): EnumerationTransform[A] = Schema.Transform[Any, A, String]( schema, _ => Left("Not implemented."), @@ -417,7 +417,7 @@ object SchemaGen { type EnumerationTransformAndValue[A] = (EnumerationTransform[A], A) - val anyEnumerationTransformAndValue: Gen[Sized, EnumerationTransformAndValue[_]] = + val anyEnumerationTransformAndValue: Gen[Sized, EnumerationTransformAndValue[Any]] = for { (schema, gen) <- anyEnumerationTransformAndGen value <- gen @@ -429,25 +429,25 @@ object SchemaGen { anyEnumerationTransform ) - type TransformAndValue[A] = (Schema.Transform[_, A, String], A) + type TransformAndValue[A] = (Schema.Transform[Any, A, String], A) - val anyTransformAndValue: Gen[Sized, TransformAndValue[_]] = - Gen.oneOf[Sized, TransformAndValue[_]]( - anySequenceTransformAndValue + val anyTransformAndValue: Gen[Sized, TransformAndValue[Any]] = + Gen.oneOf[Sized, TransformAndValue[Any]]( + anySequenceTransformAndValue.asInstanceOf[Gen[Sized, TransformAndValue[Any]]] // anyRecordTransformAndValue, // anyEnumerationTransformAndValue ) - type TransformAndGen[A] = (Schema.Transform[_, A, String], Gen[Sized, A]) + type TransformAndGen[A] = (Schema.Transform[Any, A, String], Gen[Sized, A]) - val anyTransformAndGen: Gen[Sized, TransformAndGen[_]] = - Gen.oneOf[Sized, TransformAndGen[_]]( - anySequenceTransformAndGen, - anyRecordTransformAndGen, + val anyTransformAndGen: Gen[Sized, TransformAndGen[Any]] = + Gen.oneOf[Sized, TransformAndGen[Any]]( + anySequenceTransformAndGen.asInstanceOf[Gen[Sized, TransformAndGen[Any]]], + anyRecordTransformAndGen.asInstanceOf[Gen[Sized, TransformAndGen[Any]]], anyEnumerationTransformAndGen ) - lazy val anySchema: Gen[Sized, Schema[_]] = + lazy val anySchema: Gen[Sized, Schema[Any]] = for { treeDepth <- Gen.bounded(0, 2)(Gen.const(_)) tree <- anyTree(treeDepth) @@ -462,7 +462,7 @@ object SchemaGen { type SchemaAndValue[A] = (Schema[A], A) - lazy val anySchemaAndValue: Gen[Sized, SchemaAndValue[_]] = + lazy val anySchemaAndValue: Gen[Sized, SchemaAndValue[Any]] = for { schema <- anySchema dynamic <- DynamicValueGen.anyDynamicValueOfSchema(schema) @@ -556,7 +556,7 @@ object SchemaGen { Gen.const(Schema[Arity24]) ) - val anyCaseClassAndGen: Gen[Sized, CaseClassAndGen[_]] = + val anyCaseClassAndGen: Gen[Sized, CaseClassAndGen[Any]] = anyCaseClassSchema.map { case s @ Schema.CaseClass1(_, _, _, _) => (s -> anyArity1).asInstanceOf[CaseClassAndGen[Any]] case s @ Schema.CaseClass2(_, _, _, _, _) => (s -> anyArity2).asInstanceOf[CaseClassAndGen[Any]] @@ -564,7 +564,7 @@ object SchemaGen { case s => (s -> anyArity24).asInstanceOf[CaseClassAndGen[Any]] } - val anyCaseClassAndValue: Gen[Sized, CaseClassAndValue[_]] = + val anyCaseClassAndValue: Gen[Sized, CaseClassAndValue[Any]] = for { (schema, gen) <- anyCaseClassAndGen value <- gen @@ -576,61 +576,65 @@ object SchemaGen { lazy val anyEnumSchema: Gen[Any, Schema.Enum[Arity]] = Gen.const(Arity.arityEnumSchema) - val anyEnumAndGen: Gen[Sized, EnumAndGen[_]] = - anyEnumSchema.map(_ -> anyArity) + val anyEnumAndGen: Gen[Sized, EnumAndGen[Any]] = + anyEnumSchema.map(_ -> anyArity).asInstanceOf[Gen[Sized, EnumAndGen[Any]]] - val anyEnumAndValue: Gen[Sized, EnumAndValue[_]] = + val anyEnumAndValue: Gen[Sized, EnumAndValue[Any]] = for { (schema, gen) <- anyEnumAndGen value <- gen } yield schema -> value - lazy val anyLeaf: Gen[Sized, Schema[_]] = - Gen.oneOf( - anyPrimitive, - anyPrimitive.map(Schema.list(_)), - anyPrimitive.map(_.optional), - anyPrimitive.zip(anyPrimitive).map { case (l, r) => Schema.either(l, r) }, - anyPrimitive.zip(anyPrimitive).map { case (l, r) => Schema.tuple2(l, r) }, - anyStructure(anyPrimitive) - .zip(Gen.string(Gen.alphaChar).map(TypeId.parse)) - .map(z => Schema.record(z._2, z._1)), - Gen.const(Schema[Json]), + lazy val anyLeaf: Gen[Sized, Schema[Any]] = + Gen + .oneOf( + anyPrimitive, + anyPrimitive.map(Schema.list(_)), + anyPrimitive.map(_.optional), + anyPrimitive.zip(anyPrimitive).map { case (l, r) => Schema.either(l, r) }, + anyPrimitive.zip(anyPrimitive).map { case (l, r) => Schema.tuple2(l, r) }, + anyStructure(anyPrimitive) + .zip(Gen.string(Gen.alphaChar).map(TypeId.parse)) + .map(z => Schema.record(z._2, z._1)), + Gen.const(Schema[Json]), // anyEnumeration(anyPrimitive).map(toCaseSet).map(Schema.enumeration[Any, CaseSet.Aux[Any]](_)), - anyCaseClassSchema, - anyEnumSchema - ) + anyCaseClassSchema, + anyEnumSchema + ) + .asInstanceOf[Gen[Sized, Schema[Any]]] - def anyTree(depth: Int): Gen[Sized, Schema[_]] = + def anyTree(depth: Int): Gen[Sized, Schema[Any]] = if (depth == 0) anyLeaf else - Gen.oneOf( - anyTree(depth - 1).map(Schema.list(_)), - // Nested optional cause some issues. Ignore them for now: See https://github.com/zio/zio-schema/issues/68 - anyTree(depth - 1).map { - case s @ Schema.Optional(_, _) => s - case s => Schema.option(s) - }, - anyTree(depth - 1).zip(anyTree(depth - 1)).map { case (l, r) => Schema.either(l, r) }, - anyTree(depth - 1).zip(anyTree(depth - 1)).map { case (l, r) => Schema.tuple2(l, r) }, - anyStructure(anyTree(depth - 1)) - .zip(Gen.string(Gen.alphaChar).map(TypeId.parse)) - .map(z => Schema.record(z._2, z._1)), - Gen.const(Schema[Json]), - anyDynamic + Gen + .oneOf( + anyTree(depth - 1).map(Schema.list(_)), + // Nested optional cause some issues. Ignore them for now: See https://github.com/zio/zio-schema/issues/68 + anyTree(depth - 1).map { + case s if s.isInstanceOf[Schema.Optional[_]] => s + case s => Schema.option(s).asInstanceOf[Schema[Any]] + }, + anyTree(depth - 1).zip(anyTree(depth - 1)).map { case (l, r) => Schema.either(l, r) }, + anyTree(depth - 1).zip(anyTree(depth - 1)).map { case (l, r) => Schema.tuple2(l, r) }, + anyStructure(anyTree(depth - 1)) + .zip(Gen.string(Gen.alphaChar).map(TypeId.parse)) + .map(z => Schema.record(z._2, z._1)), + Gen.const(Schema[Json]), + anyDynamic // anyEnumeration(anyTree(depth - 1)).map(toCaseSet).map(Schema.enumeration[Any, CaseSet.Aux[Any]](_)) - ) + ) + .asInstanceOf[Gen[Sized, Schema[Any]]] type SchemaAndDerivedValue[A, B] = (Schema[A], Schema[B], Chunk[scala.util.Either[A, B]]) - lazy val anyLeafAndValue: Gen[Sized, SchemaAndValue[_]] = + lazy val anyLeafAndValue: Gen[Sized, SchemaAndValue[Any]] = for { schema <- anyLeaf value <- DynamicValueGen.anyDynamicValueOfSchema(schema) } yield (schema -> schema.fromDynamic(value).toOption.get).asInstanceOf[SchemaAndValue[Any]] - lazy val anyTreeAndValue: Gen[Sized, SchemaAndValue[_]] = + lazy val anyTreeAndValue: Gen[Sized, SchemaAndValue[Any]] = for { schema <- anyTree(1) value <- DynamicValueGen.anyDynamicValueOfSchema(schema) @@ -674,16 +678,16 @@ object SchemaGen { } } - lazy val anyRecursiveType: Gen[Sized, Schema[_]] = + lazy val anyRecursiveType: Gen[Sized, Schema[Json]] = Gen.const(Schema[Json]) - lazy val anyRecursiveTypeAndValue: Gen[Sized, SchemaAndValue[_]] = + lazy val anyRecursiveTypeAndValue: Gen[Sized, SchemaAndValue[Json]] = for { schema <- Gen.const(Schema[Json]) value <- Json.gen } yield (schema, value) - lazy val anyDeepRecursiveTypeAndValue: Gen[Sized, SchemaAndValue[_]] = + lazy val anyDeepRecursiveTypeAndValue: Gen[Sized, SchemaAndValue[Json]] = for { schema <- Gen.const(Schema[Json]) value <- Json.genDeep @@ -693,7 +697,7 @@ object SchemaGen { case class SchemaTest[A](name: String, schema: StandardType[A], gen: Gen[Sized, A]) - def schemasAndGens: List[SchemaTest[_]] = + def schemasAndGens: List[SchemaTest[Any]] = List( SchemaTest("String", StandardType.StringType, Gen.string), SchemaTest("Bool", StandardType.BoolType, Gen.boolean), @@ -752,5 +756,5 @@ object SchemaGen { SchemaTest("ZoneId", StandardType.ZoneIdType, JavaTimeGen.anyZoneId), SchemaTest("ZoneOffset", StandardType.ZoneOffsetType, JavaTimeGen.anyZoneOffset), SchemaTest("UnitType", StandardType.UnitType, Gen.unit) - ) ++ platformSpecificSchemasAndGens + ).asInstanceOf[List[SchemaTest[Any]]] ++ platformSpecificSchemasAndGens } diff --git a/tests/shared/src/test/scala-2/zio/schema/SchemaMigrationSpec.scala b/tests/shared/src/test/scala/zio/schema/SchemaMigrationSpec.scala similarity index 100% rename from tests/shared/src/test/scala-2/zio/schema/SchemaMigrationSpec.scala rename to tests/shared/src/test/scala/zio/schema/SchemaMigrationSpec.scala diff --git a/tests/shared/src/test/scala/zio/schema/StandardTypeGen.scala b/tests/shared/src/test/scala/zio/schema/StandardTypeGen.scala new file mode 100644 index 000000000..09cc588d8 --- /dev/null +++ b/tests/shared/src/test/scala/zio/schema/StandardTypeGen.scala @@ -0,0 +1,89 @@ +package zio.schema + +import java.math.{ BigDecimal => JBigDecimal, BigInteger => JBigInt } + +import zio.schema.PlatformSpecificGen.{ platformSpecificStandardTypeAndGen, platformSpecificStandardTypes } +import zio.test.{ Gen, Sized } + +object StandardTypeGen { + + //IMPORTANT! - Updating the following list without updating the schema primitive case set in zio.schema.DynamicValue.schema will trigger a set of very obscure test failures + val anyStandardType: Gen[Any, StandardType[Any]] = Gen.fromIterable( + List( + StandardType.StringType, + StandardType.BoolType, + StandardType.ShortType, + StandardType.IntType, + StandardType.LongType, + StandardType.FloatType, + StandardType.DoubleType, + StandardType.BinaryType, + StandardType.BigDecimalType, + StandardType.BigIntegerType, + StandardType.CharType, + StandardType.UUIDType, + StandardType.DayOfWeekType, + StandardType.DurationType, + StandardType.InstantType, + StandardType.LocalDateType, + StandardType.LocalDateTimeType, + StandardType.LocalTimeType, + StandardType.MonthType, + StandardType.MonthDayType, + StandardType.OffsetDateTimeType, + StandardType.OffsetTimeType, + StandardType.PeriodType, + StandardType.YearType, + StandardType.YearMonthType, + StandardType.ZonedDateTimeType, + StandardType.ZoneIdType, + StandardType.ZoneOffsetType + ).asInstanceOf[List[StandardType[Any]]] + ) ++ platformSpecificStandardTypes + + val javaBigInt: Gen[Any, JBigInt] = + Gen.bigInt(JBigInt.valueOf(Long.MinValue), JBigInt.valueOf(Long.MaxValue)).map { sBigInt => + new JBigInt(sBigInt.toByteArray) + } + + val javaBigDecimal: Gen[Any, JBigDecimal] = + Gen.bigDecimal(JBigDecimal.valueOf(Long.MinValue), JBigDecimal.valueOf(Long.MaxValue)).map(_.bigDecimal) + + type StandardTypeAndGen[A] = (StandardType[A], Gen[Sized, A]) + + val anyStandardTypeAndGen: Gen[Any, StandardTypeAndGen[Any]] = { + anyStandardType.map { t => + t.asInstanceOf[StandardType[_]] match { + case typ: StandardType.StringType.type => typ -> Gen.string + case typ: StandardType.BoolType.type => typ -> Gen.boolean + case typ: StandardType.ShortType.type => typ -> Gen.short + case typ: StandardType.IntType.type => typ -> Gen.int + case typ: StandardType.LongType.type => typ -> Gen.long + case typ: StandardType.FloatType.type => typ -> Gen.float + case typ: StandardType.DoubleType.type => typ -> Gen.double + case typ: StandardType.BinaryType.type => typ -> Gen.chunkOf(Gen.byte) + case typ: StandardType.CharType.type => typ -> Gen.asciiChar + case typ: StandardType.UUIDType.type => typ -> Gen.uuid + case typ: StandardType.BigDecimalType.type => typ -> javaBigDecimal + case typ: StandardType.BigIntegerType.type => typ -> javaBigInt + case typ: StandardType.DayOfWeekType.type => typ -> JavaTimeGen.anyDayOfWeek + case typ: StandardType.DurationType.type => typ -> JavaTimeGen.anyDuration + case typ: StandardType.InstantType.type => typ -> JavaTimeGen.anyInstant + case typ: StandardType.LocalDateType.type => typ -> JavaTimeGen.anyLocalDate + case typ: StandardType.LocalDateTimeType.type => typ -> JavaTimeGen.anyLocalDateTime + case typ: StandardType.LocalTimeType.type => typ -> JavaTimeGen.anyLocalTime + case typ: StandardType.MonthType.type => typ -> JavaTimeGen.anyMonth + case typ: StandardType.MonthDayType.type => typ -> JavaTimeGen.anyMonthDay + case typ: StandardType.OffsetDateTimeType.type => typ -> JavaTimeGen.anyOffsetDateTime + case typ: StandardType.OffsetTimeType.type => typ -> JavaTimeGen.anyOffsetTime + case typ: StandardType.PeriodType.type => typ -> JavaTimeGen.anyPeriod + case typ: StandardType.YearType.type => typ -> JavaTimeGen.anyYear + case typ: StandardType.YearMonthType.type => typ -> JavaTimeGen.anyYearMonth + case typ: StandardType.ZonedDateTimeType.type => typ -> JavaTimeGen.anyZonedDateTime + case typ: StandardType.ZoneIdType.type => typ -> JavaTimeGen.anyZoneId + case typ: StandardType.ZoneOffsetType.type => typ -> JavaTimeGen.anyZoneOffset + case typ => platformSpecificStandardTypeAndGen(typ.asInstanceOf[StandardType[Any]]) + } + }.asInstanceOf[Gen[Any, StandardTypeAndGen[Any]]] + } +} diff --git a/tests/shared/src/test/scala-2/zio/schema/types.scala b/tests/shared/src/test/scala/zio/schema/types.scala similarity index 98% rename from tests/shared/src/test/scala-2/zio/schema/types.scala rename to tests/shared/src/test/scala/zio/schema/types.scala index 520410002..384976095 100644 --- a/tests/shared/src/test/scala-2/zio/schema/types.scala +++ b/tests/shared/src/test/scala/zio/schema/types.scala @@ -229,13 +229,13 @@ object types { Gen.const(Schema[Arities]) ) - def anySchemaAndValue: Gen[Sized, SchemaAndValue[_]] = + def anySchemaAndValue: Gen[Sized, SchemaAndValue[Any]] = for { schema <- anySchema dynamicValue <- DynamicValueGen.anyDynamicValueOfSchema(schema) } yield schema.asInstanceOf[Schema[Any]] -> dynamicValue.toTypedValue(schema).toOption.get - def anySchemaAndValuePair: Gen[Sized, SchemaAndValuePair[_]] = + def anySchemaAndValuePair: Gen[Sized, SchemaAndValuePair[Any]] = for { schema <- anySchema dynamicValue1 <- DynamicValueGen.anyDynamicValueOfSchema(schema) @@ -245,7 +245,7 @@ object types { .toOption .get) - def anySchemaAndValues(n: Int): Gen[Sized, SchemaAndValues[_]] = + def anySchemaAndValues(n: Int): Gen[Sized, SchemaAndValues[Any]] = for { schema <- anySchema dynamicValues <- Gen.listOfN(n)(DynamicValueGen.anyDynamicValueOfSchema(schema)) diff --git a/zio-schema-avro/src/test/scala-2/zio/schema/codec/AvroCodecSpec.scala b/zio-schema-avro/src/test/scala/zio/schema/codec/AvroCodecSpec.scala similarity index 100% rename from zio-schema-avro/src/test/scala-2/zio/schema/codec/AvroCodecSpec.scala rename to zio-schema-avro/src/test/scala/zio/schema/codec/AvroCodecSpec.scala diff --git a/zio-schema-avro/src/test/scala-2/zio/schema/codec/AvroSchemaCodecSpec.scala b/zio-schema-avro/src/test/scala/zio/schema/codec/AvroSchemaCodecSpec.scala similarity index 99% rename from zio-schema-avro/src/test/scala-2/zio/schema/codec/AvroSchemaCodecSpec.scala rename to zio-schema-avro/src/test/scala/zio/schema/codec/AvroSchemaCodecSpec.scala index 25895f44d..bc19b6b82 100644 --- a/zio-schema-avro/src/test/scala-2/zio/schema/codec/AvroSchemaCodecSpec.scala +++ b/zio-schema-avro/src/test/scala/zio/schema/codec/AvroSchemaCodecSpec.scala @@ -81,7 +81,7 @@ object AvroSchemaCodecSpec extends ZIOSpecDefault { val expected = """[{"type":"record","name":"A","fields":[]},{"type":"record","name":"B","fields":[]},{"type":"record","name":"MyC","fields":[]},{"type":"record","name":"D","fields":[{"name":"s","type":"string"}]}]""" assert(result)(isRight(equalTo(expected))) - }, + } @@ TestAspect.scala2Only, test("wraps nested unions") { val schemaA = DeriveSchema.gen[UnionWithNesting.Nested.A.type] val schemaB = DeriveSchema.gen[UnionWithNesting.Nested.B.type] @@ -1178,7 +1178,8 @@ object AvroSchemaCodecSpec extends ZIOSpecDefault { val s = """{"type":"enum","name":"TestEnum","symbols":["a","b","c"]}""" val schema = AvroSchemaCodec.decode(Chunk.fromArray(s.getBytes())) - val symbolKeysAssetion = Assertion.hasKeys(hasSameElements(Seq("a", "b", "c"))) + val symbolKeysAssetion: Assertion[Predef.Map[String, Any]] = + Assertion.hasKeys(hasSameElements(Seq("a", "b", "c"))) val enumStringTypeAssertion: Assertion[ListMap[String, (Schema[_], Chunk[Any])]] = Assertion.hasValues(forall(tuple2First(isStandardType(StandardType.StringType)))) assert(schema)(isRight(isEnum(enumStructure(symbolKeysAssetion && enumStringTypeAssertion)))) @@ -1858,8 +1859,8 @@ object AssertionHelper { def enumStructure(assertion: Assertion[ListMap[String, (Schema[_], Chunk[Any])]]): Assertion[Schema.Enum[_]] = Assertion.assertionRec("enumStructure")(assertion)( - enum => - Some(`enum`.cases.foldRight(ListMap.empty[String, (Schema[_], Chunk[Any])]) { (caseValue, acc) => + enum0 => + Some(enum0.cases.foldRight(ListMap.empty[String, (Schema[_], Chunk[Any])]) { (caseValue, acc) => (acc + (caseValue.id -> scala.Tuple2(caseValue.schema, caseValue.annotations))) }) ) diff --git a/zio-schema-derivation/shared/src/main/scala-3/zio/schema/DeriveSchema.scala b/zio-schema-derivation/shared/src/main/scala-3/zio/schema/DeriveSchema.scala index b41711c30..47b4ac5a6 100644 --- a/zio-schema-derivation/shared/src/main/scala-3/zio/schema/DeriveSchema.scala +++ b/zio-schema-derivation/shared/src/main/scala-3/zio/schema/DeriveSchema.scala @@ -255,11 +255,17 @@ private case class DeriveSchema()(using val ctx: Quotes) { case None => tpe.asType } + val annotations = paramAnns.getOrElse(label, List.empty) + val nameExpr = annotations.collectFirst { + case ann if ann.isExprOf[fieldName] => + val fieldNameAnn = ann.asExprOf[fieldName] + '{${fieldNameAnn}.name} + }.getOrElse(Expr(label)) fieldType match { case '[t] => - '{ try ${m}.apply(${Expr(label)}).asInstanceOf[t] + '{ try ${m}.apply(${nameExpr}).asInstanceOf[t] catch { - case _: ClassCastException => throw new RuntimeException("Field " + ${Expr(label)} + " has invalid type") - case _: Throwable => throw new RuntimeException("Field " + ${Expr(label)} + " is missing") + case _: ClassCastException => throw new RuntimeException("Field " + ${nameExpr} + " has invalid type") + case _: Throwable => throw new RuntimeException("Field " + ${nameExpr} + " is missing") } }.asTerm } @@ -284,8 +290,14 @@ private case class DeriveSchema()(using val ctx: Quotes) { case None => tpe.asType } + val annotations = paramAnns.getOrElse(label, List.empty) + val nameExpr = annotations.collectFirst { + case ann if ann.isExprOf[fieldName] => + val fieldNameAnn = ann.asExprOf[fieldName] + '{${fieldNameAnn}.name} + }.getOrElse(Expr(label)) fieldType match { case '[t] => - '{(${Expr(label)}, ${Select.unique(b.asTerm, label).asExprOf[t]})} + '{(${nameExpr}, ${Select.unique(b.asTerm, label).asExprOf[t]})} } } val toMap = '{(b: T) => Right(ListMap.apply(${Varargs(tuples('b))} :_*)) } diff --git a/zio-schema-json/jvm/src/test/scala-2/zio/schema/codec/JsonCodecJVMSpec.scala b/zio-schema-json/jvm/src/test/scala/zio/schema/codec/JsonCodecJVMSpec.scala similarity index 100% rename from zio-schema-json/jvm/src/test/scala-2/zio/schema/codec/JsonCodecJVMSpec.scala rename to zio-schema-json/jvm/src/test/scala/zio/schema/codec/JsonCodecJVMSpec.scala diff --git a/zio-schema-json/shared/src/test/scala-2/zio/schema/codec/JsonCodecSpec.scala b/zio-schema-json/shared/src/test/scala/zio/schema/codec/JsonCodecSpec.scala similarity index 100% rename from zio-schema-json/shared/src/test/scala-2/zio/schema/codec/JsonCodecSpec.scala rename to zio-schema-json/shared/src/test/scala/zio/schema/codec/JsonCodecSpec.scala diff --git a/zio-schema-msg-pack/src/test/scala-2/zio/schema/codec/MessagePackCodecSpec.scala b/zio-schema-msg-pack/src/test/scala/zio/schema/codec/MessagePackCodecSpec.scala similarity index 100% rename from zio-schema-msg-pack/src/test/scala-2/zio/schema/codec/MessagePackCodecSpec.scala rename to zio-schema-msg-pack/src/test/scala/zio/schema/codec/MessagePackCodecSpec.scala diff --git a/zio-schema-protobuf/shared/src/test/scala-2/zio/schema/codec/ProtobufCodecSpec.scala b/zio-schema-protobuf/shared/src/test/scala/zio/schema/codec/ProtobufCodecSpec.scala similarity index 100% rename from zio-schema-protobuf/shared/src/test/scala-2/zio/schema/codec/ProtobufCodecSpec.scala rename to zio-schema-protobuf/shared/src/test/scala/zio/schema/codec/ProtobufCodecSpec.scala diff --git a/zio-schema-thrift/src/test/scala-2/zio/schema/codec/ThriftCodecSpec.scala b/zio-schema-thrift/src/test/scala/zio/schema/codec/ThriftCodecSpec.scala similarity index 100% rename from zio-schema-thrift/src/test/scala-2/zio/schema/codec/ThriftCodecSpec.scala rename to zio-schema-thrift/src/test/scala/zio/schema/codec/ThriftCodecSpec.scala diff --git a/zio-schema-thrift/src/test/scala-2/zio/schema/codec/generated/BasicDouble.java b/zio-schema-thrift/src/test/scala/zio/schema/codec/generated/BasicDouble.java similarity index 100% rename from zio-schema-thrift/src/test/scala-2/zio/schema/codec/generated/BasicDouble.java rename to zio-schema-thrift/src/test/scala/zio/schema/codec/generated/BasicDouble.java diff --git a/zio-schema-thrift/src/test/scala-2/zio/schema/codec/generated/BasicInt.java b/zio-schema-thrift/src/test/scala/zio/schema/codec/generated/BasicInt.java similarity index 100% rename from zio-schema-thrift/src/test/scala-2/zio/schema/codec/generated/BasicInt.java rename to zio-schema-thrift/src/test/scala/zio/schema/codec/generated/BasicInt.java diff --git a/zio-schema-thrift/src/test/scala-2/zio/schema/codec/generated/BasicString.java b/zio-schema-thrift/src/test/scala/zio/schema/codec/generated/BasicString.java similarity index 100% rename from zio-schema-thrift/src/test/scala-2/zio/schema/codec/generated/BasicString.java rename to zio-schema-thrift/src/test/scala/zio/schema/codec/generated/BasicString.java diff --git a/zio-schema-thrift/src/test/scala-2/zio/schema/codec/generated/BoolValue.java b/zio-schema-thrift/src/test/scala/zio/schema/codec/generated/BoolValue.java similarity index 100% rename from zio-schema-thrift/src/test/scala-2/zio/schema/codec/generated/BoolValue.java rename to zio-schema-thrift/src/test/scala/zio/schema/codec/generated/BoolValue.java diff --git a/zio-schema-thrift/src/test/scala-2/zio/schema/codec/generated/Color.java b/zio-schema-thrift/src/test/scala/zio/schema/codec/generated/Color.java similarity index 100% rename from zio-schema-thrift/src/test/scala-2/zio/schema/codec/generated/Color.java rename to zio-schema-thrift/src/test/scala/zio/schema/codec/generated/Color.java diff --git a/zio-schema-thrift/src/test/scala-2/zio/schema/codec/generated/Embedded.java b/zio-schema-thrift/src/test/scala/zio/schema/codec/generated/Embedded.java similarity index 100% rename from zio-schema-thrift/src/test/scala-2/zio/schema/codec/generated/Embedded.java rename to zio-schema-thrift/src/test/scala/zio/schema/codec/generated/Embedded.java diff --git a/zio-schema-thrift/src/test/scala-2/zio/schema/codec/generated/EnumValue.java b/zio-schema-thrift/src/test/scala/zio/schema/codec/generated/EnumValue.java similarity index 100% rename from zio-schema-thrift/src/test/scala-2/zio/schema/codec/generated/EnumValue.java rename to zio-schema-thrift/src/test/scala/zio/schema/codec/generated/EnumValue.java diff --git a/zio-schema-thrift/src/test/scala-2/zio/schema/codec/generated/Enumeration.java b/zio-schema-thrift/src/test/scala/zio/schema/codec/generated/Enumeration.java similarity index 100% rename from zio-schema-thrift/src/test/scala-2/zio/schema/codec/generated/Enumeration.java rename to zio-schema-thrift/src/test/scala/zio/schema/codec/generated/Enumeration.java diff --git a/zio-schema-thrift/src/test/scala-2/zio/schema/codec/generated/HighArity.java b/zio-schema-thrift/src/test/scala/zio/schema/codec/generated/HighArity.java similarity index 100% rename from zio-schema-thrift/src/test/scala-2/zio/schema/codec/generated/HighArity.java rename to zio-schema-thrift/src/test/scala/zio/schema/codec/generated/HighArity.java diff --git a/zio-schema-thrift/src/test/scala-2/zio/schema/codec/generated/IntList.java b/zio-schema-thrift/src/test/scala/zio/schema/codec/generated/IntList.java similarity index 100% rename from zio-schema-thrift/src/test/scala-2/zio/schema/codec/generated/IntList.java rename to zio-schema-thrift/src/test/scala/zio/schema/codec/generated/IntList.java diff --git a/zio-schema-thrift/src/test/scala-2/zio/schema/codec/generated/IntValue.java b/zio-schema-thrift/src/test/scala/zio/schema/codec/generated/IntValue.java similarity index 100% rename from zio-schema-thrift/src/test/scala-2/zio/schema/codec/generated/IntValue.java rename to zio-schema-thrift/src/test/scala/zio/schema/codec/generated/IntValue.java diff --git a/zio-schema-thrift/src/test/scala-2/zio/schema/codec/generated/MapValue.java b/zio-schema-thrift/src/test/scala/zio/schema/codec/generated/MapValue.java similarity index 100% rename from zio-schema-thrift/src/test/scala-2/zio/schema/codec/generated/MapValue.java rename to zio-schema-thrift/src/test/scala/zio/schema/codec/generated/MapValue.java diff --git a/zio-schema-thrift/src/test/scala-2/zio/schema/codec/generated/OneOf.java b/zio-schema-thrift/src/test/scala/zio/schema/codec/generated/OneOf.java similarity index 100% rename from zio-schema-thrift/src/test/scala-2/zio/schema/codec/generated/OneOf.java rename to zio-schema-thrift/src/test/scala/zio/schema/codec/generated/OneOf.java diff --git a/zio-schema-thrift/src/test/scala-2/zio/schema/codec/generated/Record.java b/zio-schema-thrift/src/test/scala/zio/schema/codec/generated/Record.java similarity index 100% rename from zio-schema-thrift/src/test/scala-2/zio/schema/codec/generated/Record.java rename to zio-schema-thrift/src/test/scala/zio/schema/codec/generated/Record.java diff --git a/zio-schema-thrift/src/test/scala-2/zio/schema/codec/generated/SetValue.java b/zio-schema-thrift/src/test/scala/zio/schema/codec/generated/SetValue.java similarity index 100% rename from zio-schema-thrift/src/test/scala-2/zio/schema/codec/generated/SetValue.java rename to zio-schema-thrift/src/test/scala/zio/schema/codec/generated/SetValue.java diff --git a/zio-schema-thrift/src/test/scala-2/zio/schema/codec/generated/StringList.java b/zio-schema-thrift/src/test/scala/zio/schema/codec/generated/StringList.java similarity index 100% rename from zio-schema-thrift/src/test/scala-2/zio/schema/codec/generated/StringList.java rename to zio-schema-thrift/src/test/scala/zio/schema/codec/generated/StringList.java diff --git a/zio-schema-thrift/src/test/scala-2/zio/schema/codec/generated/StringValue.java b/zio-schema-thrift/src/test/scala/zio/schema/codec/generated/StringValue.java similarity index 100% rename from zio-schema-thrift/src/test/scala-2/zio/schema/codec/generated/StringValue.java rename to zio-schema-thrift/src/test/scala/zio/schema/codec/generated/StringValue.java