MCPcopy Create free account
hub / github.com/stretchr/testify / parseLabeledOutput

Function parseLabeledOutput

assert/assertions_test.go:3142–3175  ·  view source on GitHub ↗

parseLabeledOutput does the inverse of labeledOutput - it takes a formatted output string and turns it back into a slice of labeledContent.

(output string)

Source from the content-addressed store, hash-verified

3140// parseLabeledOutput does the inverse of labeledOutput - it takes a formatted
3141// output string and turns it back into a slice of labeledContent.
3142func 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
3177type captureTestingT struct {
3178 msg string

Callers 1

checkResultAndErrMsgMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected