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.

89 lines
2.2 KiB

package isupport_test
import (
"github.com/gissleh/irc/isupport"
"reflect"
"strings"
"testing"
)
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"
var is isupport.ISupport
func init() {
for _, token := range strings.Split(isupportMessages, " ") {
pair := strings.SplitN(token, "=", 2)
if len(pair) == 2 {
is.Set(pair[0], pair[1])
} else {
is.Set(pair[0], "")
}
}
}
func TestISupport_ParsePrefixedNick(t *testing.T) {
table := []struct {
Full string
Prefixes string
Modes string
Nick string
}{
{"User", "", "", "User"},
{"+User", "+", "v", "User"},
{"@%+User", "@%+", "ohv", "User"},
{"~User", "~", "a", "User"},
}
for _, row := range table {
t.Run(row.Full, func(t *testing.T) {
nick, modes, prefixes := is.ParsePrefixedNick(row.Full)
assertEq(t, row.Nick, nick, "nick")
assertEq(t, row.Modes, modes, "modes")
assertEq(t, row.Prefixes, prefixes, "prefixes")
})
}
}
func TestISupport_IsChannel(t *testing.T) {
table := map[string]bool{
"#Test": true,
"&Test": true,
"User": false,
"+Stuff": false,
"#TestAndSuch": true,
"@astrwef": false,
}
for channelName, isChannel := range table {
t.Run(channelName, func(t *testing.T) {
assertEq(t, isChannel, is.IsChannel(channelName), "isChannel")
})
}
}
func TestISupport_IsPermissionMode(t *testing.T) {
table := map[rune]bool{
'#': false,
'+': false,
'o': true,
'v': true,
'h': true,
'a': true,
'g': false,
'p': false,
}
for flag, expected := range table {
t.Run(string(flag), func(t *testing.T) {
assertEq(t, expected, is.IsPermissionMode(flag), "")
})
}
}
func assertEq(t *testing.T, a interface{}, b interface{}, failMessage string) {
if !reflect.DeepEqual(a, b) {
t.Errorf("Assert failed: %s (%#+v != %#+v)", failMessage, a, b)
}
}