mirror of
https://github.com/ergochat/ergo.git
synced 2025-01-01 15:42:38 +01:00
51 lines
1.2 KiB
Go
51 lines
1.2 KiB
Go
// Copyright (c) 2018 Shivaram Lingamneni
|
|
// released under the MIT license
|
|
|
|
package modes
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestSetMode(t *testing.T) {
|
|
set := NewModeSet()
|
|
|
|
if applied := set.SetMode(Invisible, false); applied != false {
|
|
t.Errorf("all modes should be false by default")
|
|
}
|
|
|
|
if applied := set.SetMode(Invisible, true); applied != true {
|
|
t.Errorf("initial SetMode call should return true")
|
|
}
|
|
|
|
set.SetMode(Operator, true)
|
|
|
|
if applied := set.SetMode(Invisible, true); applied != false {
|
|
t.Errorf("redundant SetMode call should return false")
|
|
}
|
|
|
|
expected1 := []Mode{Invisible, Operator}
|
|
expected2 := []Mode{Operator, Invisible}
|
|
if allModes := set.AllModes(); !(reflect.DeepEqual(allModes, expected1) || reflect.DeepEqual(allModes, expected2)) {
|
|
t.Errorf("unexpected AllModes value: %v", allModes)
|
|
}
|
|
|
|
if modeString := set.String(); !(modeString == "io" || modeString == "oi") {
|
|
t.Errorf("unexpected modestring: %s", modeString)
|
|
}
|
|
}
|
|
|
|
func TestNilReceivers(t *testing.T) {
|
|
var set ModeSet
|
|
|
|
if set.HasMode(Invisible) {
|
|
t.Errorf("nil ModeSet should not have any modes")
|
|
}
|
|
|
|
str := set.String()
|
|
if str != "" {
|
|
t.Errorf("nil Modeset should have empty String(), got %v instead", str)
|
|
}
|
|
}
|