feat: add unittest to check panic on inexactly overlap

This commit is contained in:
cuiweixie 2025-12-03 19:56:50 +08:00
parent 8f9de727bb
commit 04fd64d135
No known key found for this signature in database
GPG key ID: 16DF64EE15E495A3

View file

@ -104,6 +104,32 @@ func TestOR(t *testing.T) {
}
}
func TestORBytesInexactOverlap(t *testing.T) {
shouldPanic := func(f func()) (ok bool) {
defer func() {
if r := recover(); r != nil {
if r.(string) == "ORBytes: invalid overlap" {
ok = true
}
}
}()
f()
return
}
a := make([]byte, 5)
if ok := shouldPanic(func() {
ORBytes(a[1:4], a[0:3], make([]byte, 3))
}); !ok {
t.Error("expected panic on inexact overlap")
}
if ok := shouldPanic(func() {
ORBytes(a[1:4], make([]byte, 3), a[0:3])
}); !ok {
t.Error("expected panic on inexact overlap")
}
}
// Tests that bit testing works for various alignments.
func TestTest(t *testing.T) {
for align := 0; align < 2; align++ {