Skip to content

Commit 324fc3f

Browse files
committedAug 25, 2023
test(randomstring_test.go): add test case for modifying character set based on generation options
This commit adds a new test case to the randomstring_test.go file. The test case tests the modifyCharset function, which modifies the character set based on the provided generation options. The test verifies that the function correctly modifies the character set based on the options and returns the expected result.
1 parent c16d90a commit 324fc3f

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
 

‎randomstring_test.go

+34
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,37 @@ func TestGenerateString(t *testing.T) {
5353
}
5454
}
5555
}
56+
57+
func TestModifyCharset(t *testing.T) {
58+
tests := []struct {
59+
opts GenerationOptions
60+
}{
61+
{GenerationOptions{DisableNumeric: true}},
62+
{GenerationOptions{DisableLowercase: true}},
63+
{GenerationOptions{DisableUppercase: true}},
64+
{GenerationOptions{EnableSpecialCharacter: true}},
65+
{GenerationOptions{DisableNumeric: true, DisableLowercase: true, DisableUppercase: true}},
66+
{GenerationOptions{DisableNumeric: true, DisableLowercase: true, DisableUppercase: true, EnableSpecialCharacter: true}},
67+
}
68+
69+
for _, tt := range tests {
70+
charset := modifyCharset(tt.opts, map[string]Charset{
71+
"numeric": Numeric,
72+
"lowercase": Lowercase,
73+
"uppercase": Uppercase,
74+
"specialCharater": SpecialCharacters,
75+
}, Alphanumeric)
76+
if !tt.opts.DisableNumeric && !tt.opts.DisableLowercase && !tt.opts.DisableUppercase && !tt.opts.EnableSpecialCharacter && charset != Alphanumeric {
77+
t.Errorf("expected charset to be Alphanumeric, got %v", charset)
78+
}
79+
if tt.opts.DisableNumeric && charset == Numeric {
80+
t.Errorf("expected charset to not contain numeric characters, got %v", charset)
81+
}
82+
if tt.opts.DisableLowercase && charset == Lowercase {
83+
t.Errorf("expected charset to not contain lowercase characters, got %v", charset)
84+
}
85+
if tt.opts.DisableUppercase && charset == Uppercase {
86+
t.Errorf("expected charset to not contain uppercase characters, got %v", charset)
87+
}
88+
}
89+
}

0 commit comments

Comments
 (0)