(t *testing.T)
| 143 | } |
| 144 | |
| 145 | func TestCmdExampleCheck(t *testing.T) { |
| 146 | c := testCatalog() |
| 147 | tests := []struct { |
| 148 | name string |
| 149 | r ref |
| 150 | wantKind string // "" = no finding |
| 151 | wantPath string |
| 152 | }{ |
| 153 | {"valid shortcut", ref{words: []string{"contact", "+search-user"}, flags: []string{"--query"}}, "", ""}, |
| 154 | {"valid leaf positional", ref{words: []string{"api", "GET", "/x"}}, "", ""}, |
| 155 | {"unknown top command", ref{words: []string{"nope"}}, unknownCommand, "nope"}, |
| 156 | {"group leftover = unknown subcommand", |
| 157 | ref{words: []string{"mail", "user_mailbox.messages", "batch_modify_message"}}, |
| 158 | unknownCommand, "mail user_mailbox.messages batch_modify_message"}, |
| 159 | {"unknown flag", ref{words: []string{"contact", "+search-user"}, flags: []string{"--nope"}}, unknownFlag, "contact +search-user"}, |
| 160 | {"universal flag ok", ref{words: []string{"contact", "+search-user"}, flags: []string{"--help"}}, "", ""}, |
| 161 | } |
| 162 | for _, tt := range tests { |
| 163 | t.Run(tt.name, func(t *testing.T) { |
| 164 | fs := checkRefs(c, []ref{tt.r}) |
| 165 | if tt.wantKind == "" { |
| 166 | if len(fs) != 0 { |
| 167 | t.Fatalf("expected no finding, got %+v", fs) |
| 168 | } |
| 169 | return |
| 170 | } |
| 171 | if len(fs) != 1 { |
| 172 | t.Fatalf("expected 1 finding, got %d: %+v", len(fs), fs) |
| 173 | } |
| 174 | if fs[0].kind != tt.wantKind || fs[0].path != tt.wantPath { |
| 175 | t.Errorf("got kind=%s path=%q, want kind=%s path=%q", fs[0].kind, fs[0].path, tt.wantKind, tt.wantPath) |
| 176 | } |
| 177 | }) |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | func TestCmdExampleCheckSuggestsNearest(t *testing.T) { |
| 182 | c := testCatalog() |
nothing calls this directly
no test coverage detected