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
Something interesting
Tutorials
+11.2k Golang : Proper way to test CIDR membership of an IP 4 or 6 address example
+21.6k Golang : GORM create record or insert new record into database example
+11k How to test Facebook App on localhost ?
+6.1k PageSpeed : Clear or flush cache on web server
+4.7k Linux/MacOSX : How to symlink a file?
+15.6k Golang : How to convert(cast) IP address to string?
+9.7k Golang : List available AWS regions
+7.5k Golang : How to stop user from directly running an executable file?
+36.7k Golang : Display float in 2 decimal points and rounding up or down
+5.7k Unix/Linux/MacOSx : Get local IP address
+6k Golang : Convert Chinese UTF8 characters to Pin Yin
+16.5k Golang : Get IP addresses of a domain name