-
Notifications
You must be signed in to change notification settings - Fork 0
/
int32_test.go
86 lines (80 loc) · 1.74 KB
/
int32_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
package pointer
import (
"fmt"
"testing"
)
func TestInt32(t *testing.T) {
tests := []int32{
-(1 << 31), -1, 0, 1, ^int32(0) >> 1,
}
for _, v := range tests {
var p *int32 = Int32(v)
if p == nil {
t.Errorf("Int32(%v) = nil; want %v", v, v)
}
if n := Int32Value(p); n != v {
t.Errorf("Int32(%v) = %v; want %v", v, n, v)
}
}
}
func TestInt32Slice(t *testing.T) {
data := []int32{
-(1 << 31), -1, 0, 1, ^int32(0) >> 1,
}
a := Int32Slice(data...)
if len(a) != len(data) {
t.Errorf("len(slice) = %d; want %d", len(a), len(data))
return
}
for i, p := range a {
v := data[i]
switch {
case p == nil:
t.Errorf("Int32Slice(%v)[%d] = nil; want %v", data, i, v)
case *p != v:
t.Errorf("Int32Slice(%v)[%d] = %v; want %v", data, i, *p, v)
}
}
}
func TestInt32Value_Nil(t *testing.T) {
var zero int32
v := Int32Value(nil)
if v != zero {
t.Errorf("Int32Value(nil) = %v; want %v", v, zero)
}
}
func TestEqualInt32(t *testing.T) {
tests := []struct {
v1, v2 *int32
eq bool
}{
{Int32(-(1 << 31)), Int32(-1), false},
{Int32(-(1 << 31)), Int32(-(1 << 31)), true},
{Int32(-1), Int32(-1), true},
{nil, nil, true},
{nil, Int32(-(1 << 31)), false},
{Int32(-(1 << 31)), nil, false},
}
for _, tt := range tests {
if eq := EqualInt32(tt.v1, tt.v2); eq != tt.eq {
t.Errorf("EqualInt32(%d, %d) = %t; want %t", tt.v1, tt.v2, eq, tt.eq)
}
}
}
func TestInt32FormatterFormat(t *testing.T) {
tests := []struct {
p *int32
s string
}{
{Int32(-(1 << 31)), fmt.Sprintf("%v", -(1 << 31))},
{Int32(-1), fmt.Sprintf("%v", -1)},
{nil, "<nil>"},
}
for _, tt := range tests {
p := NewInt32Formatter(tt.p)
s := fmt.Sprintf("%v", p)
if s != tt.s {
t.Errorf("{%+v}.Format() = %q; want %q", p, s, tt.s)
}
}
}