Skip to content

Commit bb7256f

Browse files
committed
wit: add additional ABI size and alignment tests for record and variant types
1 parent 831ae36 commit bb7256f

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

wit/abi_test.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func TestDiscriminant(t *testing.T) {
9999
}
100100
}
101101

102-
func TestTypeSize(t *testing.T) {
102+
func TestTypeSizeAndAlign(t *testing.T) {
103103
tests := []struct {
104104
name string
105105
v Type
@@ -119,6 +119,10 @@ func TestTypeSize(t *testing.T) {
119119
{"f64", F64{}, 8, 8},
120120
{"char", Char{}, 4, 4},
121121
{"string", String{}, 8, 4},
122+
{"option<string>", &TypeDef{Kind: &Option{Type: String{}}}, 12, 4},
123+
{"option<f32>", &TypeDef{Kind: &Option{Type: F32{}}}, 8, 4},
124+
{"variant", &TypeDef{Kind: &Variant{Cases: []Case{{Type: String{}}, {Type: F64{}}}}}, 16, 8},
125+
{"record", &TypeDef{Kind: &Record{Fields: []Field{{Type: U16{}}, {Type: &TypeDef{Kind: &Result{OK: U64{}}}}, {Type: U8{}}}}}, 32, 8},
122126
}
123127
for _, tt := range tests {
124128
t.Run(tt.name, func(t *testing.T) {
@@ -156,6 +160,7 @@ func TestTypeFlat(t *testing.T) {
156160
{"option<string>", &TypeDef{Kind: &Option{Type: String{}}}, []Type{U32{}, PointerTo(U8{}), U32{}}},
157161
{"option<f32>", &TypeDef{Kind: &Option{Type: F32{}}}, []Type{U32{}, F32{}}},
158162
{"variant", &TypeDef{Kind: &Variant{Cases: []Case{{Type: String{}}, {Type: F64{}}}}}, []Type{U32{}, U64{}, U32{}}},
163+
{"record", &TypeDef{Kind: &Record{Fields: []Field{{Type: U16{}}, {Type: &TypeDef{Kind: &Result{OK: U64{}}}}, {Type: U8{}}}}}, []Type{U32{}, U32{}, U64{}, U32{}}},
159164
}
160165
for _, tt := range tests {
161166
t.Run(tt.name, func(t *testing.T) {
@@ -177,9 +182,6 @@ func witFor[T Node](nodes ...T) []string {
177182

178183
// TestHasBorrow verifies that HasBorrow returns true for WIT types that contain a Borrow type.
179184
func TestHasBorrow(t *testing.T) {
180-
makeBorrow := func() *TypeDef { return &TypeDef{Kind: &Borrow{}} }
181-
makeTypeDef := func(kind TypeDefKind) *TypeDef { return &TypeDef{Kind: kind} }
182-
183185
testCases := []struct {
184186
name string
185187
typeDef *TypeDef
@@ -211,3 +213,11 @@ func TestHasBorrow(t *testing.T) {
211213
})
212214
}
213215
}
216+
217+
func makeTypeDef(kind TypeDefKind) *TypeDef {
218+
return &TypeDef{Kind: kind}
219+
}
220+
221+
func makeBorrow() *TypeDef {
222+
return &TypeDef{Kind: &Borrow{}}
223+
}

0 commit comments

Comments
 (0)