Skip to content

Commit

Permalink
Undo structs.DisplayName() and structs_test.go
Browse files Browse the repository at this point in the history
  • Loading branch information
nemoola committed Mar 1, 2024
1 parent 4b6c377 commit cce7c35
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
9 changes: 9 additions & 0 deletions structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1557,6 +1557,15 @@ func (m *Member) AvatarURL(size string) string {

}

// DisplayName returns the member's guild nickname if they have one,
// otherwise it returns their discord display name.
func (m *Member) DisplayName() string {
if m.Nick != "" {
return m.Nick
}
return m.User.GlobalName
}

// ClientStatus stores the online, offline, idle, or dnd status of each device of a Guild member.
type ClientStatus struct {
Desktop Status `json:"desktop"`
Expand Down
36 changes: 36 additions & 0 deletions structs_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Discordgo - Discord bindings for Go
// Available at https://github.com/bwmarrin/discordgo

// Copyright 2015-2016 Bruce Marriner <bruce@sqls.net>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package discordgo

import (
"testing"
)

func TestMember_DisplayName(t *testing.T) {

Check failure on line 14 in structs_test.go

View workflow job for this annotation

GitHub Actions / lint

TestMember_DisplayName redeclared in this block

Check failure on line 14 in structs_test.go

View workflow job for this annotation

GitHub Actions / test (1.13)

TestMember_DisplayName redeclared in this block

Check failure on line 14 in structs_test.go

View workflow job for this annotation

GitHub Actions / test (1.14)

TestMember_DisplayName redeclared in this block

Check failure on line 14 in structs_test.go

View workflow job for this annotation

GitHub Actions / test (1.15)

TestMember_DisplayName redeclared in this block

Check failure on line 14 in structs_test.go

View workflow job for this annotation

GitHub Actions / test (1.16)

TestMember_DisplayName redeclared in this block

Check failure on line 14 in structs_test.go

View workflow job for this annotation

GitHub Actions / test (1.17)

TestMember_DisplayName redeclared in this block

Check failure on line 14 in structs_test.go

View workflow job for this annotation

GitHub Actions / test (1.18)

TestMember_DisplayName redeclared in this block
user := &User{
GlobalName: "Global",
}
t.Run("no server nickname set", func(t *testing.T) {

Check failure on line 18 in structs_test.go

View workflow job for this annotation

GitHub Actions / test (1.13)

TestMember_DisplayName.func1 redeclared in this block

Check failure on line 18 in structs_test.go

View workflow job for this annotation

GitHub Actions / test (1.14)

TestMember_DisplayName.func1 redeclared in this block

Check failure on line 18 in structs_test.go

View workflow job for this annotation

GitHub Actions / test (1.15)

TestMember_DisplayName.func1 redeclared in this block
m := &Member{
Nick: "",
User: user,
}
if dn := m.DisplayName(); dn != user.GlobalName {
t.Errorf("Member.DisplayName() = %v, want %v", dn, user.GlobalName)
}
})
t.Run("server nickname set", func(t *testing.T) {

Check failure on line 27 in structs_test.go

View workflow job for this annotation

GitHub Actions / test (1.13)

TestMember_DisplayName.func2 redeclared in this block

Check failure on line 27 in structs_test.go

View workflow job for this annotation

GitHub Actions / test (1.14)

TestMember_DisplayName.func2 redeclared in this block

Check failure on line 27 in structs_test.go

View workflow job for this annotation

GitHub Actions / test (1.15)

TestMember_DisplayName.func2 redeclared in this block
m := &Member{
Nick: "Server",
User: user,
}
if dn := m.DisplayName(); dn != m.Nick {
t.Errorf("Member.DisplayName() = %v, want %v", dn, m.Nick)
}
})
}

0 comments on commit cce7c35

Please sign in to comment.