(t *testing.T, pattern, actual string)
| 92 | } |
| 93 | |
| 94 | func matchErrors(t *testing.T, pattern, actual string) bool { |
| 95 | patternLines := strings.Split(pattern, "\n") |
| 96 | actualLines := strings.Split(actual, "\n") |
| 97 | if len(patternLines) != len(actualLines) { |
| 98 | return false |
| 99 | } |
| 100 | for i, patternLine := range patternLines { |
| 101 | indices := regexp.MustCompile(`\{\{.*?\}\}`).FindAllStringIndex(patternLine, -1) |
| 102 | patternParts := []string{"^"} |
| 103 | lastStop := 0 |
| 104 | for _, startstop := range indices { |
| 105 | start := startstop[0] |
| 106 | stop := startstop[1] |
| 107 | patternParts = append(patternParts, |
| 108 | regexp.QuoteMeta(patternLine[lastStop:start]), |
| 109 | patternLine[start+2:stop-2]) |
| 110 | lastStop = stop |
| 111 | } |
| 112 | patternParts = append(patternParts, regexp.QuoteMeta(patternLine[lastStop:]), "$") |
| 113 | pattern := strings.Join(patternParts, "") |
| 114 | re, err := regexp.Compile(pattern) |
| 115 | if err != nil { |
| 116 | t.Fatalf("could not compile regexp for %#v: %v", patternLine, err) |
| 117 | } |
| 118 | if !re.MatchString(actualLines[i]) { |
| 119 | return false |
| 120 | } |
| 121 | } |
| 122 | return true |
| 123 | } |
| 124 | |
| 125 | // Indent the given text with a given indentation string. |
| 126 | func indentText(text, indent string) string { |
no test coverage detected