mirror of
https://github.com/wneessen/apg-go.git
synced 2024-09-19 03:12:47 +02:00
Winni Neessen
93f092e690
The update introduces a new 'SpellPassword' setting in the configuration that, when enabled, spells out the generated passwords in the phonetic alphabet. The accompanied changes include the addition of 'spelling.go' and 'spelling_test.go' files containing the spelling logic and corresponding tests. The domain-specific error handling is also enhanced for unsupported characters.
53 lines
949 B
Go
53 lines
949 B
Go
package apg
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestConvertByteToWord(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
char byte
|
|
want string
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "UpperCaseChar",
|
|
char: 'A',
|
|
want: alphabetNames['A'],
|
|
wantErr: false,
|
|
},
|
|
{
|
|
name: "LowerCaseChar",
|
|
char: 'a',
|
|
want: strings.ToLower(alphabetNames['A']),
|
|
wantErr: false,
|
|
},
|
|
{
|
|
name: "NonAlphaChar",
|
|
char: '(',
|
|
want: symbNumNames['('],
|
|
wantErr: false,
|
|
},
|
|
{
|
|
name: "UnsupportedChar",
|
|
char: 'ü',
|
|
want: "",
|
|
wantErr: true,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, err := ConvertByteToWord(tt.char)
|
|
if (err != nil) != tt.wantErr {
|
|
t.Errorf("ConvertByteToWord() error = %v, wantErr %v", err, tt.wantErr)
|
|
return
|
|
}
|
|
if got != tt.want {
|
|
t.Errorf("ConvertByteToWord() got = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|