diff --git a/byteseq_test.go b/byteseq_test.go index 7903292..8ef956a 100644 --- a/byteseq_test.go +++ b/byteseq_test.go @@ -61,10 +61,10 @@ func Test_EqualFold(t *testing.T) { } for _, tc := range testCases { - res := EqualFold[string](tc.S1, tc.S2) + res := EqualFold(tc.S1, tc.S2) require.Equal(t, tc.Expected, res, "string") - res = EqualFold[[]byte]([]byte(tc.S1), []byte(tc.S2)) + res = EqualFold([]byte(tc.S1), []byte(tc.S2)) require.Equal(t, tc.Expected, res, "bytes") } } diff --git a/xml.go b/xml.go index 9cc2351..6e28f84 100644 --- a/xml.go +++ b/xml.go @@ -2,3 +2,8 @@ package utils // XMLMarshal returns the XML encoding of v. type XMLMarshal func(v any) ([]byte, error) + +// XMLUnmarshal parses the XML-encoded data and stores the result +// in the value pointed to by v. If v is nil or not a pointer, +// Unmarshal returns an InvalidUnmarshalError. +type XMLUnmarshal func(data []byte, v any) error diff --git a/xml_test.go b/xml_test.go index e4699e6..ff55753 100644 --- a/xml_test.go +++ b/xml_test.go @@ -59,3 +59,20 @@ func Test_DefaultXMLEncoder(t *testing.T) { require.Equal(t, string(raw), xmlString) } + +func Test_DefaultXMLDecoder(t *testing.T) { + t.Parallel() + + var ( + ss serversXMLStructure + xmlBytes = []byte(xmlString) + xmlDecoder XMLUnmarshal = xml.Unmarshal + ) + + err := xmlDecoder(xmlBytes, &ss) + require.Nil(t, err) + require.Equal(t, 2, len(ss.Servers)) + require.Equal(t, "1", ss.Version) + require.Equal(t, "fiber one", ss.Servers[0].Name) + require.Equal(t, "fiber two", ss.Servers[1].Name) +}