Extended ByteStringBuilder tests in ByteStringSpec
This commit is contained in:
parent
a87faade06
commit
e01e324c80
1 changed files with 25 additions and 0 deletions
|
|
@ -9,6 +9,8 @@ import org.scalacheck.Arbitrary._
|
||||||
import org.scalacheck.Prop._
|
import org.scalacheck.Prop._
|
||||||
import org.scalacheck.Gen._
|
import org.scalacheck.Gen._
|
||||||
|
|
||||||
|
import scala.collection.mutable.Builder
|
||||||
|
|
||||||
import java.nio.{ ByteBuffer, ShortBuffer, IntBuffer, FloatBuffer, DoubleBuffer }
|
import java.nio.{ ByteBuffer, ShortBuffer, IntBuffer, FloatBuffer, DoubleBuffer }
|
||||||
import java.nio.{ ByteOrder }, ByteOrder.{ BIG_ENDIAN, LITTLE_ENDIAN }
|
import java.nio.{ ByteOrder }, ByteOrder.{ BIG_ENDIAN, LITTLE_ENDIAN }
|
||||||
import java.lang.Float.floatToRawIntBits
|
import java.lang.Float.floatToRawIntBits
|
||||||
|
|
@ -79,6 +81,16 @@ class ByteStringSpec extends WordSpec with MustMatchers with Checkers {
|
||||||
(!strict || (bsAIt.toSeq, bsBIt.toSeq) == (vecAIt.toSeq, vecBIt.toSeq))
|
(!strict || (bsAIt.toSeq, bsBIt.toSeq) == (vecAIt.toSeq, vecBIt.toSeq))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def likeVecBld(body: Builder[Byte, _] ⇒ Unit): Boolean = {
|
||||||
|
val bsBuilder = ByteString.newBuilder
|
||||||
|
val vecBuilder = Vector.newBuilder[Byte]
|
||||||
|
|
||||||
|
body(bsBuilder)
|
||||||
|
body(vecBuilder)
|
||||||
|
|
||||||
|
bsBuilder.result == vecBuilder.result
|
||||||
|
}
|
||||||
|
|
||||||
def testShortDecoding(slice: ByteStringSlice, byteOrder: ByteOrder): Boolean = {
|
def testShortDecoding(slice: ByteStringSlice, byteOrder: ByteOrder): Boolean = {
|
||||||
val elemSize = 2
|
val elemSize = 2
|
||||||
val (bytes, from, until) = slice
|
val (bytes, from, until) = slice
|
||||||
|
|
@ -359,6 +371,19 @@ class ByteStringSpec extends WordSpec with MustMatchers with Checkers {
|
||||||
}
|
}
|
||||||
|
|
||||||
"A ByteStringBuilder" must {
|
"A ByteStringBuilder" must {
|
||||||
|
"function like a VectorBuilder" when {
|
||||||
|
"adding various contents using ++= and +=" in {
|
||||||
|
check { (array1: Array[Byte], array2: Array[Byte], bs1: ByteString, bs2: ByteString, bs3: ByteString) ⇒
|
||||||
|
likeVecBld { builder ⇒
|
||||||
|
builder ++= array1
|
||||||
|
bs1 foreach { b ⇒ builder += b }
|
||||||
|
builder ++= bs2
|
||||||
|
bs3 foreach { b ⇒ builder += b }
|
||||||
|
builder ++= Vector(array2: _*)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
"function as expected" when {
|
"function as expected" when {
|
||||||
"putting Bytes, using putByte and putBytes" in {
|
"putting Bytes, using putByte and putBytes" in {
|
||||||
// mixing putByte and putBytes here for more rigorous testing
|
// mixing putByte and putBytes here for more rigorous testing
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue