diff --git a/random.go b/random.go index 1195b2e..312dfa5 100644 --- a/random.go +++ b/random.go @@ -354,6 +354,9 @@ func (g *Generator) generateRandom() (string, error) { ok = g.checkMinimumRequirements(password) } + if g.config.MobileGrouping { + return GroupCharsForMobile(password), nil + } return password, nil } diff --git a/random_test.go b/random_test.go index 2b088bf..2d4c8b0 100644 --- a/random_test.go +++ b/random_test.go @@ -453,6 +453,27 @@ func TestGenerateRandom(t *testing.T) { } } +func TestGenerateRandom_withGrouping(t *testing.T) { + config := NewConfig(WithAlgorithm(AlgoRandom), WithMinLength(1), + WithMaxLength(1), WithMobileGrouping()) + config.MinNumeric = 1 + generator := New(config) + pw, err := generator.generateRandom() + if err != nil { + t.Errorf("generateRandom() failed: %s", err) + } + if len(pw) > 1 { + t.Errorf("expected password with length 1 but got: %d", len(pw)) + } + n, err := strconv.Atoi(pw) + if err != nil { + t.Errorf("expected password to be a number but got an error: %s", err) + } + if n < 0 || n > 9 { + t.Errorf("expected password to be a number between 0 and 9, got: %d", n) + } +} + func TestGenerate(t *testing.T) { tests := []struct { name string