Skip to content

Commit 5079905

Browse files
committed
Merge branch 'cheeseng-2.2-every-serializable' into 2.2.3-and-greater
2 parents 3679ab6 + f9c28cf commit 5079905

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

src/main/scala/org/scalactic/Every.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ import scala.annotation.unchecked.{ uncheckedVariance => uV }
141141
*
142142
* @tparam T the type of elements contained in this <code>Every</code>
143143
*/
144-
sealed abstract class Every[+T] protected (underlying: Vector[T]) extends PartialFunction[Int, T] {
144+
sealed abstract class Every[+T] protected (underlying: Vector[T]) extends PartialFunction[Int, T] with Serializable {
145145

146146
/*
147147
private def this(firstElement: T, otherElements: T*) = this(Vector(firstElement) ++ otherElements)

src/test/scala/org/scalactic/EverySpec.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import org.scalatest._
2020
import scala.collection.GenTraversable
2121
import scala.collection.mutable.Buffer
2222
import scala.collection.mutable.ListBuffer
23+
import SharedHelpers.serializeRoundtrip
2324

2425
class EverySpec extends UnitSpec {
2526
"An Every" can "be constructed as a One" in {
@@ -1174,11 +1175,21 @@ class EverySpec extends UnitSpec {
11741175
Every(99).zipWithIndex shouldBe Every((99,0))
11751176
Every(1, 2, 3, 4, 5).zipWithIndex shouldBe Every((1,0), (2,1), (3,2), (4,3), (5,4))
11761177
}
1178+
it should "be serializable" in {
1179+
serializeRoundtrip(Every(1))
1180+
}
11771181
"A One" can "be widened to an Every type via .asEvery" in {
11781182
One(1).asEvery shouldBe One(1)
11791183
}
1184+
it should "be serializable" in {
1185+
serializeRoundtrip(One(1))
1186+
}
11801187
"A Many" can "be widened to an Every type via .asEvery" in {
11811188
Many(1, 2, 3).asEvery shouldBe Many(1, 2, 3)
11821189
}
1190+
it should "be serializable" in {
1191+
serializeRoundtrip(Many(1, 2, 3))
1192+
}
1193+
11831194
}
11841195

src/test/scala/org/scalactic/OrSpec.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import org.scalatest._
2020
import scala.util.Try
2121
import scala.util.Success
2222
import scala.util.Failure
23+
import SharedHelpers.serializeRoundtrip
2324

2425
class OrSpec extends UnitSpec with Accumulation with TypeCheckedTripleEquals {
2526

@@ -514,6 +515,11 @@ class OrSpec extends UnitSpec with Accumulation with TypeCheckedTripleEquals {
514515
Good[Int].orBad("howdy").fold(_ + 1, _.length) shouldBe 5
515516

516517
}
518+
it can "be serialized correctly" in {
519+
serializeRoundtrip(Or.from(Success(12)) shouldBe Good(12))
520+
val ex = new Exception("oops")
521+
serializeRoundtrip(Or.from(Failure(ex)) shouldBe Bad(ex))
522+
}
517523
"A Good" can "be widened to an Or type via .asOr" in {
518524
Good(1).asOr shouldBe Good(1)
519525
/*
@@ -532,6 +538,9 @@ class OrSpec extends UnitSpec with Accumulation with TypeCheckedTripleEquals {
532538
(acc, x) => acc orElse (if (x % 2 == 0) Good(x) else acc)
533539
} shouldBe Good(6)
534540
}
541+
it can "be serialized correctly" in {
542+
serializeRoundtrip(Good(1))
543+
}
535544
"A Bad" can "be widened to an Or type via .asOr" in {
536545
Bad("oops").asOr shouldBe Bad("oops")
537546
/*
@@ -554,5 +563,8 @@ class OrSpec extends UnitSpec with Accumulation with TypeCheckedTripleEquals {
554563
acc orElse (if (x % 2 == 0) Good(x) else acc)
555564
} shouldBe Bad("no evens")
556565
}
566+
it can "be serialized correctly" in {
567+
serializeRoundtrip(Bad("oops"))
568+
}
557569
}
558570

0 commit comments

Comments
 (0)