ssh-chat/chat/set_test.go
Federico Ruggi 58e1cb60bd commands: /ignore, /unignore
#154
* Add `/ignore`/`/unignore` commands
* Move set to common package, use set for ignores
* `chat/set.go` is now `common/set.go`
* use `*IdSet` as type for ignored list for users
* remove `IsIgnoring` and `IgnoredNames` user functions, so to use directly `IdSet` methods
* refactor code accordingly
2016-08-01 11:19:12 -04:00

44 lines
659 B
Go

package chat
import (
"testing"
"github.com/shazow/ssh-chat/chat/message"
"github.com/shazow/ssh-chat/common"
)
func TestSet(t *testing.T) {
var err error
s := common.NewIdSet()
u := message.NewUser(message.SimpleId("foo"))
if s.In(u) {
t.Errorf("Set should be empty.")
}
err = s.Add(u)
if err != nil {
t.Error(err)
}
if !s.In(u) {
t.Errorf("Set should contain user.")
}
u2 := message.NewUser(message.SimpleId("bar"))
err = s.Add(u2)
if err != nil {
t.Error(err)
}
err = s.Add(u2)
if err != common.ErrIdTaken {
t.Error(err)
}
size := s.Len()
if size != 2 {
t.Errorf("Set wrong size: %d (expected %d)", size, 2)
}
}