Skip to content

Commit

Permalink
Fix invalid ranges in ByteStringSpec #22389
Browse files Browse the repository at this point in the history
  • Loading branch information
johanandren committed Feb 24, 2017
1 parent 4322bb1 commit 28d96a2
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions akka-actor-tests/src/test/scala/akka/util/ByteStringSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ class ByteStringSpec extends WordSpec with Matchers with Checkers {
n Gen.choose(min, max)
b Gen.containerOfN[Array, Byte](n, arbitrary[Byte])
from Gen.choose(0, b.length)
until Gen.choose(from, b.length)
until Gen.choose(from, from max b.length)
} yield ByteString(b).slice(from, until)

implicit val arbitraryByteString: Arbitrary[ByteString] = Arbitrary {
Gen.sized { s
for {
chunks Gen.choose(0, s)
bytes Gen.listOfN(chunks, genSimpleByteString(1, s / (chunks max 1)))
bytes Gen.listOfN(chunks, genSimpleByteString(1, 1 max (s / (chunks max 1))))
} yield (ByteString.empty /: bytes)(_ ++ _)
}
}
Expand All @@ -44,8 +44,11 @@ class ByteStringSpec extends WordSpec with Matchers with Checkers {
implicit val arbitraryByteStringSlice: Arbitrary[ByteStringSlice] = Arbitrary {
for {
xs arbitraryByteString.arbitrary
from Gen.choose(0, xs.length - 1)
until Gen.choose(from, xs.length)
from Gen.choose(0, 0 max (xs.length - 1))
until {
require(from <= xs.length)
Gen.choose(from, xs.length)
}
} yield (xs, from, until)
}

Expand Down

0 comments on commit 28d96a2

Please sign in to comment.