This repository has been archived by the owner on Oct 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
cop_test.go
151 lines (138 loc) · 3.5 KB
/
cop_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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package aci
import (
"fmt"
"testing"
)
func ExampleComparisonOperator_Compare() {
fmt.Printf("%Ts are identical: %t", Ne, Ne.Compare(Eq))
// Output: aci.ComparisonOperators are identical: false
}
func ExampleComparisonOperator_stringers() {
for _, cop := range []ComparisonOperator{
Eq, Ne, Lt, Gt, Le, Ge,
} {
fmt.Printf("[%d] %s (%s)[%s]\n",
int(cop),
cop.Description(),
cop.Context(),
cop)
}
// Output:
// [1] Equal To (Eq)[=]
// [2] Not Equal To (Ne)[!=]
// [3] Less Than (Lt)[<]
// [4] Greater Than (Gt)[>]
// [5] Less Than Or Equal (Le)[<=]
// [6] Greater Than Or Equal (Ge)[>=]
}
func ExampleComparisonOperator_Valid() {
var unknown ComparisonOperator = ComparisonOperator(12)
fmt.Printf("Is a known %T: %t", unknown, unknown.Valid() == nil)
// Output: Is a known aci.ComparisonOperator: false
}
/*
This example demonstrates the string representation for all
known ComparisonOperator constants.
*/
func ExampleComparisonOperator_String() {
for _, cop := range []ComparisonOperator{
Eq, Ne, Lt, Gt, Le, Ge,
} {
fmt.Printf("%s\n", cop)
}
// Output:
// =
// !=
// <
// >
// <=
// >=
}
/*
This example demonstrates the use of the Context method to show
all the context name for all ComparisonOperator constants.
*/
func ExampleComparisonOperator_Context() {
for _, cop := range []ComparisonOperator{
Eq, Ne, Lt, Gt, Le, Ge,
} {
fmt.Printf("%s\n", cop.Context())
}
// Output:
// Eq
// Ne
// Lt
// Gt
// Le
// Ge
}
/*
This example demonstrates the use of the Description method to
show all descriptive text for all ComparisonOperator constants.
*/
func ExampleComparisonOperator_Description() {
for _, cop := range []ComparisonOperator{
Eq, Ne, Lt, Gt, Le, Ge,
} {
fmt.Printf("%s\n", cop.Description())
}
// Output:
// Equal To
// Not Equal To
// Less Than
// Greater Than
// Less Than Or Equal
// Greater Than Or Equal
}
func TestComparisonOperator_codecov(t *testing.T) {
var lousyCop ComparisonOperator = ComparisonOperator(7)
_ = lousyCop.String()
_ = lousyCop.Context()
_ = lousyCop.Description()
_ = lousyCop.Valid()
_ = lousyCop.Compare(Eq)
_ = lousyCop.Compare(1)
_ = lousyCop.Compare(`=`)
_ = lousyCop.Compare(`eq`)
_ = lousyCop.Compare(`equal to`)
_ = lousyCop.Compare(3.14567)
// test permutations of keywords and cops
permutations := map[string]map[Keyword][]any{
`valid`: {
// target keywords
Target: {`eq`, `ne`, Eq, Ne, 1, 2},
TargetTo: {`eq`, `ne`},
TargetFrom: {`eq`, `ne`},
TargetCtrl: {`eq`, `ne`},
TargetAttr: {`eq`, `ne`},
TargetFilter: {`eq`, `ne`, Ne, 2},
TargetExtOp: {`eq`, `ne`},
TargetScope: {`eq`},
TargetAttrFilters: {`eq`, 1, Eq},
// bind keywords
BindUDN: {`eq`, `ne`, Eq, "equal to", `EQ`},
BindGDN: {`eq`, Ne, `not equal to`, `NE`, `ne`},
BindRDN: {`eq`, `ne`},
BindDNS: {`eq`, `ne`},
BindUAT: {`eq`, `ne`},
BindGAT: {`eq`, `ne`},
BindDoW: {`eq`, `ne`},
BindIP: {`eq`, `ne`},
BindAM: {`eq`, `ne`},
BindToD: {`eq`, 4, `ne`, Le, `LE`, 6, `le`, Lt, `LT`, `lt`, 3, Ge, `GE`, `ge`, Gt, `GT`, `gt`},
BindSSF: {`eq`, 1, `ne`, Le, `LE`, 5, `le`, Lt, `LT`, 2, `lt`, Ge, `GE`, `ge`, Gt, `GT`, `gt`},
},
}
for typ, kwmap := range permutations {
for kw, values := range kwmap {
for i := 0; i < len(values); i++ {
op := values[i]
if !keywordAllowsComparisonOperator(kw, op) {
t.Errorf("%s [%s] failed: %s %T [%v] denied or not resolved",
t.Name(), kw, typ, badCop, op)
return
}
}
}
}
}