testSQLFile tests parsing a single SQL file
(t *testing.T, file SQLTestFile)
| 215 | |
| 216 | // testSQLFile tests parsing a single SQL file |
| 217 | func testSQLFile(t *testing.T, file SQLTestFile) TestResult { |
| 218 | result := TestResult{ |
| 219 | File: file.Name, |
| 220 | Dialect: file.Dialect, |
| 221 | Success: false, |
| 222 | } |
| 223 | |
| 224 | // Extract SQL statement (remove comments) |
| 225 | sqlStatement := extractSQLStatement(file.Content) |
| 226 | if strings.TrimSpace(sqlStatement) == "" { |
| 227 | result.Error = fmt.Errorf("empty SQL statement after removing comments") |
| 228 | return result |
| 229 | } |
| 230 | |
| 231 | // Get tokenizer from pool |
| 232 | tkz := tokenizer.GetTokenizer() |
| 233 | defer tokenizer.PutTokenizer(tkz) |
| 234 | |
| 235 | // Tokenize |
| 236 | startTime := time.Now() |
| 237 | tokens, err := tkz.Tokenize([]byte(sqlStatement)) |
| 238 | if err != nil { |
| 239 | result.Error = fmt.Errorf("tokenization failed: %w", err) |
| 240 | return result |
| 241 | } |
| 242 | |
| 243 | // Parse directly from model tokens |
| 244 | p := parser.NewParser() |
| 245 | defer p.Release() |
| 246 | |
| 247 | ast, err := p.ParseFromModelTokens(tokens) |
| 248 | result.ParseTime = time.Since(startTime) |
| 249 | |
| 250 | if err != nil { |
| 251 | result.Error = fmt.Errorf("parsing failed: %w", err) |
| 252 | return result |
| 253 | } |
| 254 | |
| 255 | if ast == nil { |
| 256 | result.Error = fmt.Errorf("parser returned nil AST without error") |
| 257 | return result |
| 258 | } |
| 259 | |
| 260 | if len(ast.Statements) == 0 { |
| 261 | result.Error = fmt.Errorf("parser returned empty statement list") |
| 262 | return result |
| 263 | } |
| 264 | |
| 265 | result.Success = true |
| 266 | return result |
| 267 | } |
| 268 | |
| 269 | // TestIntegration_PostgreSQL_Simple tests simple PostgreSQL queries |
| 270 | func TestIntegration_PostgreSQL_Simple(t *testing.T) { |
no test coverage detected