MCPcopy Create free account
hub / github.com/decomp/decomp / parseFixPrint

Function parseFixPrint

cmd/go-post/main_test.go:37–73  ·  view source on GitHub ↗
(t *testing.T, fn func(*ast.File) bool, desc, in string, mustBeGofmt bool)

Source from the content-addressed store, hash-verified

35func fnop(*ast.File) bool { return false }
36
37func 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
75func TestRewrite(t *testing.T) {
76 for _, tt := range testCases {

Callers 1

TestRewriteFunction · 0.85

Calls 2

gofmtFileFunction · 0.85
tdiffFunction · 0.85

Tested by

no test coverage detected