From f3a4b516d1154b9c155a04c49d851bacfbd5004b Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Fri, 4 Aug 2023 18:38:55 +0200 Subject: [PATCH] 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. --- mode_test.go | 46 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/mode_test.go b/mode_test.go index f4a498b..9d5a324 100644 --- a/mode_test.go +++ b/mode_test.go @@ -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) + } + } + }) + } +}