TestParse_EdgeCases tests edge cases in the Parse function
(t *testing.T)
| 23 | |
| 24 | // TestParse_EdgeCases tests edge cases in the Parse function |
| 25 | func TestParse_EdgeCases(t *testing.T) { |
| 26 | tests := []struct { |
| 27 | name string |
| 28 | sql string |
| 29 | shouldErr bool |
| 30 | }{ |
| 31 | { |
| 32 | name: "Empty token list", |
| 33 | sql: "", |
| 34 | shouldErr: true, |
| 35 | }, |
| 36 | { |
| 37 | name: "Single semicolon", |
| 38 | sql: ";", |
| 39 | shouldErr: false, // Should parse as empty statement list |
| 40 | }, |
| 41 | { |
| 42 | name: "Multiple statements with semicolons", |
| 43 | sql: "SELECT * FROM users; SELECT * FROM products;", |
| 44 | shouldErr: false, |
| 45 | }, |
| 46 | { |
| 47 | name: "Statement with trailing semicolon", |
| 48 | sql: "SELECT * FROM users;", |
| 49 | shouldErr: false, |
| 50 | }, |
| 51 | { |
| 52 | name: "Multiple semicolons", |
| 53 | sql: "SELECT * FROM users;;", |
| 54 | shouldErr: false, |
| 55 | }, |
| 56 | } |
| 57 | |
| 58 | for _, tt := range tests { |
| 59 | t.Run(tt.name, func(t *testing.T) { |
| 60 | if tt.sql == "" { |
| 61 | // Empty SQL - test with empty token list |
| 62 | p := NewParser() |
| 63 | astObj := ast.NewAST() |
| 64 | defer ast.ReleaseAST(astObj) |
| 65 | |
| 66 | _, err := p.Parse([]token.Token{}) |
| 67 | if tt.shouldErr && err == nil { |
| 68 | t.Error("Expected error for empty token list, got nil") |
| 69 | } |
| 70 | return |
| 71 | } |
| 72 | |
| 73 | tokens := tokenizeSQL(t, tt.sql) |
| 74 | p := NewParser() |
| 75 | astObj := ast.NewAST() |
| 76 | defer ast.ReleaseAST(astObj) |
| 77 | |
| 78 | result, err := p.Parse(tokens) |
| 79 | |
| 80 | if tt.shouldErr { |
| 81 | if err == nil { |
| 82 | t.Error("Expected error, got nil") |
nothing calls this directly
no test coverage detected