This commit is contained in:
parent
0eaeb726b9
commit
ba2314db4a
2 changed files with 36 additions and 0 deletions
|
@ -28,6 +28,7 @@ func TestParse(t *testing.T) {
|
||||||
{"float", types.Float},
|
{"float", types.Float},
|
||||||
{"float64", types.Float64},
|
{"float64", types.Float64},
|
||||||
{"float32", types.Float32},
|
{"float32", types.Float32},
|
||||||
|
{"string", types.String},
|
||||||
{"any", types.Any},
|
{"any", types.Any},
|
||||||
{"*any", types.AnyPointer},
|
{"*any", types.AnyPointer},
|
||||||
{"*byte", &types.Pointer{To: types.Byte}},
|
{"*byte", &types.Pointer{To: types.Byte}},
|
||||||
|
|
35
src/types/Struct_test.go
Normal file
35
src/types/Struct_test.go
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
package types_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"git.urbach.dev/cli/q/src/types"
|
||||||
|
"git.urbach.dev/go/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestStruct(t *testing.T) {
|
||||||
|
point := types.NewStruct("math", "Point")
|
||||||
|
|
||||||
|
x := &types.Field{
|
||||||
|
Name: "x",
|
||||||
|
Type: types.Int,
|
||||||
|
Index: 0,
|
||||||
|
Offset: 0,
|
||||||
|
}
|
||||||
|
|
||||||
|
y := &types.Field{
|
||||||
|
Name: "y",
|
||||||
|
Type: types.Int,
|
||||||
|
Index: 1,
|
||||||
|
Offset: 8,
|
||||||
|
}
|
||||||
|
|
||||||
|
point.AddField(x)
|
||||||
|
point.AddField(y)
|
||||||
|
|
||||||
|
assert.Equal(t, x.String(), "x")
|
||||||
|
assert.Equal(t, y.String(), "y")
|
||||||
|
assert.Equal(t, point.FieldByName("x"), x)
|
||||||
|
assert.Equal(t, point.FieldByName("y"), y)
|
||||||
|
assert.Nil(t, point.FieldByName("invalid"))
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue