| 82 | } |
| 83 | |
| 84 | func TestInspector(t *testing.T) { |
| 85 | // Create a simple AST |
| 86 | ast := &AST{ |
| 87 | Statements: []Statement{ |
| 88 | &SelectStatement{ |
| 89 | Columns: []Expression{ |
| 90 | &Identifier{Name: "id"}, |
| 91 | }, |
| 92 | TableName: "users", |
| 93 | }, |
| 94 | }, |
| 95 | } |
| 96 | |
| 97 | var identifiers []*Identifier |
| 98 | Inspect(ast, func(n Node) bool { |
| 99 | if id, ok := n.(*Identifier); ok { |
| 100 | identifiers = append(identifiers, id) |
| 101 | } |
| 102 | return true |
| 103 | }) |
| 104 | |
| 105 | if len(identifiers) != 1 { |
| 106 | t.Errorf("expected 1 identifier, got %d", len(identifiers)) |
| 107 | } |
| 108 | if identifiers[0].Name != "id" { |
| 109 | t.Errorf("expected identifier name 'id', got '%s'", identifiers[0].Name) |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | func TestVisitFunc(t *testing.T) { |
| 114 | ast := &AST{ |