package main import ( "testing" "git.stormux.org/storm/barnard/gumble/gumble" "git.stormux.org/storm/barnard/uiterm" ) func TestMatchesVolumeResetKeyAcceptsBothTerminalBackspaces(t *testing.T) { configured := uiterm.KeyBackspace if !matchesVolumeResetKey(&configured, uiterm.KeyBackspace) { t.Fatal("configured backspace did not match itself") } if !matchesVolumeResetKey(&configured, uiterm.KeyBackspace2) { t.Fatal("configured backspace did not match delete/127 representation") } if matchesVolumeResetKey(&configured, uiterm.KeyDelete) { t.Fatal("delete key unexpectedly matched volume reset") } } func TestTreeMuteDefaultMatchesLowerAndUpperM(t *testing.T) { configured := uiterm.KeyM for _, ch := range []rune{'m', 'M'} { if !matchesCharacterHotkey(&configured, ch) { t.Errorf("%q did not match tree mute binding", ch) } } } func TestTreeItemDistinguishesMuteKinds(t *testing.T) { tests := []struct { name string user func() *gumble.User want string }{ { name: "local mute", user: func() *gumble.User { u := &gumble.User{Name: "Username"} u.SetLocallyMuted(true) return u }, want: "[LOCALLY MUTED] Username", }, {name: "server mute", user: func() *gumble.User { return &gumble.User{Name: "Username", Muted: true} }, want: "[SERVER MUTED] Username"}, {name: "self mute", user: func() *gumble.User { return &gumble.User{Name: "Username", SelfMuted: true} }, want: "[SELF MUTED] Username"}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { if got := (TreeItem{User: tt.user()}).String(); got != tt.want { t.Fatalf("display = %q, want %q", got, tt.want) } }) } } // Regression: rebuilding the channel tree ranged protocol-owned maps without // Client.Do while TCP handlers could add or remove users/channels. func TestTreeItemBuildReadsMapsUnderClientSnapshot(t *testing.T) { root := &gumble.Channel{ID: 0, Users: gumble.Users{}, Children: gumble.Channels{}} user := &gumble.User{Session: 1, Name: "user"} child := &gumble.Channel{ID: 2, Name: "child", Users: gumble.Users{}, Children: gumble.Channels{}} root.Users[user.Session] = user root.Children[child.ID] = child b := &Barnard{Client: &gumble.Client{Channels: gumble.Channels{0: root}}, MutedChannels: map[uint32]bool{}} items := b.TreeItemBuild(TreeItem{Channel: root}) if len(items) != 2 { t.Fatalf("got %d items", len(items)) } }