| 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 | if len(completion) != len(specs) { |
| 27 | t.Fatalf("completion items = %d, specs = %d", len(completion), len(specs)) |
| 28 | } |
| 29 | help := builtinSlashHelpItems() |
| 30 | helpNames := map[string]bool{} |
| 31 | for _, item := range help { |
| 32 | helpNames[item.label] = true |
| 33 | } |
| 34 | for i, spec := range specs { |
| 35 | item := completion[i] |
| 36 | if item.label != spec.name || item.insert != spec.insert || item.hint != spec.hint || item.descend != spec.descend { |
| 37 | t.Fatalf("completion item for %q drifted: %+v", spec.name, item) |
| 38 | } |
| 39 | if helpNames[spec.name] != spec.showInHelp { |
| 40 | t.Fatalf("help visibility for %q = %v, want %v", spec.name, helpNames[spec.name], spec.showInHelp) |
| 41 | } |
| 42 | } |
| 43 | } |
| 44 |