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

Function TestParse_EdgeCases

pkg/sql/parser/parser_final_coverage_test.go:25–95  ·  view source on GitHub ↗

TestParse_EdgeCases tests edge cases in the Parse function

(t *testing.T)

Source from the content-addressed store, hash-verified

23
24// TestParse_EdgeCases tests edge cases in the Parse function
25func 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")

Callers

nothing calls this directly

Calls 7

ParseMethod · 0.95
NewASTFunction · 0.92
ReleaseASTFunction · 0.92
tokenizeSQLFunction · 0.85
RunMethod · 0.80
NewParserFunction · 0.70
ErrorMethod · 0.45

Tested by

no test coverage detected