parseLabeledOutput does the inverse of labeledOutput - it takes a formatted output string and turns it back into a slice of labeledContent.
(output string)
| 3140 | // parseLabeledOutput does the inverse of labeledOutput - it takes a formatted |
| 3141 | // output string and turns it back into a slice of labeledContent. |
| 3142 | func parseLabeledOutput(output string) []labeledContent { |
| 3143 | labelPattern := regexp.MustCompile(`^\t([^\t]*): *\t(.*)$`) |
| 3144 | contentPattern := regexp.MustCompile(`^\t *\t(.*)$`) |
| 3145 | var contents []labeledContent |
| 3146 | lines := strings.Split(output, "\n") |
| 3147 | i := -1 |
| 3148 | for _, line := range lines { |
| 3149 | if line == "" { |
| 3150 | // skip blank lines |
| 3151 | continue |
| 3152 | } |
| 3153 | matches := labelPattern.FindStringSubmatch(line) |
| 3154 | if len(matches) == 3 { |
| 3155 | // a label |
| 3156 | contents = append(contents, labeledContent{ |
| 3157 | label: matches[1], |
| 3158 | content: matches[2] + "\n", |
| 3159 | }) |
| 3160 | i++ |
| 3161 | continue |
| 3162 | } |
| 3163 | matches = contentPattern.FindStringSubmatch(line) |
| 3164 | if len(matches) == 2 { |
| 3165 | // just content |
| 3166 | if i >= 0 { |
| 3167 | contents[i].content += matches[1] + "\n" |
| 3168 | continue |
| 3169 | } |
| 3170 | } |
| 3171 | // Couldn't parse output |
| 3172 | return nil |
| 3173 | } |
| 3174 | return contents |
| 3175 | } |
| 3176 | |
| 3177 | type captureTestingT struct { |
| 3178 | msg string |
no outgoing calls
no test coverage detected