forked from KeKe-Li/log
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtime_format_test.go
116 lines (109 loc) · 1.57 KB
/
time_format_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
package log
import (
"bytes"
"testing"
"time"
)
func TestFormatTime(t *testing.T) {
now := time.Now()
have := FormatTime(now)
want := now.Format(TimeFormatLayout)
if have := string(have[:]); have != want {
t.Errorf("have:%s, want:%s", have, want)
return
}
}
func TestFormatTimeString(t *testing.T) {
now := time.Now()
have := FormatTimeString(now)
want := now.Format(TimeFormatLayout)
if have != want {
t.Errorf("have:%s, want:%s", have, want)
return
}
}
func TestItoa(t *testing.T) {
tests := []struct {
buf []byte
n int
want []byte
}{
{
make([]byte, 2),
0,
[]byte{'0', '0'},
},
{
make([]byte, 2),
1,
[]byte{'0', '1'},
},
{
make([]byte, 2),
2,
[]byte{'0', '2'},
},
{
make([]byte, 2),
11,
[]byte{'1', '1'},
},
{
make([]byte, 2),
98,
[]byte{'9', '8'},
},
{
make([]byte, 3),
0,
[]byte{'0', '0', '0'},
},
{
make([]byte, 3),
6,
[]byte{'0', '0', '6'},
},
{
make([]byte, 3),
67,
[]byte{'0', '6', '7'},
},
{
make([]byte, 3),
567,
[]byte{'5', '6', '7'},
},
{
make([]byte, 4),
0,
[]byte{'0', '0', '0', '0'},
},
{
make([]byte, 4),
6,
[]byte{'0', '0', '0', '6'},
},
{
make([]byte, 4),
67,
[]byte{'0', '0', '6', '7'},
},
{
make([]byte, 4),
567,
[]byte{'0', '5', '6', '7'},
},
{
make([]byte, 4),
4567,
[]byte{'4', '5', '6', '7'},
},
}
for _, v := range tests {
itoa(v.buf, v.n)
if !bytes.Equal(v.buf, v.want) {
t.Errorf("n=%d, have=%v, want=%v", v.n, v.buf, v.want)
return
}
}
}