TestParseContext_BasicSuccess verifies that ParseContext works for valid SQL
(t *testing.T)
| 47 | |
| 48 | // TestParseContext_BasicSuccess verifies that ParseContext works for valid SQL |
| 49 | func TestParseContext_BasicSuccess(t *testing.T) { |
| 50 | tests := []struct { |
| 51 | name string |
| 52 | sql string |
| 53 | }{ |
| 54 | { |
| 55 | name: "simple select", |
| 56 | sql: "SELECT * FROM users", |
| 57 | }, |
| 58 | { |
| 59 | name: "select with where", |
| 60 | sql: "SELECT name, email FROM users WHERE active = true", |
| 61 | }, |
| 62 | { |
| 63 | name: "insert statement", |
| 64 | sql: "INSERT INTO users (name) VALUES ('John')", |
| 65 | }, |
| 66 | { |
| 67 | name: "update statement", |
| 68 | sql: "UPDATE users SET name = 'Jane' WHERE id = 1", |
| 69 | }, |
| 70 | { |
| 71 | name: "delete statement", |
| 72 | sql: "DELETE FROM users WHERE id = 1", |
| 73 | }, |
| 74 | } |
| 75 | |
| 76 | for _, tt := range tests { |
| 77 | t.Run(tt.name, func(t *testing.T) { |
| 78 | ctx := context.Background() |
| 79 | tokens := tokenizeSQL(t, tt.sql) |
| 80 | |
| 81 | p := NewParser() |
| 82 | defer p.Release() |
| 83 | |
| 84 | ast, err := p.ParseContext(ctx, tokens) |
| 85 | if err != nil { |
| 86 | t.Fatalf("ParseContext() error = %v", err) |
| 87 | } |
| 88 | |
| 89 | if ast == nil { |
| 90 | t.Error("Expected AST but got nil") |
| 91 | return |
| 92 | } |
| 93 | |
| 94 | if len(ast.Statements) == 0 { |
| 95 | t.Error("Expected statements in AST but got none") |
| 96 | } |
| 97 | }) |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | // TestParseContext_CancelledContext verifies that cancellation is detected |
| 102 | func TestParseContext_CancelledContext(t *testing.T) { |
nothing calls this directly
no test coverage detected