* =act #21237 fix regression in ByteString.slice * Update ByteStringSpec.scala
This commit is contained in:
parent
9ef93c6200
commit
fb45dd03f3
2 changed files with 43 additions and 15 deletions
|
|
@ -21,11 +21,7 @@ import scala.collection.mutable.Builder
|
|||
|
||||
class ByteStringSpec extends WordSpec with Matchers with Checkers {
|
||||
|
||||
// // uncomment when developing locally to get better coverage
|
||||
// implicit override val generatorDrivenConfig =
|
||||
// PropertyCheckConfig(
|
||||
// minSuccessful = 1000,
|
||||
// minSize = 0, maxSize = 100)
|
||||
implicit val betterGeneratorDrivenConfig = PropertyCheckConfig().copy(minSuccessful = 1000)
|
||||
|
||||
def genSimpleByteString(min: Int, max: Int) = for {
|
||||
n ← Gen.choose(min, max)
|
||||
|
|
@ -365,13 +361,48 @@ class ByteStringSpec extends WordSpec with Matchers with Checkers {
|
|||
ByteStrings(ByteString1.fromString(""), ByteString1.fromString("ab")).dropRight(Int.MinValue) should ===(ByteString("ab"))
|
||||
}
|
||||
"slice" in {
|
||||
ByteStrings(ByteString1.fromString("a"), ByteString1.fromString("")).slice(0, 1) should ===(ByteString("a"))
|
||||
ByteStrings(ByteString1.fromString(""), ByteString1.fromString("a")).slice(1, 1) should ===(ByteString(""))
|
||||
// We explicitly test all edge cases to always test them, refs bug #21237
|
||||
ByteStrings(ByteString1.fromString("a"), ByteString1.fromString("")).slice(-10, 10) should ===(ByteString("a"))
|
||||
ByteStrings(ByteString1.fromString("a"), ByteString1.fromString("")).slice(-10, 0) should ===(ByteString(""))
|
||||
ByteStrings(ByteString1.fromString("a"), ByteString1.fromString("")).slice(-10, 1) should ===(ByteString("a"))
|
||||
ByteStrings(ByteString1.fromString("a"), ByteString1.fromString("")).slice(0, 1) should ===(ByteString("a"))
|
||||
ByteStrings(ByteString1.fromString("a"), ByteString1.fromString("")).slice(0, 10) should ===(ByteString("a"))
|
||||
ByteStrings(ByteString1.fromString("a"), ByteString1.fromString("")).slice(1, 10) should ===(ByteString(""))
|
||||
ByteStrings(ByteString1.fromString("a"), ByteString1.fromString("")).slice(1, -2) should ===(ByteString(""))
|
||||
ByteStrings(ByteString1.fromString("a"), ByteString1.fromString("")).slice(-10, -100) should ===(ByteString(""))
|
||||
ByteStrings(ByteString1.fromString("a"), ByteString1.fromString("")).slice(-100, -10) should ===(ByteString(""))
|
||||
// Get an empty if `from` is greater then `until`
|
||||
ByteStrings(ByteString1.fromString("a"), ByteString1.fromString("")).slice(1, 0) should ===(ByteString(""))
|
||||
|
||||
ByteStrings(ByteString1.fromString("ab"), ByteString1.fromString("cd")).slice(2, 2) should ===(ByteString(""))
|
||||
ByteStrings(ByteString1.fromString("ab"), ByteString1.fromString("cd")).slice(2, 3) should ===(ByteString("c"))
|
||||
ByteStrings(ByteString1.fromString("ab"), ByteString1.fromString("cd")).slice(2, 4) should ===(ByteString("cd"))
|
||||
ByteStrings(ByteString1.fromString("ab"), ByteString1.fromString("cd")).slice(3, 4) should ===(ByteString("d"))
|
||||
ByteStrings(ByteString1.fromString("ab"), ByteString1.fromString("cd")).slice(10, 100) should ===(ByteString(""))
|
||||
// Can obtain expected results from 6 basic patterns
|
||||
ByteStrings(ByteString1.fromString("ab"), ByteString1.fromString("cd")).slice(-10, 10) should ===(ByteString("abcd"))
|
||||
ByteStrings(ByteString1.fromString("ab"), ByteString1.fromString("cd")).slice(-10, 0) should ===(ByteString(""))
|
||||
ByteStrings(ByteString1.fromString("ab"), ByteString1.fromString("cd")).slice(-10, 4) should ===(ByteString("abcd"))
|
||||
ByteStrings(ByteString1.fromString("ab"), ByteString1.fromString("cd")).slice(0, 4) should ===(ByteString("abcd"))
|
||||
ByteStrings(ByteString1.fromString("ab"), ByteString1.fromString("cd")).slice(1, -2) should ===(ByteString(""))
|
||||
ByteStrings(ByteString1.fromString("ab"), ByteString1.fromString("cd")).slice(0, 10) should ===(ByteString("abcd"))
|
||||
ByteStrings(ByteString1.fromString("ab"), ByteString1.fromString("cd")).slice(-10, -100) should ===(ByteString(""))
|
||||
ByteStrings(ByteString1.fromString("ab"), ByteString1.fromString("cd")).slice(-100, -10) should ===(ByteString(""))
|
||||
|
||||
ByteStrings(ByteString1.fromString("a"), ByteString1.fromString("")).slice(1, -2) should ===(ByteString(""))
|
||||
ByteStrings(ByteString1.fromString("a"), ByteString1.fromString("")).slice(-10, -100) should ===(ByteString(""))
|
||||
ByteStrings(ByteString1.fromString("a"), ByteString1.fromString("")).slice(-100, -10) should ===(ByteString(""))
|
||||
|
||||
// various edge cases using raw ByteString1
|
||||
ByteString1.fromString("cd").slice(100, 10) should ===(ByteString(""))
|
||||
ByteString1.fromString("cd").slice(100, 1000) should ===(ByteString(""))
|
||||
ByteString1.fromString("cd").slice(-10, -5) should ===(ByteString(""))
|
||||
ByteString1.fromString("cd").slice(-2, -5) should ===(ByteString(""))
|
||||
ByteString1.fromString("cd").slice(-2, 1) should ===(ByteString("c"))
|
||||
ByteString1.fromString("abcd").slice(1, -1) should ===(ByteString(""))
|
||||
|
||||
// Get an empty if `from` is greater than `until`
|
||||
ByteStrings(ByteString1.fromString("ab"), ByteString1.fromString("cd")).slice(4, 0) should ===(ByteString(""))
|
||||
}
|
||||
"dropRight" in {
|
||||
ByteStrings(ByteString1.fromString("a"), ByteString1.fromString("")).dropRight(0) should ===(ByteString("a"))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue