github.com/XiaoMi/Gaea@v1.2.5/parser/yy_parser_test.go (about) 1 package parser 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/XiaoMi/Gaea/parser/ast" 8 "github.com/XiaoMi/Gaea/parser/tidb-types/parser_driver" 9 ) 10 11 func TestNodeToString(t *testing.T) { 12 tableName := "tb1" 13 d := &driver.ValueExpr{} 14 d.SetValue(tableName) 15 s, err := NodeToStringWithoutQuote(d) 16 if err != nil { 17 t.Fatal(err) 18 } 19 if s != tableName { 20 t.Errorf("table name not equal, expect: %s, actual: %s", tableName, s) 21 } 22 } 23 24 type NodePrintVisitor struct { 25 } 26 27 func (v *NodePrintVisitor) Enter(n ast.Node) (ast.Node, bool) { 28 fmt.Printf("enter: %T\n", n) 29 return n, false 30 } 31 32 func (v *NodePrintVisitor) Leave(n ast.Node) (ast.Node, bool) { 33 fmt.Printf("leave: %T\n", n) 34 return n, true 35 } 36 37 func TestASTNode(t *testing.T) { 38 sql := `desc xm_order` 39 n, err := ParseSQL(sql) 40 if err != nil { 41 t.Fatalf("parse sql error: %v", err) 42 } 43 v := &NodePrintVisitor{} 44 n.Accept(v) 45 }