| 1 |
This test checks the behavior of the 'extract variable/constant' code action |
| 2 |
at top level (outside any function). See issue #70665. |
| 3 |
|
| 4 |
-- a.go -- |
| 5 |
package a |
| 6 |
|
| 7 |
const Length = len("hello") + 2 //@codeaction(`len("hello")`, "refactor.extract.constant", edit=lenhello) |
| 8 |
|
| 9 |
var Slice = append([]int{}, 1, 2, 3) //@codeaction("[]int{}", "refactor.extract.variable", edit=sliceliteral) |
| 10 |
|
| 11 |
type SHA256 [32]byte //@codeaction("32", "refactor.extract.constant", edit=arraylen) |
| 12 |
|
| 13 |
func F([2]int) {} //@codeaction("2", "refactor.extract.constant", edit=paramtypearraylen) |
| 14 |
|
| 15 |
-- @lenhello/a.go -- |
| 16 |
@@ -3 +3,2 @@ |
| 17 |
-const Length = len("hello") + 2 //@codeaction(`len("hello")`, "refactor.extract.constant", edit=lenhello) |
| 18 |
+const newConst = len("hello") |
| 19 |
+const Length = newConst + 2 //@codeaction(`len("hello")`, "refactor.extract.constant", edit=lenhello) |
| 20 |
-- @sliceliteral/a.go -- |
| 21 |
@@ -5 +5,2 @@ |
| 22 |
-var Slice = append([]int{}, 1, 2, 3) //@codeaction("[]int{}", "refactor.extract.variable", edit=sliceliteral) |
| 23 |
+var newVar = []int{} |
| 24 |
+var Slice = append(newVar, 1, 2, 3) //@codeaction("[]int{}", "refactor.extract.variable", edit=sliceliteral) |
| 25 |
-- @arraylen/a.go -- |
| 26 |
@@ -7 +7,2 @@ |
| 27 |
-type SHA256 [32]byte //@codeaction("32", "refactor.extract.constant", edit=arraylen) |
| 28 |
+const newConst = 32 |
| 29 |
+type SHA256 [newConst]byte //@codeaction("32", "refactor.extract.constant", edit=arraylen) |
| 30 |
-- @paramtypearraylen/a.go -- |
| 31 |
@@ -9 +9,2 @@ |
| 32 |
-func F([2]int) {} //@codeaction("2", "refactor.extract.constant", edit=paramtypearraylen) |
| 33 |
+const newConst = 2 |
| 34 |
+func F([newConst]int) {} //@codeaction("2", "refactor.extract.constant", edit=paramtypearraylen) |
| 35 |
-- b/b.go -- |
| 36 |
package b |
| 37 |
|
| 38 |
// Check that package- and file-level name collisions are avoided. |
| 39 |
|
| 40 |
import newVar3 "errors" |
| 41 |
|
| 42 |
var newVar, newVar1, newVar2 any // these names are taken already |
| 43 |
var _ = newVar3.New("") |
| 44 |
var a, b int |
| 45 |
var C = a + b //@codeaction("a + b", "refactor.extract.variable", edit=fresh) |
| 46 |
|
| 47 |
-- @fresh/b/b.go -- |
| 48 |
@@ -10 +10,2 @@ |
| 49 |
-var C = a + b //@codeaction("a + b", "refactor.extract.variable", edit=fresh) |
| 50 |
+var newVar4 = a + b |
| 51 |
+var C = newVar4 //@codeaction("a + b", "refactor.extract.variable", edit=fresh) |