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
+5.7k Golang : Struct field tags and what is their purpose?
+9.9k Golang : Turn string or text file into slice example
+11.6k Golang : Fuzzy string search or approximate string matching example
+25.5k Golang : Generate MD5 checksum of a file
+15.6k Chrome : ERR_INSECURE_RESPONSE and allow Chrome browser to load insecure content
+5.6k PHP : Convert string to timestamp or datestamp before storing to database(MariaDB/MySQL)
+8.8k Golang : Random integer with rand.Seed() within a given range
+12.7k Golang : Send data to /dev/null a.k.a blackhole with ioutil.Discard
+11k Golang : Replace a parameter's value inside a configuration file example
+6.7k Golang : Output or print out JSON stream/encoded data
+9.7k Golang : List available AWS regions
+6.9k Golang : Normalize email to prevent multiple signups example