mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-22 11:59:40 +01:00
review fix: add nil receivers to other read-only ModeSet methods
This commit is contained in:
parent
0751f52f37
commit
f408d0f37b
@ -366,6 +366,10 @@ func (set *ModeSet) SetMode(mode Mode, on bool) (applied bool) {
|
||||
|
||||
// return the modes in the set as a slice
|
||||
func (set *ModeSet) AllModes() (result []Mode) {
|
||||
if set == nil {
|
||||
return
|
||||
}
|
||||
|
||||
set.RLock()
|
||||
defer set.RUnlock()
|
||||
|
||||
@ -376,22 +380,27 @@ func (set *ModeSet) AllModes() (result []Mode) {
|
||||
}
|
||||
|
||||
// String returns the modes in this set.
|
||||
func (set *ModeSet) String() string {
|
||||
func (set *ModeSet) String() (result string) {
|
||||
if set == nil {
|
||||
return
|
||||
}
|
||||
|
||||
set.RLock()
|
||||
defer set.RUnlock()
|
||||
|
||||
if len(set.modes) == 0 {
|
||||
return ""
|
||||
}
|
||||
var result []byte
|
||||
var buf strings.Builder
|
||||
for mode := range set.modes {
|
||||
result = append(result, mode.String()...)
|
||||
buf.WriteRune(rune(mode))
|
||||
}
|
||||
return string(result)
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
// Prefixes returns a list of prefixes for the given set of channel modes.
|
||||
func (set *ModeSet) Prefixes(isMultiPrefix bool) (prefixes string) {
|
||||
if set == nil {
|
||||
return
|
||||
}
|
||||
|
||||
set.RLock()
|
||||
defer set.RUnlock()
|
||||
|
||||
|
@ -35,3 +35,16 @@ func TestSetMode(t *testing.T) {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user