Debian Codegraph @

gopls/internal/test/marker/testdata/codeaction/extract_variable-if.txt

raw
1 This test checks the behavior of the 'extract variable/constant' code actions
2 when the optimal place for the new declaration is within the "if" statement,
3 like so:
4
5 if x := 1 + 2 or y + y ; true {
6 } else if x > 0 {
7 }
8
9 A future refactor.variable implementation that does this should avoid
10 using a 'const' declaration, which is not legal at that location.
11
12 -- flags --
13 -ignore_extra_diags
14
15 -- a.go --
16 package a
17
18 func constant() {
19 if true {
20 } else if 1 + 2 > 0 { //@ codeaction("1 + 2", "refactor.extract.constant", edit=constant)
21 }
22 }
23
24 func variable(y int) {
25 if true {
26 } else if y + y > 0 { //@ codeaction("y + y", "refactor.extract.variable", edit=variable)
27 }
28 }
29
30 -- @constant/a.go --
31 @@ -4 +4 @@
32 + const newConst = 1 + 2
33 @@ -5 +6 @@
34 - } else if 1 + 2 > 0 { //@ codeaction("1 + 2", "refactor.extract.constant", edit=constant)
35 + } else if newConst > 0 { //@ codeaction("1 + 2", "refactor.extract.constant", edit=constant)
36 -- @variable/a.go --
37 @@ -10 +10 @@
38 + newVar := y + y
39 @@ -11 +12 @@
40 - } else if y + y > 0 { //@ codeaction("y + y", "refactor.extract.variable", edit=variable)
41 + } else if newVar > 0 { //@ codeaction("y + y", "refactor.extract.variable", edit=variable)