Skip to content

Fix a typo in slice-to-array conversion tests. #1089

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 16, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 19 additions & 36 deletions tests/slice_to_array_ptr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ func TestSliceToArrayPointerConversion(t *testing.T) {
// GopherJS uses TypedArray for numeric types and Array for everything else
// since those are substantially different types, the tests are repeated
// for both.
expectOutOfBoundsPanic := func(t *testing.T) {
t.Helper()
if recover() == nil {
t.Error("out-of-bounds conversion of s should panic")
}
}

t.Run("Numeric", func(t *testing.T) {
s := make([]byte, 2, 4)
t.Run("NotNil", func(t *testing.T) {
Expand All @@ -28,15 +35,9 @@ func TestSliceToArrayPointerConversion(t *testing.T) {
})

t.Run("SliceToLargerArray", func(t *testing.T) {
r := func() (r interface{}) {
defer func() { r = recover() }()
s4 := (*[4]byte)(s)
_ = s4
return nil
}()
if r == nil {
t.Error("out-of-bounds conversion of s should panic")
}
defer expectOutOfBoundsPanic(t)
s4 := (*[4]byte)(s)
_ = s4
})

t.Run("SharedMemory", func(t *testing.T) {
Expand All @@ -62,15 +63,9 @@ func TestSliceToArrayPointerConversion(t *testing.T) {
})

t.Run("NilSliceToLargerArray", func(t *testing.T) {
r := func() (r interface{}) {
defer func() { r = recover() }()
q1 := (*[1]byte)(q)
_ = q1
return nil
}
if r == nil {
t.Error("out-of-bounds conversion of q should panic")
}
defer expectOutOfBoundsPanic(t)
q1 := (*[1]byte)(q)
_ = q1
})

t.Run("ZeroLenSlice", func(t *testing.T) {
Expand Down Expand Up @@ -105,15 +100,9 @@ func TestSliceToArrayPointerConversion(t *testing.T) {
})

t.Run("SliceToLargerArray", func(t *testing.T) {
r := func() (r interface{}) {
defer func() { r = recover() }()
s4 := (*[4]string)(s)
_ = s4
return nil
}()
if r == nil {
t.Error("out-of-bounds conversion of s should panic")
}
defer expectOutOfBoundsPanic(t)
s4 := (*[4]string)(s)
_ = s4
})

t.Run("SharedMemory", func(t *testing.T) {
Expand All @@ -140,15 +129,9 @@ func TestSliceToArrayPointerConversion(t *testing.T) {
})

t.Run("NilSliceToLargerArray", func(t *testing.T) {
r := func() (r interface{}) {
defer func() { r = recover() }()
q1 := (*[1]string)(q)
_ = q1
return nil
}
if r == nil {
t.Error("out-of-bounds conversion of q should panic")
}
defer expectOutOfBoundsPanic(t)
q1 := (*[1]string)(q)
_ = q1
})

t.Run("ZeroLenSlice", func(t *testing.T) {
Expand Down