extractCommandBlock returns the substring of `md` covering one command's section, identified by its full path (e.g. "item create"). Used to scope assertions to a single command rather than the whole document.
(md, path string)
| 354 | // Used to scope assertions to a single command rather than the whole |
| 355 | // document. |
| 356 | func extractCommandBlock(md, path string) string { |
| 357 | heading := "## `padtest " + path + "`" |
| 358 | idx := strings.Index(md, heading) |
| 359 | if idx < 0 { |
| 360 | return "" |
| 361 | } |
| 362 | rest := md[idx+len(heading):] |
| 363 | // Block ends at the next `## ` heading at the same level. |
| 364 | next := regexp.MustCompile(`(?m)^## `) |
| 365 | if loc := next.FindStringIndex(rest); loc != nil { |
| 366 | return md[idx : idx+len(heading)+loc[0]] |
| 367 | } |
| 368 | return md[idx:] |
| 369 | } |
| 370 | |
| 371 | func head(s string, lines int) string { |
| 372 | parts := strings.SplitN(s, "\n", lines+1) |
no outgoing calls
no test coverage detected