Skip to content

Commit

Permalink
Merge pull request #795 from ashawley/fix-tuple-serialization
Browse files Browse the repository at this point in the history
Fix serialization of Gen tuples
  • Loading branch information
larsrh authored Apr 16, 2021
2 parents 488ca94 + d36a449 commit ecb819b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,29 +85,39 @@ object SerializabilitySpecification extends Properties("Serializability") {
serializableArbitrary[Boolean]("Boolean")
serializableArbitrary[Int => Int]("Int => Int")
serializableArbitrary[List[Int]]("List[Int]")
serializableArbitrary[(String,Int)]("(String,Int)")
serializableArbitrary[(Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int)]("Tuple22[Int]")
serializableArbitrary[List[(String,Int)]]("List[(String,Int)]")

serializableGen("identifier", Gen.identifier)
serializableGen("oneOf", Gen.oneOf(true, false))
serializableGen("choose", Gen.choose(1, 10))
serializableGen("function1", Gen.function1[Int, Int](Gen.choose(1, 10)))
serializableGen("zip(String,Int)", Gen.zip(Arbitrary.arbitrary[String], Arbitrary.arbitrary[Int]))

serializableCogen[String]("String")
serializableCogen[Int]("Int")
serializableCogen[Double]("Double")
serializableCogen[Boolean]("Boolean")
serializableCogen[Int => Int]("Int => Int")
serializableCogen[List[Int]]("List[Int]")
serializableCogen[(String,Int)]("(String,Int)")
serializableCogen[(Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int)]("Tuple22[Int]")
serializableCogen[List[(String,Int)]]("List[(String,Int)]")

serializableShrink[String]("String")
serializableShrink[Int]("Int")
serializableShrink[Double]("Double")
serializableShrink[Boolean]("Boolean")
serializableShrink[Int => Int]("Int => Int")
serializableShrink[List[Int]]("List[Int]")
serializableShrink[(String,Int)]("(String,Int)")
serializableShrink[(Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int)]("Tuple22[Int])")
serializableShrink[List[(String,Int)]]("List[(String,Int)]")

property("Seed serializability") = {
assert(serializable(rng.Seed(1L)))
proved
}

}
}
2 changes: 1 addition & 1 deletion project/codegen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ object codegen {
s.init.foldRight(s"${s.last._2}.map { ${s.last._1} => (${vals(i)}) }") {
case ((t, g), acc) =>
val T = t.toUpperCase
s"${g}.flatMap(new Function1[${T}, Gen[(${types(i)})]] { def apply(${t}: ${T}): Gen[(${types(i)})] = $acc })"
s"$g.flatMap(($t: $T) => $acc)"
}

def vals(i: Int) = csv(idents("t",i))
Expand Down

0 comments on commit ecb819b

Please sign in to comment.