MCPcopy
hub / github.com/tinygo-org/tinygo / TestAlignment

Function TestAlignment

src/reflect/all_test.go:1342–1363  ·  view source on GitHub ↗

Check that structure alignment & offsets viewed through reflect agree with those from the compiler itself.

(t *testing.T)

Source from the content-addressed store, hash-verified

1340// Check that structure alignment & offsets viewed through reflect agree with those
1341// from the compiler itself.
1342func TestAlignment(t *testing.T) {
1343 type T1inner struct {
1344 a int
1345 }
1346 type T1 struct {
1347 T1inner
1348 f int
1349 }
1350 type T2inner struct {
1351 a, b int
1352 }
1353 type T2 struct {
1354 T2inner
1355 f int
1356 }
1357
1358 x := T1{T1inner{2}, 17}
1359 check2ndField(x, uintptr(unsafe.Pointer(&x.f))-uintptr(unsafe.Pointer(&x)), t)
1360
1361 x1 := T2{T2inner{2, 3}, 17}
1362 check2ndField(x1, uintptr(unsafe.Pointer(&x1.f))-uintptr(unsafe.Pointer(&x1)), t)
1363}
1364
1365func Nil(a any, t *testing.T) {
1366 n := ValueOf(a).Field(0)

Callers

nothing calls this directly

Calls 2

check2ndFieldFunction · 0.85
PointerMethod · 0.80

Tested by

no test coverage detected