TestParseContext_ErrorHandling verifies proper error handling
(t *testing.T)
| 347 | |
| 348 | // TestParseContext_ErrorHandling verifies proper error handling |
| 349 | func TestParseContext_ErrorHandling(t *testing.T) { |
| 350 | tests := []struct { |
| 351 | name string |
| 352 | sql string |
| 353 | shouldError bool |
| 354 | }{ |
| 355 | { |
| 356 | name: "incomplete select", |
| 357 | sql: "SELECT FROM users", |
| 358 | shouldError: true, |
| 359 | }, |
| 360 | { |
| 361 | name: "missing table name", |
| 362 | sql: "SELECT * FROM", |
| 363 | shouldError: true, |
| 364 | }, |
| 365 | } |
| 366 | |
| 367 | for _, tt := range tests { |
| 368 | t.Run(tt.name, func(t *testing.T) { |
| 369 | ctx := context.Background() |
| 370 | |
| 371 | // Try to tokenize - some errors may occur here |
| 372 | tkz := tokenizer.GetTokenizer() |
| 373 | defer tokenizer.PutTokenizer(tkz) |
| 374 | |
| 375 | tokens, tokErr := tkz.Tokenize([]byte(tt.sql)) |
| 376 | if tokErr != nil { |
| 377 | // Expected for some invalid SQL |
| 378 | return |
| 379 | } |
| 380 | |
| 381 | p := NewParser() |
| 382 | defer p.Release() |
| 383 | |
| 384 | ast, err := p.ParseContextFromModelTokens(ctx, tokens) |
| 385 | |
| 386 | if tt.shouldError && err == nil { |
| 387 | t.Error("Expected error but got none") |
| 388 | } |
| 389 | |
| 390 | if err != nil && err == context.Canceled { |
| 391 | t.Error("Should not return context.Canceled for SQL errors") |
| 392 | } |
| 393 | |
| 394 | if tt.shouldError && ast != nil { |
| 395 | t.Error("Expected nil AST on error") |
| 396 | } |
| 397 | }) |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | // TestParseContext_DeepNesting verifies context checks with deeply nested expressions |
| 402 | func TestParseContext_DeepNesting(t *testing.T) { |
nothing calls this directly
no test coverage detected