github.com/april1989/origin-go-tools@v0.0.32/refactor/eg/testdata/A1.golden (about)

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