返回 DeepSeek-Reasonix
slash_registry_test.go
根目录 / internal / cli / slash_registry_test.go
1 package cli
2
3 import "testing"
4
5 func TestBuiltinSlashRegistryHasUniqueNamesAndAliases(t *testing.T) {
6 seen := map[string]string{}
7 for _, spec := range builtinSlashSpecs() {
8 if spec.name == "" || spec.name[0] != '/' {
9 t.Fatalf("invalid built-in slash name %q", spec.name)
10 }
11 for _, name := range append([]string{spec.name}, spec.aliases...) {
12 if owner, exists := seen[name]; exists {
13 t.Fatalf("slash name %q belongs to both %q and %q", name, owner, spec.name)
14 }
15 seen[name] = spec.name
16 if got := canonicalBuiltinSlashCommand(name); got != spec.name {
17 t.Fatalf("canonical command for %q = %q, want %q", name, got, spec.name)
18 }
19 }
20 }
21 }
22
23 func TestBuiltinSlashCompletionAndHelpComeFromRegistry(t *testing.T) {
24 specs := builtinSlashSpecs()
25 completion := builtinSlashItems()
26 completionByName := make(map[string]compItem, len(completion))
27 for _, item := range completion {
28 completionByName[item.label] = item
29 }
30 visible := 0
31 for _, spec := range specs {
32 if !spec.hidden {
33 visible++
34 }
35 }
36 if len(completion) != visible {
37 t.Fatalf("completion items = %d, visible specs = %d", len(completion), visible)
38 }
39 help := builtinSlashHelpItems()
40 helpNames := map[string]bool{}
41 for _, item := range help {
42 helpNames[item.label] = true
43 }
44 for _, spec := range specs {
45 item, discoverable := completionByName[spec.name]
46 if discoverable == spec.hidden {
47 t.Fatalf("completion visibility for %q = %v, hidden = %v", spec.name, discoverable, spec.hidden)
48 }
49 if helpNames[spec.name] != spec.showInHelp {
50 t.Fatalf("help visibility for %q = %v, want %v", spec.name, helpNames[spec.name], spec.showInHelp)
51 }
52 if spec.hidden {
53 continue
54 }
55 if item.label != spec.name || item.insert != spec.insert || item.hint != spec.hint || item.descend != spec.descend {
56 t.Fatalf("completion item for %q drifted: %+v", spec.name, item)
57 }
58 }
59 }
60
60 lines GO