MCPcopy Create free account
hub / github.com/commander-cli/commander / validateExpectedLines

Function validateExpectedLines

pkg/runtime/validator.go:143–172  ·  view source on GitHub ↗
(got string, expected ExpectedOut)

Source from the content-addressed store, hash-verified

141}
142
143func validateExpectedLines(got string, expected ExpectedOut) matcher.MatcherResult {
144 m := matcher.NewMatcher(matcher.Equal)
145 actualLines := strings.Split(got, getLineBreak())
146 result := matcher.MatcherResult{Success: true}
147
148 for key, expectedLine := range expected.Lines {
149 // line number 0 or below 0
150 if key <= 0 {
151 panic(fmt.Sprintf("Invalid line number given %d", key))
152 }
153
154 // line number exceeds result set
155 if key > len(actualLines) {
156 return matcher.MatcherResult{
157 Success: false,
158 Diff: fmt.Sprintf(
159 "Line number %d does not exists in result: \n\n%s",
160 key,
161 strings.Join(actualLines, "\n"),
162 ),
163 }
164 }
165
166 if result = m.Match(actualLines[key-1], expectedLine); !result.Success {
167 return result
168 }
169 }
170
171 return result
172}
173
174func getLineBreak() string {
175 return "\n"

Callers 1

validateExpectedOutFunction · 0.85

Calls 3

MatchMethod · 0.95
NewMatcherFunction · 0.92
getLineBreakFunction · 0.85

Tested by

no test coverage detected