-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
mode_test.go
119 lines (113 loc) · 2.87 KB
/
mode_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
// SPDX-FileCopyrightText: 2021-2024 Winni Neessen <[email protected]>
//
// SPDX-License-Identifier: MIT
package apg
import (
"testing"
)
func TestSetClearHasToggleMode(t *testing.T) {
tt := []struct {
name string
mode Mode
}{
{"ModeHumanReadable", ModeHumanReadable},
{"ModeLowerCase", ModeLowerCase},
{"ModeNumeric", ModeNumeric},
{"ModeSpecial", ModeSpecial},
{"ModeUpperCase", ModeUpperCase},
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
var m ModeMask
m = MaskSetMode(m, tc.mode)
if !MaskHasMode(m, tc.mode) {
t.Errorf("MaskSetMode() failed, mode not found in bitmask")
}
m = MaskToggleMode(m, tc.mode)
if MaskHasMode(m, tc.mode) {
t.Errorf("MaskToggleMode() failed, mode found in bitmask")
}
m = MaskToggleMode(m, tc.mode)
if !MaskHasMode(m, tc.mode) {
t.Errorf("MaskToggleMode() failed, mode not found in bitmask")
}
m = MaskClearMode(m, tc.mode)
if MaskHasMode(m, tc.mode) {
t.Errorf("MaskClearMode() failed, mode found in bitmask")
}
})
}
}
func TestModesFromFlags(t *testing.T) {
tt := []struct {
name string
ms string
mode []Mode
}{
{"ModeComplex", "C", []Mode{
ModeLowerCase, ModeNumeric, ModeSpecial,
ModeUpperCase,
}},
{"ModeHumanReadable", "H", []Mode{ModeHumanReadable}},
{"ModeLowerCase", "L", []Mode{ModeLowerCase}},
{"ModeNumeric", "N", []Mode{ModeNumeric}},
{"ModeUpperCase", "U", []Mode{ModeUpperCase}},
{"ModeSpecial", "S", []Mode{ModeSpecial}},
{"ModeLowerSpecialUpper", "LSUH", []Mode{
ModeHumanReadable,
ModeLowerCase, ModeSpecial, ModeUpperCase,
}},
{"ModeComplexNoHumanReadable", "Ch", []Mode{
ModeLowerCase,
ModeNumeric, ModeSpecial, ModeUpperCase,
}},
{"ModeComplexNoLower", "Cl", []Mode{
ModeNumeric, ModeSpecial,
ModeUpperCase,
}},
{"ModeComplexNoNumber", "Cn", []Mode{
ModeLowerCase, ModeSpecial,
ModeUpperCase,
}},
{"ModeComplexNoSpecial", "Cs", []Mode{
ModeLowerCase, ModeNumeric,
ModeUpperCase,
}},
{"ModeComplexNoUpper", "Cu", []Mode{
ModeLowerCase, ModeNumeric,
ModeSpecial,
}},
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
mm := ModesFromFlags(tc.ms)
for _, tm := range tc.mode {
if !MaskHasMode(mm, tm) {
t.Errorf("ModesFromFlags() failed, expected mode %q not found", tm)
}
}
})
}
}
func TestMode_String(t *testing.T) {
tt := []struct {
name string
m Mode
e string
}{
{"ModeHumanReadable", ModeHumanReadable, "Human-readable"},
{"ModeLowerCase", ModeLowerCase, "Lower-case"},
{"ModeNumeric", ModeNumeric, "Numeric"},
{"ModeSpecial", ModeSpecial, "Special"},
{"ModeUpperCase", ModeUpperCase, "Upper-case"},
{"ModeUnknown", 255, "Unknown"},
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
if tc.m.String() != tc.e {
t.Errorf("Mode.String() failed, expected: %s, got: %s", tc.e,
tc.m.String())
}
})
}
}