-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlog_test.go
More file actions
140 lines (120 loc) · 2.33 KB
/
log_test.go
File metadata and controls
140 lines (120 loc) · 2.33 KB
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package dl_test
import (
"bytes"
"strings"
"testing"
"github.com/task4233/dl/v2"
)
func TestFPrintf(t *testing.T) {
t.Parallel()
tests := map[string]struct {
message string
args []any
want string
}{
"success with string": {
message: "hoge",
args: nil,
want: "hoge",
},
"success with format string": {
message: "hoge: %s",
args: []any{"fuga"},
want: "hoge: [fuga]",
},
"success with empty string": {
message: "",
args: nil,
want: "",
},
"success with nil": {
message: "",
args: nil,
want: "",
},
}
for name, tt := range tests {
tt := tt
t.Run(name, func(t *testing.T) {
t.Parallel()
out := new(bytes.Buffer)
if tt.args == nil {
dl.Fprintf(out, tt.message)
} else {
dl.Fprintf(out, tt.message, tt.args)
}
if tt.want != out.String() {
t.Fatalf("failed TestPrintf, want=%s,got=%s", tt.want, out.String())
}
})
}
}
func TestFPrintln(t *testing.T) {
t.Parallel()
tests := map[string]struct {
args []any
want string
}{
"success with string": {
args: nil,
want: "<nil>\n",
},
"success with format string": {
args: []any{"fuga"},
want: "[fuga]\n",
},
}
for name, tt := range tests {
tt := tt
t.Run(name, func(t *testing.T) {
t.Parallel()
out := new(bytes.Buffer)
if tt.args == nil {
dl.Fprintln(out, nil)
} else {
dl.Fprintln(out, tt.args)
}
if tt.want != out.String() {
t.Fatalf("failed TestPrintf, want=%s,got=%s", tt.want, out.String())
}
})
}
}
func TestFInfo(t *testing.T) {
t.Parallel()
var (
num_ = 1
nil_ any = nil
)
tests := map[string]struct {
args any
want string
}{
"success with nil": {
args: nil,
want: "[DeLog] info: nil log_test.go:133\n",
},
"success with untyped int": {
args: 1,
want: "[DeLog] info: 1 (int) log_test.go:133\n",
},
"success with a variable": {
args: num_,
want: "[DeLog] info: 1 (int) log_test.go:133\n",
},
"success with a nil variable": {
args: nil_,
want: "[DeLog] info: nil log_test.go:133\n",
},
}
for name, tt := range tests {
tt := tt
t.Run(name, func(t *testing.T) {
out := new(bytes.Buffer)
dl.FInfo(out, tt.args)
if !strings.Contains(out.String(), tt.want) {
t.Fatalf("failed TestPrintf, \nwant=%s,got=%s", tt.want, out.String())
}
})
}
}