(t *testing.T, tc SplitTestCase, opts SplitTestOptions)
| 194 | } |
| 195 | |
| 196 | func runSingleTest(t *testing.T, tc SplitTestCase, opts SplitTestOptions) { |
| 197 | t.Helper() |
| 198 | |
| 199 | var lexerResult, parserResult []Statement |
| 200 | var lexerErr, parserErr error |
| 201 | |
| 202 | // Run lexer implementation if provided |
| 203 | if opts.LexerSplitFunc != nil { |
| 204 | lexerResult, lexerErr = opts.LexerSplitFunc(tc.Input) |
| 205 | } |
| 206 | |
| 207 | // Run parser implementation if provided |
| 208 | if opts.ParserSplitFunc != nil { |
| 209 | parserResult, parserErr = opts.ParserSplitFunc(tc.Input) |
| 210 | } |
| 211 | |
| 212 | // MANDATORY: If both implementations succeed, results must be identical |
| 213 | if opts.LexerSplitFunc != nil && opts.ParserSplitFunc != nil { |
| 214 | if lexerErr == nil && parserErr == nil { |
| 215 | require.Equal(t, len(lexerResult), len(parserResult), |
| 216 | "lexer and parser produced different number of statements") |
| 217 | for i := range lexerResult { |
| 218 | require.Equal(t, lexerResult[i], parserResult[i], |
| 219 | "lexer and parser produced different result for statement %d", i) |
| 220 | } |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | // Run the main split function |
| 225 | result, err := opts.SplitFunc(tc.Input) |
| 226 | |
| 227 | // Check error expectation |
| 228 | if tc.Error != "" { |
| 229 | require.Error(t, err) |
| 230 | require.Contains(t, err.Error(), tc.Error) |
| 231 | return |
| 232 | } |
| 233 | |
| 234 | require.NoError(t, err) |
| 235 | assertStatementsEqual(t, tc.Result, result) |
| 236 | } |
no test coverage detected