aboutsummaryrefslogtreecommitdiffhomepage
path: root/testdata
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2019-08-08 14:41:52 +0200
committerRon Evans <[email protected]>2019-08-08 15:23:47 +0200
commite2c8654237bd2893c256e1a268ce350952d4fb4c (patch)
tree835ab0118b2cf5f2b8433fea4ed674e49b1557c9 /testdata
parent5012be337f59c45833e4c9dc55feeaf0d86f52bf (diff)
downloadtinygo-e2c8654237bd2893c256e1a268ce350952d4fb4c.tar.gz
tinygo-e2c8654237bd2893c256e1a268ce350952d4fb4c.zip
reflect: add support for struct types
Diffstat (limited to 'testdata')
-rw-r--r--testdata/reflect.go26
-rw-r--r--testdata/reflect.txt77
2 files changed, 100 insertions, 3 deletions
diff --git a/testdata/reflect.go b/testdata/reflect.go
index 7c8a10d19..fc28b1893 100644
--- a/testdata/reflect.go
+++ b/testdata/reflect.go
@@ -11,6 +11,17 @@ type (
myslice2 []myint
mychan chan int
myptr *int
+ point struct {
+ X int16
+ Y int16
+ }
+ mystruct struct {
+ n int `foo:"bar"`
+ some point
+ zero struct{}
+ buf []byte
+ Buf []byte
+ }
)
func main() {
@@ -86,6 +97,12 @@ func main() {
// structs
struct{}{},
struct{ error }{},
+ struct {
+ a uint8
+ b int16
+ c int8
+ }{42, 321, 123},
+ mystruct{5, point{-5, 3}, struct{}{}, []byte{'G', 'o'}, []byte{'X'}},
} {
showValue(reflect.ValueOf(v), "")
}
@@ -291,7 +308,14 @@ func showValue(rv reflect.Value, indent string) {
showValue(rv.Index(i), indent+" ")
}
case reflect.Struct:
- println(indent + " struct")
+ println(indent+" struct:", rt.NumField())
+ for i := 0; i < rv.NumField(); i++ {
+ field := rt.Field(i)
+ println(indent+" field:", i, field.Name)
+ println(indent+" tag:", field.Tag)
+ println(indent+" embedded:", field.Anonymous)
+ showValue(rv.Field(i), indent+" ")
+ }
default:
println(indent + " unknown type kind!")
}
diff --git a/testdata/reflect.txt b/testdata/reflect.txt
index f43a62248..9a3e39777 100644
--- a/testdata/reflect.txt
+++ b/testdata/reflect.txt
@@ -217,9 +217,82 @@ reflect type: map
map
nil: false
reflect type: struct
- struct
+ struct: 0
reflect type: struct
- struct
+ struct: 1
+ field: 0 error
+ tag:
+ embedded: true
+ reflect type: interface
+ interface
+ nil: true
+reflect type: struct
+ struct: 3
+ field: 0 a
+ tag:
+ embedded: false
+ reflect type: uint8
+ uint: 42
+ field: 1 b
+ tag:
+ embedded: false
+ reflect type: int16
+ int: 321
+ field: 2 c
+ tag:
+ embedded: false
+ reflect type: int8
+ int: 123
+reflect type: struct
+ struct: 5
+ field: 0 n
+ tag: foo:"bar"
+ embedded: false
+ reflect type: int
+ int: 5
+ field: 1 some
+ tag:
+ embedded: false
+ reflect type: struct
+ struct: 2
+ field: 0 X
+ tag:
+ embedded: false
+ reflect type: int16
+ int: -5
+ field: 1 Y
+ tag:
+ embedded: false
+ reflect type: int16
+ int: 3
+ field: 2 zero
+ tag:
+ embedded: false
+ reflect type: struct
+ struct: 0
+ field: 3 buf
+ tag:
+ embedded: false
+ reflect type: slice
+ slice: uint8 2 2
+ pointer: true
+ nil: false
+ indexing: 0
+ reflect type: uint8
+ uint: 71
+ indexing: 1
+ reflect type: uint8
+ uint: 111
+ field: 4 Buf
+ tag:
+ embedded: false
+ reflect type: slice
+ slice: uint8 1 1
+ pointer: true
+ nil: false
+ indexing: 0
+ reflect type: uint8 settable=true
+ uint: 88
sizes:
int8 1 8