#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.
This commit is contained in:
Winni Neessen 2023-08-04 18:38:32 +02:00
parent b31219046a
commit 704269d0b8
Signed by: wneessen
GPG key ID: 5F3AF39B820C119D

View file

@ -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)