message_test.go 891 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package discordgo
  2. import (
  3. "testing"
  4. )
  5. func TestContentWithMoreMentionsReplaced(t *testing.T) {
  6. s := &Session{StateEnabled: true, State: NewState()}
  7. user := &User{
  8. ID: "user",
  9. Username: "User Name",
  10. }
  11. s.StateEnabled = true
  12. s.State.GuildAdd(&Guild{ID: "guild"})
  13. s.State.RoleAdd("guild", &Role{
  14. ID: "role",
  15. Name: "Role Name",
  16. Mentionable: true,
  17. })
  18. s.State.MemberAdd(&Member{
  19. User: user,
  20. Nick: "User Nick",
  21. GuildID: "guild",
  22. })
  23. s.State.ChannelAdd(&Channel{
  24. Name: "Channel Name",
  25. GuildID: "guild",
  26. ID: "channel",
  27. })
  28. m := &Message{
  29. Content: "<&role> <@!user> <@user> <#channel>",
  30. ChannelID: "channel",
  31. MentionRoles: []string{"role"},
  32. Mentions: []*User{user},
  33. }
  34. if result, _ := m.ContentWithMoreMentionsReplaced(s); result != "@Role Name @User Nick @User Name #Channel Name" {
  35. t.Error(result)
  36. }
  37. }