-
Notifications
You must be signed in to change notification settings - Fork 2
/
result_test.go
87 lines (80 loc) · 1.53 KB
/
result_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
// Copyright 2017 The StudyGolang Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
// https://studygolang.com
// Author: polaris polaris@studygolang.com
package cfg_test
import (
"testing"
"github.com/go-chinese-site/cfg"
)
func TestResultString(t *testing.T) {
tests := []struct {
result cfg.Result
expected string
}{
{
cfg.Result{Type: cfg.NotExists},
"",
},
{
cfg.Result{Type: cfg.Null},
"",
},
{
cfg.Result{Type: cfg.Number, Num: 10},
"10",
},
{
cfg.Result{Type: cfg.Number, Num: 10.2},
"10.2",
},
{
cfg.Result{Type: cfg.String, Str: "studygolang.com"},
"studygolang.com",
},
{
cfg.Result{Type: cfg.Interface, Raw: 10},
"10",
},
{
cfg.Result{Type: cfg.Interface, Raw: 10.2},
"10.2",
},
}
for _, tt := range tests {
actual := tt.result.String()
if actual != tt.expected {
t.Errorf("The String of the Result: %#v is %s, expected: %s", tt.result, actual, tt.expected)
}
}
}
func TestResultInt(t *testing.T) {
tests := []struct {
result cfg.Result
expected int
}{
{
cfg.Result{Type: cfg.NotExists},
0,
},
{
cfg.Result{Type: cfg.Null},
0,
},
{
cfg.Result{Type: cfg.Number, Num: 10},
10,
},
{
cfg.Result{Type: cfg.Interface, Raw: 10},
10,
},
}
for _, tt := range tests {
actual := tt.result.Int()
if actual != tt.expected {
t.Errorf("The Int of the Result: %#v is %d, expected: %d", tt.result, actual, tt.expected)
}
}
}