-
Notifications
You must be signed in to change notification settings - Fork 3
/
codes_test.go
63 lines (54 loc) · 1.44 KB
/
codes_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
package goval
import (
"testing"
)
type customTypeButSameBase ruleCode
func (c customTypeButSameBase) Equal(other RuleCoder) bool {
v, ok := other.(customTypeButSameBase)
return ok && v == c
}
func (c customTypeButSameBase) String() string { return ruleCode(c).String() }
type customTypeButSameRootBase int
func (c customTypeButSameRootBase) Equal(other RuleCoder) bool {
v, ok := other.(customTypeButSameRootBase)
return ok && v == c
}
func (c customTypeButSameRootBase) String() string { return ruleCode(c).String() }
func TestRuleCode_Equal(t *testing.T) {
tests := []struct {
desc string
got bool
exp bool
}{
{
desc: "type and value is same",
got: NumberRequired.Equal(NumberRequired),
exp: true,
},
{
desc: "type same but value is different",
got: NumberRequired.Equal(NumberRequired),
exp: true,
},
{
desc: "type and value is same. But, it used value literal",
got: NumberRequired.Equal(ruleCode(3000)),
exp: true,
},
{
desc: "type is different and literal value is same, but the source type is same",
got: NumberRequired.Equal(customTypeButSameBase(3000)),
exp: false,
},
{
desc: "type is different and literal value is same, but the root source type is same",
got: NumberRequired.Equal(customTypeButSameRootBase(3000)),
exp: false,
},
}
for _, tc := range tests {
if tc.got != tc.exp {
t.Fatalf("got: %-6v. exp: %-6v. %s", tc.got, tc.exp, tc.desc)
}
}
}