Merge pull request #17086 from hepin1989/master
#15825 add isEmpty and nonEmpty to ByteStringBuilder
This commit is contained in:
commit
faefc32237
2 changed files with 24 additions and 0 deletions
|
|
@ -80,6 +80,8 @@ class ByteStringSpec extends WordSpec with Matchers with Checkers {
|
||||||
} yield (xs.slice(from, until), bytes)
|
} yield (xs.slice(from, until), bytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
implicit val arbitraryByteStringBuilder: Arbitrary[ByteStringBuilder] = Arbitrary(ByteString.newBuilder)
|
||||||
|
|
||||||
def likeVector(bs: ByteString)(body: IndexedSeq[Byte] ⇒ Any): Boolean = {
|
def likeVector(bs: ByteString)(body: IndexedSeq[Byte] ⇒ Any): Boolean = {
|
||||||
val vec = Vector(bs: _*)
|
val vec = Vector(bs: _*)
|
||||||
body(bs) == body(vec)
|
body(bs) == body(vec)
|
||||||
|
|
@ -552,5 +554,17 @@ class ByteStringSpec extends WordSpec with Matchers with Checkers {
|
||||||
"encoding Double in big-endian" in { check { slice: ArraySlice[Double] ⇒ testDoubleEncoding(slice, BIG_ENDIAN) } }
|
"encoding Double in big-endian" in { check { slice: ArraySlice[Double] ⇒ testDoubleEncoding(slice, BIG_ENDIAN) } }
|
||||||
"encoding Double in little-endian" in { check { slice: ArraySlice[Double] ⇒ testDoubleEncoding(slice, LITTLE_ENDIAN) } }
|
"encoding Double in little-endian" in { check { slice: ArraySlice[Double] ⇒ testDoubleEncoding(slice, LITTLE_ENDIAN) } }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
"have correct empty info" when {
|
||||||
|
"is empty" in {
|
||||||
|
check { a: ByteStringBuilder ⇒ a.isEmpty }
|
||||||
|
}
|
||||||
|
"is nonEmpty" in {
|
||||||
|
check { a: ByteStringBuilder ⇒
|
||||||
|
a.putByte(1.toByte)
|
||||||
|
a.nonEmpty
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -798,4 +798,14 @@ final class ByteStringBuilder extends Builder[Byte, ByteString] {
|
||||||
|
|
||||||
override def write(b: Array[Byte], off: Int, len: Int): Unit = { builder.putBytes(b, off, len) }
|
override def write(b: Array[Byte], off: Int, len: Int): Unit = { builder.putBytes(b, off, len) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests whether this ByteStringBuilder is empty.
|
||||||
|
*/
|
||||||
|
def isEmpty: Boolean = _length == 0
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests whether this ByteStringBuilder is not empty.
|
||||||
|
*/
|
||||||
|
def nonEmpty: Boolean = _length > 0
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue