Skip to content

Commit ab4f65c

Browse files
committed
feat: add unittest to check panic on inexactly overlap
1 parent f751d91 commit ab4f65c

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

common/bitutil/bitutil_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,32 @@ func TestOR(t *testing.T) {
9292
}
9393
}
9494

95+
func TestORBytesInexactOverlap(t *testing.T) {
96+
shouldPanic := func(f func()) (ok bool) {
97+
defer func() {
98+
if r := recover(); r != nil {
99+
if r.(string) == "ORBytes: invalid overlap" {
100+
ok = true
101+
}
102+
}
103+
}()
104+
f()
105+
return
106+
}
107+
a := make([]byte, 5)
108+
if ok := shouldPanic(func() {
109+
ORBytes(a[1:4], a[0:3], make([]byte, 3))
110+
}); !ok {
111+
t.Error("expected panic on inexact overlap")
112+
}
113+
114+
if ok := shouldPanic(func() {
115+
ORBytes(a[1:4], make([]byte, 3), a[0:3])
116+
}); !ok {
117+
t.Error("expected panic on inexact overlap")
118+
}
119+
}
120+
95121
// Tests that bit testing works for various alignments.
96122
func TestTest(t *testing.T) {
97123
for align := 0; align < 2; align++ {

0 commit comments

Comments
 (0)