Skip to content

Commit ad25657

Browse files
TobiasPfeiferlandlockedsurfer
authored andcommitted
preserve annotations when calling toRecord on a Tuple: fixes zio#212 (zio#213)
* preserve annotations when calling toRecord on a Tuple: fixes zio#212 * apply scalafixAll
1 parent c3bb08b commit ad25657

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

tests/shared/src/test/scala/zio/schema/SchemaSpec.scala

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package zio.schema
22

33
import scala.collection.immutable.ListMap
44

5+
import zio.Chunk
56
import zio.schema.CaseSet._
67
import zio.test.Assertion._
78
import zio.test.{ ZSpec, _ }
@@ -17,26 +18,33 @@ object SchemaSpec extends DefaultRunnableSpec {
1718
assert(Schema.chunk(schemaUnit))(equalTo(Schema.chunk(schemaUnit)))
1819
},
1920
test("tuple") {
20-
assert(Schema.Tuple(schemaUnit, schemaUnit))(equalTo(Schema.Tuple(schemaUnit, schemaUnit)))
21+
assert(Schema.Tuple(schemaUnit, schemaUnit))(equalTo(Schema.Tuple(schemaUnit, schemaUnit))) &&
2122
assert(Schema.Tuple(schemaTransform, schemaTransform))(equalTo(Schema.Tuple(schemaTransform, schemaTransform)))
2223
},
2324
test("record") {
24-
assert(schemaRecord("key"))(equalTo(schemaRecord("key")))
25+
assert(schemaRecord("key"))(equalTo(schemaRecord("key"))) &&
2526
assert(schemaRecord("key1"))(not(equalTo(schemaRecord("key2"))))
2627
},
2728
test("transform") {
28-
assert(schemaTransform)(equalTo(schemaTransform))
29+
assert(schemaTransform)(equalTo(schemaTransform)) &&
2930
assert(schemaTransformMethod)(equalTo(schemaTransformMethod))
3031
},
3132
test("optional") {
3233
assert(Schema.Optional(schemaUnit))(equalTo(Schema.Optional(schemaUnit)))
3334
},
3435
test("enumeration") {
35-
assert(schemaEnum("key"))(equalTo(schemaEnum("key")))
36+
assert(schemaEnum("key"))(equalTo(schemaEnum("key"))) &&
3637
assert(schemaEnum("key1"))(not(equalTo(schemaEnum("key2"))))
3738

3839
}
39-
)
40+
),
41+
test("Tuple.toRecord should preserve annotations") {
42+
val left = Schema.primitive(StandardType.StringType)
43+
val right = Schema.primitive(StandardType.StringType)
44+
val tupleSchema = Schema.Tuple(left, right, Chunk("some Annotation"))
45+
val record = tupleSchema.toRecord
46+
assert(record.annotations)(hasFirst(equalTo("some Annotation")))
47+
}
4048
)
4149

4250
def schemaUnit: Schema[Unit] = Schema[Unit]

zio-schema/shared/src/main/scala/zio/schema/Schema.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,8 @@ object Schema extends TupleSchemas with RecordSchemas with EnumSchemas with Sche
386386
field2 = Field("_2", right),
387387
construct = (a, b) => (a, b),
388388
extractField1 = _._1,
389-
extractField2 = _._2
389+
extractField2 = _._2,
390+
annotations
390391
)
391392

392393
override def defaultValue: Either[String, (A, B)] =

0 commit comments

Comments
 (0)