Skip to content

Commit

Permalink
test custom alphabet
Browse files Browse the repository at this point in the history
  • Loading branch information
jackspirou committed Sep 17, 2024
1 parent 5c05f3b commit 55297ab
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions publicid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package publicid

import (
"fmt"
"strings"
"testing"
)

Expand Down Expand Up @@ -124,3 +125,19 @@ func TestNewFailsAfterAttempts(t *testing.T) {
}
}
}

func TestNewWithCustomAlphabet(t *testing.T) {
customAlphabet := "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
id, err := New(Alphabet(customAlphabet))
if err != nil {
t.Errorf("New(Alphabet(%q)) returned an error: %v", customAlphabet, err)
}
if len(id) != DefaultIDLength {
t.Errorf("New(Alphabet(%q)) returned id with length %d, want %d", customAlphabet, len(id), DefaultIDLength)
}
for _, char := range id {
if !strings.ContainsRune(customAlphabet, char) {
t.Errorf("New(Alphabet(%q)) returned id containing invalid character: %c", customAlphabet, char)
}
}
}

0 comments on commit 55297ab

Please sign in to comment.