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

Function TestVisitor

pkg/sql/ast/visitor_test.go:47–82  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

45}
46
47func TestVisitor(t *testing.T) {
48 // Create a simple AST
49 ast := &AST{
50 Statements: []Statement{
51 &SelectStatement{
52 Columns: []Expression{
53 &Identifier{Name: "id"},
54 &Identifier{Name: "name"},
55 },
56 TableName: "users",
57 Where: &BinaryExpression{
58 Left: &Identifier{Name: "id"},
59 Operator: "=",
60 Right: &Identifier{Name: "1"},
61 },
62 },
63 },
64 }
65
66 counter := &nodeCounter{}
67 err := Walk(counter, ast)
68 if err != nil {
69 t.Errorf("unexpected error: %v", err)
70 }
71
72 // Count expected nodes:
73 // 1. AST
74 // 2. SelectStatement
75 // 3-4. Two column Identifiers
76 // 5. BinaryExpression
77 // 6-7. Left and right Identifiers in BinaryExpression
78 expectedCount := 7
79 if counter.count != expectedCount {
80 t.Errorf("expected %d nodes, got %d", expectedCount, counter.count)
81 }
82}
83
84func TestInspector(t *testing.T) {
85 // Create a simple AST

Callers

nothing calls this directly

Calls 2

WalkFunction · 0.85
ErrorfMethod · 0.65

Tested by

no test coverage detected