-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
day_time_test.go
52 lines (43 loc) · 1.15 KB
/
day_time_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
package jsonx
import (
"encoding/json"
"testing"
"time"
)
func TestDayTime(t *testing.T) {
tests := []struct {
rawData string
}{
{
rawData: `{"start": "8:33:00", "end": "15:00:42", "nothing": null, "empty": ""}`,
},
{
rawData: `{"start": "8:33:00", "end": "15:00:42", "nothing": null, "empty": ""}`,
},
}
for _, tt := range tests {
v := struct {
Start DayTime `json:"start"`
End DayTime `json:"end"`
Nothing DayTime `json:"nothing"`
Empty DayTime `json:"empty"`
}{}
err := json.Unmarshal([]byte(tt.rawData), &v)
if err != nil {
t.Fatal(err)
}
if !v.Nothing.IsZero() {
t.Fatalf("expected 'nothing' to be zero but got: %v", v.Nothing)
}
if !v.Empty.IsZero() {
t.Fatalf("expected 'empty' to be zero but got: %v", v.Empty)
}
loc := time.UTC
if expected, got := time.Date(0, time.January, 1, 8, 33, 0, 0, loc), v.Start.ToTime(); expected != got {
t.Fatalf("expected 'start' to be: %v but got: %v", expected, got)
}
if expected, got := time.Date(0, time.January, 1, 15, 0, 42, 0, loc), v.End.ToTime(); expected != got {
t.Fatalf("expected 'start' to be: %v but got: %v", expected, got)
}
}
}