MCPcopy Index your code
hub / github.com/tinygo-org/tinygo / matchErrors

Function matchErrors

errors_test.go:94–123  ·  view source on GitHub ↗
(t *testing.T, pattern, actual string)

Source from the content-addressed store, hash-verified

92}
93
94func 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.
126func indentText(text, indent string) string {

Callers 1

testErrorMessagesFunction · 0.85

Calls 2

FatalfMethod · 0.65
MatchStringMethod · 0.65

Tested by

no test coverage detected