...
Source file
src/go/ast/walk_test.go
Documentation: go/ast
1
2
3
4
5 package ast_test
6
7 import (
8 "go/ast"
9 "go/parser"
10 "go/token"
11 "testing"
12 )
13
14 func TestPreorderBreak(t *testing.T) {
15
16
17
18
19
20 src := "package p\ntype T struct {\n\tF int `json:\"f\"` // a field\n}\n"
21
22 fset := token.NewFileSet()
23 f, err := parser.ParseFile(fset, "", src, 0)
24 if err != nil {
25 panic(err)
26 }
27
28 for n := range ast.Preorder(f) {
29 if id, ok := n.(*ast.Ident); ok && id.Name == "F" {
30 break
31 }
32 }
33 }
34
View as plain text