Debian Codegraph @

go/analysis/passes/inline/testdata/src/issue77610.txtar

raw
1 This test verifies that unused imports conservatively added by the inliner are
2 removed in FormatSourceRemoveImports.
3
4 -- go.mod --
5 module example.com
6
7 -- a/a.go --
8 package a
9
10 import "io"
11
12 //go:fix inline
13 func OldHello(w io.Writer) error { // want OldHello:"goFixInline a.OldHello"
14 return NewHello(w)
15 }
16
17 func NewHello(w io.Writer) error {
18 _, err := w.Write([]byte("Hello, World!"))
19 return err
20 }
21
22 -- b/b.go --
23 package b
24
25 import (
26 "strings"
27 "example.com/a"
28 )
29
30 func _() {
31 var buf strings.Builder
32 // The inliner wants to add an import for "io"; make sure post-processing of the fix removes it.
33 a.OldHello(&buf) // want "Call of a.OldHello should be inlined"
34 }
35
36 -- b/b.go.golden --
37 package b
38
39 import (
40 "strings"
41 "example.com/a"
42 )
43
44 func _() {
45 var buf strings.Builder
46 // The inliner wants to add an import for "io"; make sure post-processing of the fix removes it.
47 a.NewHello(&buf) // want "Call of a.OldHello should be inlined"
48 }
49
50 -- c/c.go --
51 package c
52
53 import "encoding/json"
54
55 //go:fix inline
56 func OldProcess(m json.Marshaler) error { // want OldProcess:"goFixInline c.OldProcess"
57 return NewProcess(m)
58 }
59
60 func NewProcess(m json.Marshaler) error {
61 _, err := m.MarshalJSON()
62 return err
63 }
64
65 -- d/d.go --
66 package d
67
68 import (
69 "time"
70
71 "example.com/c"
72 )
73
74 func _() {
75 t := time.Now()
76 // The inliner wants to add an import for "encoding/json"; make sure post-processing of the fix removes it.
77 c.OldProcess(t) // want "Call of c.OldProcess should be inlined"
78 }
79
80 -- d/d.go.golden --
81 package d
82
83 import (
84 "time"
85
86 "example.com/c"
87 )
88
89 func _() {
90 t := time.Now()
91 // The inliner wants to add an import for "encoding/json"; make sure post-processing of the fix removes it.
92 c.NewProcess(t) // want "Call of c.OldProcess should be inlined"
93 }