-
Notifications
You must be signed in to change notification settings - Fork 2
/
encoders_test.go
59 lines (55 loc) · 1.45 KB
/
encoders_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package pinboard
import (
"encoding/xml"
"reflect"
"testing"
"time"
)
func TestPostTagsUnmarshal(t *testing.T) {
type tagsTest struct {
XMLName xml.Name
Tags postTags `xml:"tags,attr"`
}
got := &tagsTest{}
want := postTags{"foo", "bar", "baz"}
body := `<post tags="foo bar baz"/>`
err := xml.Unmarshal([]byte(body), got)
if err != nil {
t.Errorf("Failed to %v unmarshal body", err)
}
if !reflect.DeepEqual(want, got.Tags) {
t.Errorf("Wanted %v, got %v", want, got.Tags)
}
}
func TestUtcDateUnmarshal(t *testing.T) {
type utcDateTest struct {
XMLName xml.Name
Created utcDate `xml:"created_at,attr"`
}
got := &utcDateTest{}
want := utcDate{time.Date(1985, time.June, 27, 0, 0, 0, 0, time.UTC)}
body := `<post created_at="1985-06-27"/>`
err := xml.Unmarshal([]byte(body), got)
if err != nil {
t.Errorf("Failed to %v unmarshal body", err)
}
if !reflect.DeepEqual(want, got.Created) {
t.Errorf("Wanted %v, got %v", want, got.Created)
}
}
func TestNotesDateUnmarshal(t *testing.T) {
type notesDateTest struct {
XMLName xml.Name
Created notesDate `xml:"created_at,attr"`
}
got := ¬esDateTest{}
want := notesDate{time.Date(1985, time.June, 27, 15, 13, 33, 0, time.UTC)}
body := `<post created_at="1985-06-27 15:13:33"/>`
err := xml.Unmarshal([]byte(body), got)
if err != nil {
t.Errorf("Failed to %v unmarshal body", err)
}
if !reflect.DeepEqual(want, got.Created) {
t.Errorf("Wanted %v, got %v", want, got.Created)
}
}