1package modes
2
3import "testing"
4
5func TestSlashSuggesterHidesUnjailUntilJailed(t *testing.T) {
6 s := newSlashSuggester()
7
8 if got := commandNames(s.matches("/unj")); contains(got, "/unjail") {
9 t.Fatalf("/unjail should be hidden while not jailed, got %v", got)
10 }
11 if got := commandNames(s.matches("/ja")); !contains(got, "/jail") {
12 t.Fatalf("/jail should be visible while not jailed, got %v", got)
13 }
14
15 s.SetJailed(true)
16 if got := commandNames(s.matches("/unj")); !contains(got, "/unjail") {
17 t.Fatalf("/unjail should be visible while jailed, got %v", got)
18 }
19 if got := commandNames(s.matches("/ja")); contains(got, "/jail") {
20 t.Fatalf("/jail should be hidden while jailed, got %v", got)
21 }
22}
23
24func TestSlashSuggesterShowsLlamaOnlyWhenConfigured(t *testing.T) {
25 s := newSlashSuggester()
26 if got := commandNames(s.matches("/llama")); contains(got, "/llama") {
27 t.Fatalf("/llama visible without login: %v", got)
28 }
29 s.SetLlamaConfigured(true)
30 if got := commandNames(s.matches("/llama")); !contains(got, "/llama") {
31 t.Fatalf("/llama missing with login: %v", got)
32 }
33}
34
35func TestSlashSuggesterHasSwarm(t *testing.T) {
36 s := newSlashSuggester()
37 if got := commandNames(s.matches("/sw")); !contains(got, "/swarm") {
38 t.Fatalf("/swarm missing from suggestions, got %v", got)
39 }
40}
41
42func TestSlashCommandsAreCaseInsensitive(t *testing.T) {
43 s := newSlashSuggester()
44 if got := commandNames(s.matches("/EX")); !contains(got, "/exit") {
45 t.Fatalf("/EX did not suggest /exit: %v", got)
46 }
47 if !isKnownSlashCommand("/Exit") {
48 t.Fatal("/Exit was not recognized as a built-in command")
49 }
50 if !slashCancelsTurn("/CLEAR") {
51 t.Fatal("/CLEAR did not retain /clear cancellation semantics")
52 }
53}
54
55func TestSlashSuggesterBuiltinsShadowExtensionsCaseInsensitively(t *testing.T) {
56 s := newSlashSuggester()
57 s.SetExtra([]slashCommand{{Name: "/EXIT", Desc: "extension exit"}})
58 matches := commandNames(s.matches("/exit"))
59 if len(matches) != 1 || matches[0] != "/exit" {
60 t.Fatalf("matches = %v, want only built-in /exit", matches)
61 }
62}
63
64func commandNames(cmds []slashCommand) []string {
65 out := make([]string, 0, len(cmds))
66 for _, c := range cmds {
67 if !c.Header {
68 out = append(out, c.Name)
69 }
70 }
71 return out
72}
73
74func contains(xs []string, want string) bool {
75 for _, x := range xs {
76 if x == want {
77 return true
78 }
79 }
80 return false
81}