1
0
mirror of https://github.com/golang/go synced 2024-11-06 00:26:11 -07:00
go/refactor/eg/testdata/A1.golden
Alan Donovan 4744be3abc refactor/eg: use format.Node not printer.Fprint for canonical output
Fixes golang/go#10038

Change-Id: If3243f0c68fc0442dcc1e2dd71cbdc629beff70c
Reviewed-on: https://go-review.googlesource.com/6481
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-03-02 19:38:58 +00:00

53 lines
1.1 KiB
Plaintext

// +build ignore
package A1
import (
"errors"
. "fmt"
myfmt "fmt"
"os"
"strings"
)
func example(n int) {
x := "foo" + strings.Repeat("\t", n)
// Match, despite named import.
errors.New(x)
// Match, despite dot import.
errors.New(x)
// Match: multiple matches in same function are possible.
errors.New(x)
// No match: wildcarded operand has the wrong type.
myfmt.Errorf("%s", 3)
// No match: function operand doesn't match.
myfmt.Printf("%s", x)
// No match again, dot import.
Printf("%s", x)
// Match.
myfmt.Fprint(os.Stderr, errors.New(x+"foo"))
// No match: though this literally matches the template,
// fmt doesn't resolve to a package here.
var fmt struct{ Errorf func(string, string) }
fmt.Errorf("%s", x)
// Recursive matching:
// Match: both matches are well-typed, so both succeed.
errors.New(errors.New(x + "foo").Error())
// Outer match succeeds, inner doesn't: 3 has wrong type.
errors.New(myfmt.Errorf("%s", 3).Error())
// Inner match succeeds, outer doesn't: the inner replacement
// has the wrong type (error not string).
myfmt.Errorf("%s", errors.New(x+"foo"))
}