github.com/april1989/origin-go-tools@v0.0.32/refactor/eg/testdata/A1.go (about) 1 // +build ignore 2 3 package A1 4 5 import ( 6 . "fmt" 7 myfmt "fmt" 8 "os" 9 "strings" 10 ) 11 12 func example(n int) { 13 x := "foo" + strings.Repeat("\t", n) 14 // Match, despite named import. 15 myfmt.Errorf("%s", x) 16 17 // Match, despite dot import. 18 Errorf("%s", x) 19 20 // Match: multiple matches in same function are possible. 21 myfmt.Errorf("%s", x) 22 23 // No match: wildcarded operand has the wrong type. 24 myfmt.Errorf("%s", 3) 25 26 // No match: function operand doesn't match. 27 myfmt.Printf("%s", x) 28 29 // No match again, dot import. 30 Printf("%s", x) 31 32 // Match. 33 myfmt.Fprint(os.Stderr, myfmt.Errorf("%s", x+"foo")) 34 35 // No match: though this literally matches the template, 36 // fmt doesn't resolve to a package here. 37 var fmt struct{ Errorf func(string, string) } 38 fmt.Errorf("%s", x) 39 40 // Recursive matching: 41 42 // Match: both matches are well-typed, so both succeed. 43 myfmt.Errorf("%s", myfmt.Errorf("%s", x+"foo").Error()) 44 45 // Outer match succeeds, inner doesn't: 3 has wrong type. 46 myfmt.Errorf("%s", myfmt.Errorf("%s", 3).Error()) 47 48 // Inner match succeeds, outer doesn't: the inner replacement 49 // has the wrong type (error not string). 50 myfmt.Errorf("%s", myfmt.Errorf("%s", x+"foo")) 51 }