mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Ensure that safemem.BlockSeqOf(safemem.Block{}) produces an empty BlockSeq.
PiperOrigin-RevId: 298941855
This commit is contained in:
@@ -20,6 +20,27 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestBlockSeqOfEmptyBlock(t *testing.T) {
|
||||
bs := BlockSeqOf(Block{})
|
||||
if !bs.IsEmpty() {
|
||||
t.Errorf("BlockSeqOf(Block{}).IsEmpty(): got false, wanted true; BlockSeq is %v", bs)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBlockSeqOfNonemptyBlock(t *testing.T) {
|
||||
b := BlockFromSafeSlice(make([]byte, 1))
|
||||
bs := BlockSeqOf(b)
|
||||
if bs.IsEmpty() {
|
||||
t.Fatalf("BlockSeqOf(non-empty Block).IsEmpty(): got true, wanted false; BlockSeq is %v", bs)
|
||||
}
|
||||
if head := bs.Head(); head != b {
|
||||
t.Fatalf("BlockSeqOf(non-empty Block).Head(): got %v, wanted %v", head, b)
|
||||
}
|
||||
if tail := bs.Tail(); !tail.IsEmpty() {
|
||||
t.Fatalf("BlockSeqOf(non-empty Block).Tail().IsEmpty(): got false, wanted true: tail is %v", tail)
|
||||
}
|
||||
}
|
||||
|
||||
type blockSeqTest struct {
|
||||
desc string
|
||||
|
||||
|
||||
@@ -56,6 +56,9 @@ type BlockSeq struct {
|
||||
|
||||
// BlockSeqOf returns a BlockSeq representing the single Block b.
|
||||
func BlockSeqOf(b Block) BlockSeq {
|
||||
if b.length == 0 {
|
||||
return BlockSeq{}
|
||||
}
|
||||
bs := BlockSeq{
|
||||
data: b.start,
|
||||
length: -1,
|
||||
|
||||
Reference in New Issue
Block a user