diff options
author | Colin Cross <ccross@android.com> | 2015-11-20 17:03:25 -0800 |
---|---|---|
committer | Colin Cross <ccross@android.com> | 2015-11-20 17:26:52 -0800 |
commit | 9d1469d55967c45fc9b985efda9ceddd1a74a934 (patch) | |
tree | 9e4f7e19560352dc2d5e2e4b976322750a1df322 /unpack_test.go | |
parent | 83cedbec8582347a12b4233a34b269eebab3b0e6 (diff) | |
download | android_build_blueprint-9d1469d55967c45fc9b985efda9ceddd1a74a934.tar.gz android_build_blueprint-9d1469d55967c45fc9b985efda9ceddd1a74a934.tar.bz2 android_build_blueprint-9d1469d55967c45fc9b985efda9ceddd1a74a934.zip |
Support embedded anonymous property structs
Allow property structs to contain anonymous embedded structs and
interfaces. Properties in an anonymous embedded struct or interface are
treated as if they were properties in the embedding struct.
Diffstat (limited to 'unpack_test.go')
-rw-r--r-- | unpack_test.go | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/unpack_test.go b/unpack_test.go index 77a57ec..b33ae79 100644 --- a/unpack_test.go +++ b/unpack_test.go @@ -228,8 +228,137 @@ var validUnpackTestCases = []struct { }, }, }, + + // Anonymous struct + {` + m { + name: "abc", + nested: { + name: "def", + }, + } + `, + struct { + EmbeddedStruct + Nested struct { + EmbeddedStruct + } + }{ + EmbeddedStruct: EmbeddedStruct{ + Name: "abc", + }, + Nested: struct { + EmbeddedStruct + }{ + EmbeddedStruct: EmbeddedStruct{ + Name: "def", + }, + }, + }, + nil, + }, + + // Anonymous interface + {` + m { + name: "abc", + nested: { + name: "def", + }, + } + `, + struct { + EmbeddedInterface + Nested struct { + EmbeddedInterface + } + }{ + EmbeddedInterface: &struct{ Name string }{ + Name: "abc", + }, + Nested: struct { + EmbeddedInterface + }{ + EmbeddedInterface: &struct{ Name string }{ + Name: "def", + }, + }, + }, + nil, + }, + + // Anonymous struct with name collision + {` + m { + name: "abc", + nested: { + name: "def", + }, + } + `, + struct { + Name string + EmbeddedStruct + Nested struct { + Name string + EmbeddedStruct + } + }{ + Name: "abc", + EmbeddedStruct: EmbeddedStruct{ + Name: "abc", + }, + Nested: struct { + Name string + EmbeddedStruct + }{ + Name: "def", + EmbeddedStruct: EmbeddedStruct{ + Name: "def", + }, + }, + }, + nil, + }, + + // Anonymous interface with name collision + {` + m { + name: "abc", + nested: { + name: "def", + }, + } + `, + struct { + Name string + EmbeddedInterface + Nested struct { + Name string + EmbeddedInterface + } + }{ + Name: "abc", + EmbeddedInterface: &struct{ Name string }{ + Name: "abc", + }, + Nested: struct { + Name string + EmbeddedInterface + }{ + Name: "def", + EmbeddedInterface: &struct{ Name string }{ + Name: "def", + }, + }, + }, + nil, + }, } +type EmbeddedStruct struct{ Name string } +type EmbeddedInterface interface{} + func TestUnpackProperties(t *testing.T) { for _, testCase := range validUnpackTestCases { r := bytes.NewBufferString(testCase.input) |