Reorder modes and add new test for modes

The ordering of modes in the existing test was changed to logically group them together. In addition, a new test was added, `TestModesFromFlags`, to cover multiple different conditions including complex modes and cases where certain mode elements are excluded. This expansion in testing enhances our coverage of varied mode settings.
This commit is contained in:
Winni Neessen 2023-08-04 18:38:55 +02:00
parent 704269d0b8
commit f3a4b516d1
Signed by: wneessen
GPG key ID: 5F3AF39B820C119D

View file

@ -9,11 +9,11 @@ func TestSetClearHasToggleMode(t *testing.T) {
name string
mode Mode
}{
{"ModeNumber", ModeNumber},
{"ModeLowerCase", ModeLowerCase},
{"ModeUpperCase", ModeUpperCase},
{"ModeSpecial", ModeSpecial},
{"ModeHumanReadable", ModeHumanReadable},
{"ModeLowerCase", ModeLowerCase},
{"ModeNumber", ModeNumber},
{"ModeSpecial", ModeSpecial},
{"ModeUpperCase", ModeUpperCase},
}
for _, tc := range tt {
@ -38,3 +38,41 @@ func TestSetClearHasToggleMode(t *testing.T) {
})
}
}
func TestModesFromFlags(t *testing.T) {
tt := []struct {
name string
ms string
mode []Mode
}{
{"ModeComplex", "C", []Mode{ModeLowerCase, ModeNumber, ModeSpecial,
ModeUpperCase}},
{"ModeHumanReadable", "H", []Mode{ModeHumanReadable}},
{"ModeLowerCase", "L", []Mode{ModeLowerCase}},
{"ModeNumber", "N", []Mode{ModeNumber}},
{"ModeUpperCase", "U", []Mode{ModeUpperCase}},
{"ModeSpecial", "S", []Mode{ModeSpecial}},
{"ModeLowerSpecialUpper", "LSU", []Mode{ModeLowerCase, ModeSpecial,
ModeUpperCase}},
{"ModeComplexNoLower", "Cl", []Mode{ModeNumber, ModeSpecial,
ModeUpperCase}},
{"ModeComplexNoNumber", "Cn", []Mode{ModeLowerCase, ModeSpecial,
ModeUpperCase}},
{"ModeComplexNoSpecial", "Cs", []Mode{ModeLowerCase, ModeNumber,
ModeUpperCase}},
{"ModeComplexNoUpper", "Cu", []Mode{ModeLowerCase, ModeNumber,
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)
}
}
})
}
}