forked from crypt0train/go-cgminer-api
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnumber_test.go
48 lines (43 loc) · 878 Bytes
/
number_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
package cgminer
import (
"strings"
"testing"
)
func TestNumber_UnmarshalJSON(t *testing.T) {
cases := map[string]struct {
want Number
err string
}{
`"32"`: {
want: Number(32),
},
`32`: {
want: Number(32),
},
"": {},
`""`: {},
"null": {},
`{"fff": 32}`: {
err: "Number.UnmarshalJSON: value is not a number",
},
`[1,2,3]`: {
err: "Number.UnmarshalJSON: value is not a number",
},
}
for input, c := range cases {
t.Run(input, func(t *testing.T) {
var got Number
if err := got.UnmarshalJSON([]byte(input)); err != nil {
if c.err == "" {
t.Fatal("unexpected error:", err)
}
if msg := err.Error(); !strings.Contains(msg, c.err) {
t.Fatalf("error message doesn't contains %q\nin: %s", c.err, msg)
}
}
if got != c.want {
t.Fatalf("value mismatch: %f != %f", got, c.want)
}
})
}
}