-
Notifications
You must be signed in to change notification settings - Fork 72
/
json_test.go
68 lines (62 loc) · 1.24 KB
/
json_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
60
61
62
63
64
65
66
67
68
package tomltest
import (
"testing"
)
func TestCompareDatetime(t *testing.T) {
return
tests := []struct {
kind, want, have string
wantFail bool
}{
{"datetime", "2006-01-02T15:04:05.123Z", "2006-01-02T15:04:05.123Z", false},
{"datetime", "2006-01-02T15:04:05.123Z", "2006-01-02T15:04:05", true},
{"time-local", "15:04:05.123", "15:04:05.123", false},
{"time-local", "15:04:05.123", "15:04:05", true},
}
for _, tt := range tests {
t.Run("", func(t *testing.T) {
r := Test{}
r = r.cmpAsDatetimes(tt.kind, tt.want, tt.have)
if tt.wantFail && r.Failure == "" {
t.Fatal("wanted fail, but no failure")
}
if !tt.wantFail && r.Failure != "" {
t.Fatalf("unexpected failure:\n%s", r.Failure)
}
})
}
}
func TestCompareNaN(t *testing.T) {
a := map[string]any{
"nan": map[string]any{
"type": "float",
"value": "nan",
},
}
b := map[string]any{
"nan": map[string]any{
"type": "float",
"value": "+nan",
},
}
c := map[string]any{
"nan": map[string]any{
"type": "float",
"value": "-nan",
},
}
{
r := Test{}
r = r.CompareJSON(a, b)
if r.Failure != "" {
t.Fatal(r.Failure)
}
}
{
r := Test{}
r = r.CompareJSON(b, c)
if r.Failure != "" {
t.Fatal(r.Failure)
}
}
}