MCPcopy Create free account
hub / github.com/larksuite/cli / TestCmdExampleParseRefsRobustness

Function TestCmdExampleParseRefsRobustness

cmd/cmdexample_units_test.go:192–233  ·  view source on GitHub ↗

TestCmdExampleParseRefsRobustness covers the parser edge cases hardened after review: backslash continuation, underscore flags, $(...) substitution, glued separators, trailing punctuation, and the "..." placeholder.

(t *testing.T)

Source from the content-addressed store, hash-verified

190// review: backslash continuation, underscore flags, $(...) substitution, glued
191// separators, trailing punctuation, and the "..." placeholder.
192func TestCmdExampleParseRefsRobustness(t *testing.T) {
193 cases := []struct {
194 name, content, wantWords, wantFlags string
195 wantRefs int
196 }{
197 {"backslash continuation joins flags",
198 "lark-cli contact +search-user \\\n --query foo \\\n --as user",
199 "contact +search-user", "--query --as", 1},
200 {"underscore flag not truncated",
201 "lark-cli whiteboard +update --input_format mermaid",
202 "whiteboard +update", "--input_format", 1},
203 {"command-substitution flags ignored",
204 `lark-cli slides x create --data "$(jq -n --arg c '{}')" --as user`,
205 "slides x create", "--data --as", 1},
206 {"glued separator truncates",
207 "lark-cli auth login; echo done",
208 "auth login", "", 1},
209 {"trailing CJK punctuation stripped",
210 "用 lark-cli auth login。",
211 "auth login", "", 1},
212 {"ellipsis placeholder stays placeholder",
213 "lark-cli base +...",
214 "base", "", 1},
215 }
216 for _, tt := range cases {
217 t.Run(tt.name, func(t *testing.T) {
218 refs := parseRefs(tt.content)
219 if len(refs) != tt.wantRefs {
220 t.Fatalf("refs=%d want %d: %v", len(refs), tt.wantRefs, refWordsOf(refs))
221 }
222 if tt.wantRefs == 0 {
223 return
224 }
225 if got := strings.Join(refs[0].words, " "); got != tt.wantWords {
226 t.Errorf("words=%q want %q", got, tt.wantWords)
227 }
228 if got := strings.Join(refs[0].flags, " "); got != tt.wantFlags {
229 t.Errorf("flags=%q want %q", got, tt.wantFlags)
230 }
231 })
232 }
233}

Callers

nothing calls this directly

Calls 3

parseRefsFunction · 0.85
refWordsOfFunction · 0.85
RunMethod · 0.65

Tested by

no test coverage detected