#2913 - Adding asByteBuffers to ByteString

This commit is contained in:
Viktor Klang 2013-01-27 23:46:03 +01:00
parent f12e11df46
commit 2f86107b10
2 changed files with 44 additions and 6 deletions

View file

@ -269,9 +269,19 @@ class ByteStringSpec extends WordSpec with MustMatchers with Checkers {
(b.compact eq b)
}
}
"asByteBuffers" in {
check { (a: ByteString) if (a.isCompact) a.asByteBuffers.size == 1 && a.asByteBuffers.head == a.asByteBuffer else a.asByteBuffers.size > 0 }
check { (a: ByteString) a.asByteBuffers.foldLeft(ByteString.empty) { (bs, bb) bs ++ ByteString(bb) } == a }
check { (a: ByteString) a.asByteBuffers.forall(_.isReadOnly) }
check { (a: ByteString)
import scala.collection.JavaConverters.iterableAsScalaIterableConverter;
a.asByteBuffers.zip(a.getByteBuffers().asScala).forall(x x._1 == x._2)
}
}
}
"behave like a Vector" when {
"concatenating" in { check { (a: ByteString, b: ByteString) likeVectors(a, b) { (a, b) (a ++ b) } } }
"concatenating" in { check { (a: ByteString, b: ByteString) likeVectors(a, b) { _ ++ _ } } }
"calling apply" in {
check { slice: ByteStringSlice