parseLabeledOutput does the inverse of labeledOutput - it takes a formatted output string and turns it back into a slice of labeledContent.
(output string)
| 3615 | // parseLabeledOutput does the inverse of labeledOutput - it takes a formatted |
| 3616 | // output string and turns it back into a slice of labeledContent. |
| 3617 | func parseLabeledOutput(output string) []labeledContent { |
| 3618 | labelPattern := regexp.MustCompile(`^\t([^\t]*): *\t(.*)$`) |
| 3619 | contentPattern := regexp.MustCompile(`^\t *\t(.*)$`) |
| 3620 | var contents []labeledContent |
| 3621 | lines := strings.Split(output, "\n") |
| 3622 | i := -1 |
| 3623 | for _, line := range lines { |
| 3624 | if line == "" { |
| 3625 | // skip blank lines |
| 3626 | continue |
| 3627 | } |
| 3628 | matches := labelPattern.FindStringSubmatch(line) |
| 3629 | if len(matches) == 3 { |
| 3630 | // a label |
| 3631 | contents = append(contents, labeledContent{ |
| 3632 | label: matches[1], |
| 3633 | content: matches[2] + "\n", |
| 3634 | }) |
| 3635 | i++ |
| 3636 | continue |
| 3637 | } |
| 3638 | matches = contentPattern.FindStringSubmatch(line) |
| 3639 | if len(matches) == 2 { |
| 3640 | // just content |
| 3641 | if i >= 0 { |
| 3642 | contents[i].content += matches[1] + "\n" |
| 3643 | continue |
| 3644 | } |
| 3645 | } |
| 3646 | // Couldn't parse output |
| 3647 | return nil |
| 3648 | } |
| 3649 | return contents |
| 3650 | } |
| 3651 | |
| 3652 | type captureTestingT struct { |
| 3653 | failed bool |
no outgoing calls
no test coverage detected