MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / TestParseContext_ErrorHandling

Function TestParseContext_ErrorHandling

pkg/sql/parser/context_test.go:349–399  ·  view source on GitHub ↗

TestParseContext_ErrorHandling verifies proper error handling

(t *testing.T)

Source from the content-addressed store, hash-verified

347
348// TestParseContext_ErrorHandling verifies proper error handling
349func 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
402func TestParseContext_DeepNesting(t *testing.T) {

Callers

nothing calls this directly

Calls 8

ReleaseMethod · 0.95
GetTokenizerFunction · 0.92
PutTokenizerFunction · 0.92
RunMethod · 0.80
TokenizeMethod · 0.80
NewParserFunction · 0.70
ErrorMethod · 0.45

Tested by

no test coverage detected