#53 Add ModeHumanReadable and refactor mode tests

Updated mode tests to include a new Mode, ModeHumanReadable, and created an additional test case, ModeComplexNoHumanReadable. This was done because a more human readable mode was required for some use cases. Also added a test function TestMode_String to ensure the .String() method of each mode works as intended.
This commit is contained in:
Winni Neessen 2023-08-04 20:29:43 +02:00
parent f3a4b516d1
commit 3cccc65498
Signed by: wneessen
GPG key ID: 5F3AF39B820C119D

View file

@ -52,8 +52,10 @@ func TestModesFromFlags(t *testing.T) {
{"ModeNumber", "N", []Mode{ModeNumber}},
{"ModeUpperCase", "U", []Mode{ModeUpperCase}},
{"ModeSpecial", "S", []Mode{ModeSpecial}},
{"ModeLowerSpecialUpper", "LSU", []Mode{ModeLowerCase, ModeSpecial,
ModeUpperCase}},
{"ModeLowerSpecialUpper", "LSUH", []Mode{ModeHumanReadable,
ModeLowerCase, ModeSpecial, ModeUpperCase}},
{"ModeComplexNoHumanReadable", "Ch", []Mode{ModeLowerCase,
ModeNumber, ModeSpecial, ModeUpperCase}},
{"ModeComplexNoLower", "Cl", []Mode{ModeNumber, ModeSpecial,
ModeUpperCase}},
{"ModeComplexNoNumber", "Cn", []Mode{ModeLowerCase, ModeSpecial,
@ -76,3 +78,26 @@ func TestModesFromFlags(t *testing.T) {
})
}
}
func TestMode_String(t *testing.T) {
tt := []struct {
name string
m Mode
e string
}{
{"ModeHumanReadable", ModeHumanReadable, "Human-readable"},
{"ModeLowerCase", ModeLowerCase, "Lower-case"},
{"ModeNumber", ModeNumber, "Number"},
{"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())
}
})
}
}