Debian Codegraph @

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

raw
1 This test checks the behavior of the 'fill switch' code action.
2 See fill_switch_resolve.txt for same test with resolve support.
3
4 -- capabilities.json --
5 {
6 "textDocument": {
7 "codeAction": {
8 "dataSupport": false,
9 "resolveSupport": {}
10 }
11 }
12 }
13 -- flags --
14 -ignore_extra_diags
15
16 -- go.mod --
17 module golang.org/lsptests/fillswitch
18
19 go 1.18
20
21 -- data/data.go --
22 package data
23
24 type TypeB int
25
26 const (
27 TypeBOne TypeB = iota
28 TypeBTwo
29 TypeBThree
30 )
31
32 -- a.go --
33 package fillswitch
34
35 import (
36 "golang.org/lsptests/fillswitch/data"
37 )
38
39 type typeA int
40
41 const (
42 typeAOne typeA = iota
43 typeATwo
44 typeAThree
45 )
46
47 type notification interface {
48 isNotification()
49 }
50
51 type notificationOne struct{}
52
53 func (notificationOne) isNotification() {}
54
55 type notificationTwo struct{}
56
57 func (notificationTwo) isNotification() {}
58
59 func doSwitch() {
60 var b data.TypeB
61 switch b {
62 case data.TypeBOne: //@codeaction(":", "refactor.rewrite.fillSwitch", edit=a1)
63 }
64
65 var a typeA
66 switch a {
67 case typeAThree: //@codeaction(":", "refactor.rewrite.fillSwitch", edit=a2)
68 }
69
70 var n notification
71 switch n.(type) { //@codeaction("{", "refactor.rewrite.fillSwitch", edit=a3)
72 }
73
74 switch nt := n.(type) { //@codeaction("{", "refactor.rewrite.fillSwitch", edit=a4)
75 }
76
77 var s struct {
78 a typeA
79 }
80
81 switch s.a {
82 case typeAThree: //@codeaction(":", "refactor.rewrite.fillSwitch", edit=a5)
83 }
84 }
85 -- @a1/a.go --
86 @@ -31 +31,4 @@
87 + case data.TypeBThree:
88 + case data.TypeBTwo:
89 + default:
90 + panic(fmt.Sprintf("unexpected data.TypeB: %#v", b))
91 -- @a2/a.go --
92 @@ -36 +36,4 @@
93 + case typeAOne:
94 + case typeATwo:
95 + default:
96 + panic(fmt.Sprintf("unexpected fillswitch.typeA: %#v", a))
97 -- @a3/a.go --
98 @@ -40 +40,4 @@
99 + case notificationOne:
100 + case notificationTwo:
101 + default:
102 + panic(fmt.Sprintf("unexpected fillswitch.notification: %#v", n))
103 -- @a4/a.go --
104 @@ -43 +43,4 @@
105 + case notificationOne:
106 + case notificationTwo:
107 + default:
108 + panic(fmt.Sprintf("unexpected fillswitch.notification: %#v", nt))
109 -- @a5/a.go --
110 @@ -51 +51,4 @@
111 + case typeAOne:
112 + case typeATwo:
113 + default:
114 + panic(fmt.Sprintf("unexpected fillswitch.typeA: %#v", s.a))