Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
csenet committed Apr 12, 2024
1 parent a44cc0e commit c7b7b3a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,10 @@ func ScreenName2user(logger *zap.Logger, sess *discordgo.Session, guildID string
var usernameRe = regexp.MustCompile(`(^.{2,32})#(\d{4}$)`)

func DiscordUserParse(usernameRaw string) (username, discriminator string, err error) {
// name shoud be 2-32 characters
if utf8string.NewString(usernameRaw).RuneCount() < 2 || utf8string.NewString(usernameRaw).RuneCount() > 32 {
return "", "", fmt.Errorf("username length invalid")
}
if !usernameRe.MatchString(usernameRaw) {
// for new type username
return usernameRaw, "", nil
Expand Down
10 changes: 6 additions & 4 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,6 @@ func TestDiscordUserParse(t *testing.T) {
descriminator: "1234",
wantErr: false,
},
"missmatch pattern": {
input: "onlyname",
wantErr: false,
},
"misspattern": {
input: `a`,
wantErr: true,
Expand All @@ -143,6 +139,12 @@ func TestDiscordUserParse(t *testing.T) {
assert.Equal(t, v.descriminator, d)
})
}
t.Run("new type username pattern", func(t *testing.T) {
u, d, err := DiscordUserParse("username")
assert.Empty(t, err)
assert.Equal(t, "username", u)
assert.Empty(t, d)
})
}

func TestCreateMsg(t *testing.T) {
Expand Down

0 comments on commit c7b7b3a

Please sign in to comment.