Skip to content

Commit fea29df

Browse files
grahammilnDHowett
authored andcommitted
marshal: bring in []interface{} and array-of-constrained-interface tests from PR 75
Closes #75
1 parent 4106a7e commit fea29df

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

marshal_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,33 @@ func TestMarshalInterfaceFieldPtrTime(t *testing.T) {
126126
t.Error("failed to marshal toplevel dictionary (?)")
127127
}
128128
}
129+
130+
type Dog struct {
131+
Name string
132+
}
133+
134+
type Animal interface{}
135+
136+
func TestInterfaceSliceMarshal(t *testing.T) {
137+
x := make([]Animal, 0)
138+
x = append(x, &Dog{Name: "dog"})
139+
140+
b, err := Marshal(x, XMLFormat)
141+
if err != nil {
142+
t.Error(err)
143+
} else if len(b) == 0 {
144+
t.Error("expect non-zero data")
145+
}
146+
}
147+
148+
func TestInterfaceGeneralSliceMarshal(t *testing.T) {
149+
x := make([]interface{}, 0) // accept any type
150+
x = append(x, &Dog{Name: "dog"}, "a string", 1, true)
151+
152+
b, err := Marshal(x, XMLFormat)
153+
if err != nil {
154+
t.Error(err)
155+
} else if len(b) == 0 {
156+
t.Error("expect non-zero data")
157+
}
158+
}

0 commit comments

Comments
 (0)