From 704269d0b8dc72799b5fb4387742ac2e99ad1604 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Fri, 4 Aug 2023 18:38:32 +0200 Subject: [PATCH] #53 Reorder modes and add new test case for mode flags This commit primarily reorders the modes in the "mode_test.go" file for consistency. The order is now; ModeHumanReadable, ModeLowerCase, ModeNumber, ModeSpecial, ModeUpperCase. This now follows a logical order instead of the previous semi arbitrary one. The commit also involves the addition of a new test case 'TestModesFromFlags' in the "mode_test.go" file. This test case aims at increasing the code coverage and ensuring modes obtained from the flags are correct. Lastly, the 'ModesFromFlags' function in the "mode.go" has been slightly refactored for improved readability. This does not change the functionality and thus won't affect the rest of the codebase. --- mode.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mode.go b/mode.go index af7dd1e..595906c 100644 --- a/mode.go +++ b/mode.go @@ -1,6 +1,8 @@ package apg -import "strings" +import ( + "strings" +) // Mode represents a mode of characters type Mode uint8 @@ -56,8 +58,9 @@ func MaskToggleMode(ma ModeMask, mo Mode) ModeMask { return ModeMask(uint8(ma) ^ func MaskHasMode(ma ModeMask, mo Mode) bool { return uint8(ma)&uint8(mo) != 0 } func ModesFromFlags(ms string) ModeMask { + cl := strings.Split(ms, "") var mm ModeMask - for _, m := range strings.Split(ms, "") { + for _, m := range cl { switch m { case "C": mm = MaskSetMode(mm, ModeLowerCase|ModeNumber|ModeSpecial|ModeUpperCase)