Debian Codegraph @

gopls/internal/test/marker/testdata/codeaction/moveparam.txt

raw
1 This test checks basic functionality of the "move parameter left/right" code
2 action.
3
4 Note that in many of these tests, a permutation can either be expressed as
5 a parameter move left or right. In these cases, the codeaction assertions
6 deliberately share the same golden data.
7
8 -- go.mod --
9 module example.com/moveparam
10
11 go 1.19
12
13 -- basic/basic.go --
14 package basic
15
16 func Foo(a, b int) int { //@codeaction("a", "refactor.rewrite.moveParamRight", result=basic), codeaction("b", "refactor.rewrite.moveParamLeft", result=basic)
17 return a + b
18 }
19
20 func _() {
21 x, y := 1, 2
22 z := Foo(x, y)
23 _ = z
24 }
25
26 -- basic/caller/caller.go --
27 package caller
28
29 import "example.com/moveparam/basic"
30
31 func a() int { return 1 }
32 func b() int { return 2 }
33
34 // Check that we can refactor a call in a toplevel var decl.
35 var _ = basic.Foo(1, 2)
36
37 // Check that we can refactor a call with effects in a toplevel var decl.
38 var _ = basic.Foo(a(), b())
39
40 func _() {
41 // check various refactorings in a function body, and comment handling.
42 _ = basic.Foo(1, 2) // with comments
43 // another comment
44 _ = basic.Foo(3, 4)
45 x := 4
46 x = basic.Foo(x /* this is an inline comment */, 5)
47 }
48
49 -- @basic/basic/basic.go --
50 package basic
51
52 func Foo(b, a int) int { //@codeaction("a", "refactor.rewrite.moveParamRight", result=basic), codeaction("b", "refactor.rewrite.moveParamLeft", result=basic)
53 return a + b
54 }
55
56 func _() {
57 x, y := 1, 2
58 z := Foo(y, x)
59 _ = z
60 }
61 -- @basic/basic/caller/caller.go --
62 package caller
63
64 import "example.com/moveparam/basic"
65
66 func a() int { return 1 }
67 func b() int { return 2 }
68
69 // Check that we can refactor a call in a toplevel var decl.
70 var _ = basic.Foo(2, 1)
71
72 // Check that we can refactor a call with effects in a toplevel var decl.
73 var _ = basic.Foo(b(), a())
74
75 func _() {
76 // check various refactorings in a function body, and comment handling.
77 _ = basic.Foo(2, 1) // with comments
78 // another comment
79 _ = basic.Foo(4, 3)
80 x := 4
81 x = basic.Foo(5, x)
82 }
83 -- method/method.go --
84 package method
85
86 type T struct{}
87
88 func (T) Foo(a, b int) {} //@codeaction("a", "refactor.rewrite.moveParamRight", result=method), codeaction("b", "refactor.rewrite.moveParamLeft", result=method)
89
90 func _() {
91 var t T
92 t.Foo(1, 2)
93 // TODO(rfindley): test method expressions here, once they are handled.
94 }
95
96 -- method/caller/caller.go --
97 package caller
98
99 import "example.com/moveparam/method"
100
101 func _() {
102 var t method.T
103 t.Foo(1, 2)
104 }
105
106 -- @method/method/caller/caller.go --
107 package caller
108
109 import "example.com/moveparam/method"
110
111 func _() {
112 var t method.T
113 t.Foo(2, 1)
114 }
115 -- @method/method/method.go --
116 package method
117
118 type T struct{}
119
120 func (T) Foo(b, a int) {} //@codeaction("a", "refactor.rewrite.moveParamRight", result=method), codeaction("b", "refactor.rewrite.moveParamLeft", result=method)
121
122 func _() {
123 var t T
124 t.Foo(2, 1)
125 // TODO(rfindley): test method expressions here, once they are handled.
126 }
127 -- fieldlist/joinfield.go --
128 package fieldlist
129
130 func JoinField(a int, b string, c int) {} //@codeaction("a", "refactor.rewrite.moveParamRight", result=joinfield), codeaction("b", "refactor.rewrite.moveParamLeft", result=joinfield)
131
132 func _() {
133 JoinField(1, "2", 3)
134 }
135
136 -- @joinfield/fieldlist/joinfield.go --
137 package fieldlist
138
139 func JoinField(b string, a, c int) {} //@codeaction("a", "refactor.rewrite.moveParamRight", result=joinfield), codeaction("b", "refactor.rewrite.moveParamLeft", result=joinfield)
140
141 func _() {
142 JoinField("2", 1, 3)
143 }
144 -- fieldlist/splitfield.go --
145 package fieldlist
146
147 func SplitField(a int, b, c string) {} //@codeaction("a", "refactor.rewrite.moveParamRight", result=splitfield), codeaction("b", "refactor.rewrite.moveParamLeft", result=splitfield)
148
149 func _() {
150 SplitField(1, "2", "3")
151 }
152
153 -- @splitfield/fieldlist/splitfield.go --
154 package fieldlist
155
156 func SplitField(b string, a int, c string) {} //@codeaction("a", "refactor.rewrite.moveParamRight", result=splitfield), codeaction("b", "refactor.rewrite.moveParamLeft", result=splitfield)
157
158 func _() {
159 SplitField("2", 1, "3")
160 }
161 -- unnamed/unnamed.go --
162 package unnamed
163
164 func Unnamed(int, string) { //@codeaction("int", "refactor.rewrite.moveParamRight", result=unnamed)
165 }
166
167 func _() {
168 Unnamed(1, "hi")
169 }
170 -- @unnamed/unnamed/unnamed.go --
171 package unnamed
172
173 func Unnamed(string, int) { //@codeaction("int", "refactor.rewrite.moveParamRight", result=unnamed)
174 }
175
176 func _() {
177 Unnamed("hi", 1)
178 }