| 1 | // Copyright 2026 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | package edge_testscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ast/edge_test`/ |
| 6 | |
| 7 | import ( |
| 8 | "go/astscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/" |
| 9 | "testingscip-go gomod github.com/golang/go/src go1.25.0 testing/" |
| 10 | |
| 11 | "golang.org/x/tools/go/ast/edgescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ast/edge`/" |
| 12 | ) |
| 13 | |
| 14 | func TestGetNilConcretescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ast/edge_test`/TestGetNilConcrete().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 15 | branchStmt := &astscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/.BranchStmtscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/BranchStmt#{Labelscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/BranchStmt#Label.: nil} |
| 16 | |
| 17 | out := edgescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ast/edge`/.BranchStmt_Labelscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ast/edge`/BranchStmt_Label..Getscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ast/edge`/Kind#Get().(branchStmt, -1) |
| 18 | if out.(*astscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/.Identscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/Ident#) != nil { |
| 19 | t.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().("out.(*ast.Ident) != nil") |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | func TestGetNilIfacescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ast/edge_test`/TestGetNilIface().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 24 | ifStmt := &astscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/.IfStmtscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/IfStmt#{Initscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/IfStmt#Init.: nil} |
| 25 | |
| 26 | out := edgescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ast/edge`/.IfStmt_Initscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ast/edge`/IfStmt_Init..Getscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ast/edge`/Kind#Get().(ifStmt, -1) // should not panic |
| 27 | if out != nil { |
| 28 | t.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().("out != nil") |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | func TestGetPanicsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ast/edge_test`/TestGetPanics().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 33 | t.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Run().("-1 with indexable field", func(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 34 | defer func() { _ = recover() }() |
| 35 | blockstmt := &astscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/.BlockStmtscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/BlockStmt#{Listscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/BlockStmt#List.: []astscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/.Stmtscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/Stmt#{&astscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/.IfStmtscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/IfStmt#{}}} |
| 36 | edgescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ast/edge`/.BlockStmt_Listscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ast/edge`/BlockStmt_List..Getscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ast/edge`/Kind#Get().(blockstmt, -1) // panic: slice index out of range |
| 37 | t.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().("Get did not panic") |
| 38 | }) |
| 39 | |
| 40 | t.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Run().("idx with non-indexable field", func(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 41 | defer func() { _ = recover() }() |
| 42 | id := &astscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/.IfStmtscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/IfStmt#{Condscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/IfStmt#Cond.: astscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/.NewIdentscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/NewIdent().("foo")} |
| 43 | edgescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ast/edge`/.IfStmt_Condscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ast/edge`/IfStmt_Cond..Getscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ast/edge`/Kind#Get().(id, 1) // panic: cannot index non-slice |
| 44 | t.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().("Get did not panic") |
| 45 | }) |
| 46 | } |