Golang go/ast.Expr type example

package go/ast

All expression nodes implement the Expr interface.

Golang go/ast.Expr type usage example

 func createItStatementForTestFunc(testFunc *ast.FuncDecl) *ast.ExprStmt {
  blockStatement := &ast.BlockStmt{List: testFunc.Body.List}
  fieldList := &ast.FieldList{}
  funcType := &ast.FuncType{Params: fieldList}
  funcLit := &ast.FuncLit{Type: funcType, Body: blockStatement}
  testName := rewriteTestName(testFunc.Name.Name)
  basicLit := &ast.BasicLit{Kind: 9, Value: fmt.Sprintf("\"%s\"", testName)}
  itBlockIdent := &ast.Ident{Name: "It"}
  callExpr := &ast.CallExpr{Fun: itBlockIdent, Args: []ast.Expr{basicLit, funcLit}} // <-- here
  return &ast.ExprStmt{X: callExpr}
 }

References :

http://golang.org/pkg/go/ast/#Expr

https://github.com/onsi/ginkgo/blob/master/ginkgo/convert/ginkgoastnodes.go

Advertisement