(t *testing.T, fn func(*ast.File) bool, desc, in string, mustBeGofmt bool)
| 35 | func fnop(*ast.File) bool { return false } |
| 36 | |
| 37 | func parseFixPrint(t *testing.T, fn func(*ast.File) bool, desc, in string, mustBeGofmt bool) (out string, fixed, ok bool) { |
| 38 | file, err := parser.ParseFile(fset, desc, in, parserMode) |
| 39 | if err != nil { |
| 40 | t.Errorf("%s: parsing: %v", desc, err) |
| 41 | return |
| 42 | } |
| 43 | |
| 44 | outb, err := gofmtFile(file) |
| 45 | if err != nil { |
| 46 | t.Errorf("%s: printing: %v", desc, err) |
| 47 | return |
| 48 | } |
| 49 | if s := string(outb); in != s && mustBeGofmt { |
| 50 | t.Errorf("%s: not gofmt-formatted.\n--- %s\n%s\n--- %s | gofmt\n%s", |
| 51 | desc, desc, in, desc, s) |
| 52 | tdiff(t, in, s) |
| 53 | return |
| 54 | } |
| 55 | |
| 56 | if fn == nil { |
| 57 | for _, fix := range fixes { |
| 58 | if fix.f(file) { |
| 59 | fixed = true |
| 60 | } |
| 61 | } |
| 62 | } else { |
| 63 | fixed = fn(file) |
| 64 | } |
| 65 | |
| 66 | outb, err = gofmtFile(file) |
| 67 | if err != nil { |
| 68 | t.Errorf("%s: printing: %v", desc, err) |
| 69 | return |
| 70 | } |
| 71 | |
| 72 | return string(outb), fixed, true |
| 73 | } |
| 74 | |
| 75 | func TestRewrite(t *testing.T) { |
| 76 | for _, tt := range testCases { |
no test coverage detected