Skip to content

Commit

Permalink
add test for the cases
Browse files Browse the repository at this point in the history
  • Loading branch information
kyoh86 committed Jul 30, 2021
1 parent cb4d387 commit 0543cb4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
10 changes: 10 additions & 0 deletions exportloopref_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,13 @@ func TestDepPointer(t *testing.T) {
testdata := analysistest.TestData()
analysistest.Run(t, testdata, exportloopref.Analyzer, "deeppointer")
}

func TestBreak(t *testing.T) {
testdata := analysistest.TestData()
analysistest.Run(t, testdata, exportloopref.Analyzer, "break")
}

func TestReturn(t *testing.T) {
testdata := analysistest.TestData()
analysistest.Run(t, testdata, exportloopref.Analyzer, "return")
}
10 changes: 10 additions & 0 deletions testdata/src/break/break.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package main

func main() {
var result *int
haystack := []int{1, 2}
for _, hay := range haystack {
result = &hay // Broken just below, the loop does NOT set unexpected value to result
break
}
}
15 changes: 15 additions & 0 deletions testdata/src/return/return.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package main

func main() {
result := sub()
println(*result)
}

func sub() (result *int) {
haystack := []int{1, 2}
for _, hay := range haystack {
result = &hay // Returns just below, the loop does NOT set unexpected value to result
return
}
return
}

0 comments on commit 0543cb4

Please sign in to comment.