parseLabeledOutput does the inverse of labeledOutput - it takes a formatted output string and turns it back into a slice of labeledContent.
(output string)
| 2926 | // parseLabeledOutput does the inverse of labeledOutput - it takes a formatted |
| 2927 | // output string and turns it back into a slice of labeledContent. |
| 2928 | func parseLabeledOutput(output string) []labeledContent { |
| 2929 | labelPattern := regexp.MustCompile(`^\t([^\t]*): *\t(.*)$`) |
| 2930 | contentPattern := regexp.MustCompile(`^\t *\t(.*)$`) |
| 2931 | var contents []labeledContent |
| 2932 | lines := strings.Split(output, "\n") |
| 2933 | i := -1 |
| 2934 | for _, line := range lines { |
| 2935 | if line == "" { |
| 2936 | // skip blank lines |
| 2937 | continue |
| 2938 | } |
| 2939 | matches := labelPattern.FindStringSubmatch(line) |
| 2940 | if len(matches) == 3 { |
| 2941 | // a label |
| 2942 | contents = append(contents, labeledContent{ |
| 2943 | label: matches[1], |
| 2944 | content: matches[2] + "\n", |
| 2945 | }) |
| 2946 | i++ |
| 2947 | continue |
| 2948 | } |
| 2949 | matches = contentPattern.FindStringSubmatch(line) |
| 2950 | if len(matches) == 2 { |
| 2951 | // just content |
| 2952 | if i >= 0 { |
| 2953 | contents[i].content += matches[1] + "\n" |
| 2954 | continue |
| 2955 | } |
| 2956 | } |
| 2957 | // Couldn't parse output |
| 2958 | return nil |
| 2959 | } |
| 2960 | return contents |
| 2961 | } |
| 2962 | |
| 2963 | type captureTestingT struct { |
| 2964 | msg string |
no test coverage detected
searching dependent graphs…