示例#1
0
文件: date_test.go 项目: fxtlabs/date
func TestInvalidJSON(t *testing.T) {
	cases := []struct {
		value string
		want  string
	}{
		{`"not-a-date"`, `Date.ParseISO: cannot parse not-a-date`},
		{`2015-08-15"`, `Date.UnmarshalJSON: missing double quotes (2015-08-15")`},
		{`"2015-08-15`, `Date.UnmarshalJSON: missing double quotes ("2015-08-15)`},
		{`"215-08-15"`, `Date.ParseISO: cannot parse 215-08-15`},
	}
	for _, c := range cases {
		var d date.Date
		err := d.UnmarshalJSON([]byte(c.value))
		if err == nil || err.Error() != c.want {
			t.Errorf("InvalidJSON(%v) == %v, want %v", c.value, err, c.want)
		}
	}
}