-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtype_scan_test.go
121 lines (86 loc) · 1.58 KB
/
type_scan_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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package fourcc
import (
"testing"
)
func TestTypeScan(t *testing.T) {
tests := []struct{
Value interface{}
Expected Type
}{
{
Value: "PAL8",
Expected: FOURCC('P','A','L','8'),
},
{
Value: []byte("PAL8"),
Expected: FOURCC('P','A','L','8'),
},
{
Value: uint32(0),
Expected: FOURCC(0x00,0x00,0x00,0x00),
},
{
Value: uint32(0xffffffff),
Expected: FOURCC('ÿ','ÿ','ÿ','ÿ'),
},
{
Value: uint64(0),
Expected: FOURCC(0x00,0x00,0x00,0x00),
},
{
Value: uint64(0xffffffff),
Expected: FOURCC('ÿ','ÿ','ÿ','ÿ'),
},
}
for testNumber, test := range tests {
var actual Type
if err := actual.Scan(test.Value); nil != err {
t.Errorf("For test #%d, did not expect an error, but actually got one: (%T) %q", testNumber, err, err)
continue
}
if expected := test.Expected; expected != actual {
t.Errorf("For test #%d, expected %q, but actually got %q.", testNumber, expected, actual)
continue
}
}
}
func TestTypeScanError(t *testing.T) {
tests := []struct{
Value interface{}
}{
{
Value: false,
},
{
Value: true,
},
{
Value: int8(5),
},
{
Value: int16(5),
},
{
Value: int32(5),
},
{
Value: uint8(5),
},
{
Value: uint16(5),
},
{
Value: "apple banana cherry",
},
{
Value: []byte("apple banana cherry"),
},
}
for testNumber, test := range tests {
var actual Type
if err := actual.Scan(test.Value); nil == err {
t.Errorf("For test #%d, expected an error, but did not actually got one: (%T) %q", testNumber, err, err)
continue
}
}
}