Skip to content

Commit

Permalink
reflect: add tests that verify that [Slice,String]Header is the same …
Browse files Browse the repository at this point in the history
…size as [slice,string]
  • Loading branch information
ydnar committed Mar 3, 2024
1 parent c5fcbbb commit 2ef1270
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/reflect/intw_avr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ package reflect_test
import (
"reflect"
"testing"
"unsafe"
)

// Verify that SliceHeader is the same size as a slice.
var _ [unsafe.Sizeof([]byte{})]byte = [unsafe.Sizeof(reflect.SliceHeader{})]byte{}

// TestSliceHeaderIntegerSize verifies that SliceHeader.Len and Cap are type uintptr on AVR platforms.
// See https://github.com/tinygo-org/tinygo/issues/1284.
func TestSliceHeaderIntegerSize(t *testing.T) {
Expand All @@ -15,6 +19,9 @@ func TestSliceHeaderIntegerSize(t *testing.T) {
h.Cap = uintptr(0)
}

// Verify that StringHeader is the same size as a string.
var _ [unsafe.Sizeof("hello")]byte = [unsafe.Sizeof(reflect.StringHeader{})]byte{}

// TestStringHeaderIntegerSize verifies that StringHeader.Len and Cap are type uintptr on AVR platforms.
// See https://github.com/tinygo-org/tinygo/issues/1284.
func TestStringHeaderIntegerSize(t *testing.T) {
Expand Down
7 changes: 7 additions & 0 deletions src/reflect/intw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ package reflect_test
import (
"reflect"
"testing"
"unsafe"
)

// Verify that SliceHeader is the same size as a slice.
var _ [unsafe.Sizeof([]byte{})]byte = [unsafe.Sizeof(reflect.SliceHeader{})]byte{}

// TestSliceHeaderIntegerSize verifies that SliceHeader.Len and Cap are type int on non-AVR platforms.
// See https://github.com/tinygo-org/tinygo/issues/1284.
func TestSliceHeaderIntegerSize(t *testing.T) {
Expand All @@ -15,6 +19,9 @@ func TestSliceHeaderIntegerSize(t *testing.T) {
h.Cap = int(0)
}

// Verify that StringHeader is the same size as a string.
var _ [unsafe.Sizeof("hello")]byte = [unsafe.Sizeof(reflect.StringHeader{})]byte{}

// TestStringHeaderIntegerSize verifies that StringHeader.Len and Cap are type int on non-AVR platforms.
// See https://github.com/tinygo-org/tinygo/issues/1284.
func TestStringHeaderIntegerSize(t *testing.T) {
Expand Down

0 comments on commit 2ef1270

Please sign in to comment.