mirror of
https://github.com/wneessen/apg-go.git
synced 2024-11-22 05:40:51 +01:00
Winni Neessen
1c22c9b8f0
The error message format in `ModesFromFlags()` method within `mode_test.go` has been refactored. The refactoring improved the clarity and conciseness of error reporting when the expected mode is not found during test execution.
115 lines
2.8 KiB
Go
115 lines
2.8 KiB
Go
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())
|
|
}
|
|
})
|
|
}
|
|
}
|