2023-08-04 16:02:58 +02:00
|
|
|
package apg
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSetClearHasToggleMode(t *testing.T) {
|
|
|
|
tt := []struct {
|
|
|
|
name string
|
|
|
|
mode Mode
|
|
|
|
}{
|
2023-08-04 18:38:55 +02:00
|
|
|
{"ModeHumanReadable", ModeHumanReadable},
|
2023-08-04 16:02:58 +02:00
|
|
|
{"ModeLowerCase", ModeLowerCase},
|
2023-08-05 17:54:41 +02:00
|
|
|
{"ModeNumeric", ModeNumeric},
|
2023-08-04 16:02:58 +02:00
|
|
|
{"ModeSpecial", ModeSpecial},
|
2023-08-04 18:38:55 +02:00
|
|
|
{"ModeUpperCase", ModeUpperCase},
|
2023-08-04 16:02:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range tt {
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
2023-08-04 17:14:24 +02:00
|
|
|
var m ModeMask
|
|
|
|
m = MaskSetMode(m, tc.mode)
|
|
|
|
if !MaskHasMode(m, tc.mode) {
|
|
|
|
t.Errorf("MaskSetMode() failed, mode not found in bitmask")
|
2023-08-04 16:02:58 +02:00
|
|
|
}
|
2023-08-04 17:14:24 +02:00
|
|
|
m = MaskToggleMode(m, tc.mode)
|
|
|
|
if MaskHasMode(m, tc.mode) {
|
|
|
|
t.Errorf("MaskToggleMode() failed, mode found in bitmask")
|
2023-08-04 16:02:58 +02:00
|
|
|
}
|
2023-08-04 17:14:24 +02:00
|
|
|
m = MaskToggleMode(m, tc.mode)
|
|
|
|
if !MaskHasMode(m, tc.mode) {
|
|
|
|
t.Errorf("MaskToggleMode() failed, mode not found in bitmask")
|
2023-08-04 16:02:58 +02:00
|
|
|
}
|
2023-08-04 17:14:24 +02:00
|
|
|
m = MaskClearMode(m, tc.mode)
|
|
|
|
if MaskHasMode(m, tc.mode) {
|
|
|
|
t.Errorf("MaskClearMode() failed, mode found in bitmask")
|
2023-08-04 16:02:58 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2023-08-04 18:38:55 +02:00
|
|
|
|
|
|
|
func TestModesFromFlags(t *testing.T) {
|
|
|
|
tt := []struct {
|
|
|
|
name string
|
|
|
|
ms string
|
|
|
|
mode []Mode
|
|
|
|
}{
|
2023-08-05 17:54:41 +02:00
|
|
|
{"ModeComplex", "C", []Mode{ModeLowerCase, ModeNumeric, ModeSpecial,
|
2023-08-04 18:38:55 +02:00
|
|
|
ModeUpperCase}},
|
|
|
|
{"ModeHumanReadable", "H", []Mode{ModeHumanReadable}},
|
|
|
|
{"ModeLowerCase", "L", []Mode{ModeLowerCase}},
|
2023-08-05 17:54:41 +02:00
|
|
|
{"ModeNumeric", "N", []Mode{ModeNumeric}},
|
2023-08-04 18:38:55 +02:00
|
|
|
{"ModeUpperCase", "U", []Mode{ModeUpperCase}},
|
|
|
|
{"ModeSpecial", "S", []Mode{ModeSpecial}},
|
2023-08-04 20:29:43 +02:00
|
|
|
{"ModeLowerSpecialUpper", "LSUH", []Mode{ModeHumanReadable,
|
|
|
|
ModeLowerCase, ModeSpecial, ModeUpperCase}},
|
|
|
|
{"ModeComplexNoHumanReadable", "Ch", []Mode{ModeLowerCase,
|
2023-08-05 17:54:41 +02:00
|
|
|
ModeNumeric, ModeSpecial, ModeUpperCase}},
|
|
|
|
{"ModeComplexNoLower", "Cl", []Mode{ModeNumeric, ModeSpecial,
|
2023-08-04 18:38:55 +02:00
|
|
|
ModeUpperCase}},
|
|
|
|
{"ModeComplexNoNumber", "Cn", []Mode{ModeLowerCase, ModeSpecial,
|
|
|
|
ModeUpperCase}},
|
2023-08-05 17:54:41 +02:00
|
|
|
{"ModeComplexNoSpecial", "Cs", []Mode{ModeLowerCase, ModeNumeric,
|
2023-08-04 18:38:55 +02:00
|
|
|
ModeUpperCase}},
|
2023-08-05 17:54:41 +02:00
|
|
|
{"ModeComplexNoUpper", "Cu", []Mode{ModeLowerCase, ModeNumeric,
|
2023-08-04 18:38:55 +02:00
|
|
|
ModeSpecial}},
|
|
|
|
}
|
|
|
|
for _, tc := range tt {
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
|
var mm ModeMask
|
|
|
|
mm = ModesFromFlags(tc.ms)
|
|
|
|
for _, tm := range tc.mode {
|
|
|
|
if !MaskHasMode(mm, tm) {
|
|
|
|
t.Errorf("ModesFromFlags() failed, expected mode %q not found",
|
|
|
|
tm)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2023-08-04 20:29:43 +02:00
|
|
|
|
|
|
|
func TestMode_String(t *testing.T) {
|
|
|
|
tt := []struct {
|
|
|
|
name string
|
|
|
|
m Mode
|
|
|
|
e string
|
|
|
|
}{
|
|
|
|
{"ModeHumanReadable", ModeHumanReadable, "Human-readable"},
|
|
|
|
{"ModeLowerCase", ModeLowerCase, "Lower-case"},
|
2023-08-05 17:54:41 +02:00
|
|
|
{"ModeNumeric", ModeNumeric, "Number"},
|
2023-08-04 20:29:43 +02:00
|
|
|
{"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())
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|