mirror of
https://github.com/shazow/ssh-chat.git
synced 2025-04-17 09:22:21 +03:00
#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
44 lines
659 B
Go
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)
|
|
}
|
|
}
|