Mirror of github.com/gissleh/irc
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
2.0 KiB

  1. package isupport_test
  2. import (
  3. "github.com/gissleh/irc/isupport"
  4. "github.com/stretchr/testify/assert"
  5. "strings"
  6. "testing"
  7. )
  8. var isupportMessages = "FNC SAFELIST ELIST=CTU MONITOR=100 WHOX ETRACE KNOCK CHANTYPES=#& EXCEPTS INVEX CHANMODES=eIbq,k,flj,CFLNPQcgimnprstz CHANLIMIT=#&:15 PREFIX=(aovh)~@+% MAXLIST=bqeI:100 MODES=4 NETWORK=TestServer STATUSMSG=@+% CALLERID=g CASEMAPPING=rfc1459 NICKLEN=30 MAXNICKLEN=31 CHANNELLEN=50 TOPICLEN=390 DEAF=D TARGMAX=NAMES:1,LIST:1,KICK:1,WHOIS:1,PRIVMSG:4,NOTICE:4,ACCEPT:,MONITOR: EXTBAN=$,&acjmorsuxz| CLIENTVER=3.0"
  9. var is isupport.ISupport
  10. func init() {
  11. for _, token := range strings.Split(isupportMessages, " ") {
  12. pair := strings.SplitN(token, "=", 2)
  13. if len(pair) == 2 {
  14. is.Set(pair[0], pair[1])
  15. } else {
  16. is.Set(pair[0], "")
  17. }
  18. }
  19. }
  20. func TestISupport_ParsePrefixedNick(t *testing.T) {
  21. table := []struct {
  22. Full string
  23. Prefixes string
  24. Modes string
  25. Nick string
  26. }{
  27. {"User", "", "", "User"},
  28. {"+User", "+", "v", "User"},
  29. {"@%+User", "@%+", "ohv", "User"},
  30. {"~User", "~", "a", "User"},
  31. }
  32. for _, row := range table {
  33. t.Run(row.Full, func(t *testing.T) {
  34. nick, modes, prefixes := is.ParsePrefixedNick(row.Full)
  35. assert.Equal(t, row.Nick, nick)
  36. assert.Equal(t, row.Modes, modes)
  37. assert.Equal(t, row.Prefixes, prefixes)
  38. })
  39. }
  40. }
  41. func TestISupport_IsChannel(t *testing.T) {
  42. table := map[string]bool{
  43. "#Test": true,
  44. "&Test": true,
  45. "User": false,
  46. "+Stuff": false,
  47. "#TestAndSuch": true,
  48. "@astrwef": false,
  49. }
  50. for channelName, isChannel := range table {
  51. t.Run(channelName, func(t *testing.T) {
  52. assert.Equal(t, isChannel, is.IsChannel(channelName))
  53. })
  54. }
  55. }
  56. func TestISupport_IsPermissionMode(t *testing.T) {
  57. table := map[rune]bool{
  58. '#': false,
  59. '+': false,
  60. 'o': true,
  61. 'v': true,
  62. 'h': true,
  63. 'a': true,
  64. 'g': false,
  65. 'p': false,
  66. }
  67. for flag, expected := range table {
  68. t.Run(string(flag), func(t *testing.T) {
  69. assert.Equal(t, expected, is.IsPermissionMode(flag))
  70. })
  71. }
  72. }