File: stub.txt

package info (click to toggle)
golang-golang-x-tools 1%3A0.25.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 22,724 kB
  • sloc: javascript: 2,027; asm: 1,645; sh: 166; yacc: 155; makefile: 49; ansic: 8
file content (365 lines) | stat: -rw-r--r-- 7,963 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
This test checks the 'implement interface' quick fix.

-- go.mod --
module golang.org/lsptests/stub

go 1.18

-- other/other.go --
package other

import (
	"bytes"
	renamed_context "context"
)

type Interface interface {
	Get(renamed_context.Context) *bytes.Buffer
}

-- add_selector.go --
package stub

import "io"

// This file tests that if an interface
// method references a type from its own package
// then our implementation must add the import/package selector
// in the concrete method if the concrete type is outside of the interface
// package
var _ io.ReaderFrom = &readerFrom{} //@suggestedfix("&readerFrom", re"cannot use", readerFrom)

type readerFrom struct{}
-- @readerFrom/add_selector.go --
@@ -13 +13,5 @@
+
+// ReadFrom implements io.ReaderFrom.
+func (*readerFrom) ReadFrom(r io.Reader) (n int64, err error) {
+	panic("unimplemented")
+}
-- assign.go --
package stub

import "io"

func _() {
	var br io.ByteWriter
	br = &byteWriter{} //@suggestedfix("&", re"does not implement", assign)
	_ = br
}

type byteWriter struct{}
-- @assign/assign.go --
@@ -12 +12,5 @@
+
+// WriteByte implements io.ByteWriter.
+func (b *byteWriter) WriteByte(c byte) error {
+	panic("unimplemented")
+}
-- assign_multivars.go --
package stub

import "io"

func _() {
	var br io.ByteWriter
	var i int
	i, br = 1, &multiByteWriter{} //@suggestedfix("&", re"does not implement", assign_multivars)
	_, _ = i, br
}

type multiByteWriter struct{}
-- @assign_multivars/assign_multivars.go --
@@ -13 +13,5 @@
+
+// WriteByte implements io.ByteWriter.
+func (m *multiByteWriter) WriteByte(c byte) error {
+	panic("unimplemented")
+}
-- call_expr.go --
package stub

func main() {
	check(&callExpr{}) //@suggestedfix("&", re"does not implement", call_expr)
}

func check(err error) {
	if err != nil {
		panic(err)
	}
}

type callExpr struct{}
-- @call_expr/call_expr.go --
@@ -14 +14,5 @@
+
+// Error implements error.
+func (c *callExpr) Error() string {
+	panic("unimplemented")
+}
-- embedded.go --
package stub

import (
	"io"
	"sort"
)

var _ embeddedInterface = (*embeddedConcrete)(nil) //@suggestedfix("(", re"does not implement", embedded)

type embeddedConcrete struct{}

type embeddedInterface interface {
	sort.Interface
	io.Reader
}
-- @embedded/embedded.go --
@@ -12 +12,20 @@
+// Len implements embeddedInterface.
+func (e *embeddedConcrete) Len() int {
+	panic("unimplemented")
+}
+
+// Less implements embeddedInterface.
+func (e *embeddedConcrete) Less(i int, j int) bool {
+	panic("unimplemented")
+}
+
+// Read implements embeddedInterface.
+func (e *embeddedConcrete) Read(p []byte) (n int, err error) {
+	panic("unimplemented")
+}
+
+// Swap implements embeddedInterface.
+func (e *embeddedConcrete) Swap(i int, j int) {
+	panic("unimplemented")
+}
+
-- err.go --
package stub

func _() {
	var br error = &customErr{} //@suggestedfix("&", re"does not implement", err)
	_ = br
}

type customErr struct{}
-- @err/err.go --
@@ -9 +9,5 @@
+
+// Error implements error.
+func (c *customErr) Error() string {
+	panic("unimplemented")
+}
-- function_return.go --
package stub

import (
	"io"
)

func newCloser() io.Closer {
	return closer{} //@suggestedfix("c", re"does not implement", function_return)
}

type closer struct{}
-- @function_return/function_return.go --
@@ -12 +12,5 @@
+
+// Close implements io.Closer.
+func (c closer) Close() error {
+	panic("unimplemented")
+}
-- generic_receiver.go --
package stub

import "io"

// This file tests that that the stub method generator accounts for concrete
// types that have type parameters defined.
var _ io.ReaderFrom = &genReader[string, int]{} //@suggestedfix("&genReader", re"does not implement", generic_receiver)

type genReader[T, Y any] struct {
	T T
	Y Y
}
-- @generic_receiver/generic_receiver.go --
@@ -13 +13,5 @@
+
+// ReadFrom implements io.ReaderFrom.
+func (g *genReader[T, Y]) ReadFrom(r io.Reader) (n int64, err error) {
+	panic("unimplemented")
+}
-- ignored_imports.go --
package stub

import (
	"compress/zlib"
	. "io"
	_ "io"
)

// This file tests that dot-imports and underscore imports
// are properly ignored and that a new import is added to
// reference method types

var (
	_ Reader
	_ zlib.Resetter = (*ignoredResetter)(nil) //@suggestedfix("(", re"does not implement", ignored_imports)
)

type ignoredResetter struct{}
-- @ignored_imports/ignored_imports.go --
@@ -19 +19,5 @@
+
+// Reset implements zlib.Resetter.
+func (i *ignoredResetter) Reset(r Reader, dict []byte) error {
+	panic("unimplemented")
+}
-- issue2606.go --
package stub

type I interface{ error }

type C int

var _ I = C(0) //@suggestedfix("C", re"does not implement", issue2606)
-- @issue2606/issue2606.go --
@@ -7 +7,5 @@
+// Error implements I.
+func (c C) Error() string {
+	panic("unimplemented")
+}
+
-- multi_var.go --
package stub

import "io"

// This test ensures that a variable declaration that
// has multiple values on the same line can still be
// analyzed correctly to target the interface implementation
// diagnostic.
var one, two, three io.Reader = nil, &multiVar{}, nil //@suggestedfix("&", re"does not implement", multi_var)

type multiVar struct{}
-- @multi_var/multi_var.go --
@@ -12 +12,5 @@
+
+// Read implements io.Reader.
+func (m *multiVar) Read(p []byte) (n int, err error) {
+	panic("unimplemented")
+}
-- pointer.go --
package stub

import "io"

func getReaderFrom() io.ReaderFrom {
	return &pointerImpl{} //@suggestedfix("&", re"does not implement", pointer)
}

type pointerImpl struct{}
-- @pointer/pointer.go --
@@ -10 +10,5 @@
+
+// ReadFrom implements io.ReaderFrom.
+func (p *pointerImpl) ReadFrom(r io.Reader) (n int64, err error) {
+	panic("unimplemented")
+}
-- renamed_import.go --
package stub

import (
	"compress/zlib"
	myio "io"
)

var _ zlib.Resetter = &myIO{} //@suggestedfix("&", re"does not implement", renamed_import)
var _ myio.Reader

type myIO struct{}
-- @renamed_import/renamed_import.go --
@@ -12 +12,5 @@
+
+// Reset implements zlib.Resetter.
+func (m *myIO) Reset(r myio.Reader, dict []byte) error {
+	panic("unimplemented")
+}
-- renamed_import_iface.go --
package stub

import (
	"golang.org/lsptests/stub/other"
)

// This file tests that if an interface
// method references an import from its own package
// that the concrete type does not yet import, and that import happens
// to be renamed, then we prefer the renaming of the interface.
var _ other.Interface = &otherInterfaceImpl{} //@suggestedfix("&otherInterfaceImpl", re"does not implement", renamed_import_iface)

type otherInterfaceImpl struct{}
-- @renamed_import_iface/renamed_import_iface.go --
@@ -4 +4,2 @@
+	"bytes"
+	"context"
@@ -14 +16,5 @@
+
+// Get implements other.Interface.
+func (o *otherInterfaceImpl) Get(context.Context) *bytes.Buffer {
+	panic("unimplemented")
+}
-- stdlib.go --
package stub

import (
	"io"
)

var _ io.Writer = writer{} //@suggestedfix("w", re"does not implement", stdlib)

type writer struct{}
-- @stdlib/stdlib.go --
@@ -10 +10,5 @@
+
+// Write implements io.Writer.
+func (w writer) Write(p []byte) (n int, err error) {
+	panic("unimplemented")
+}
-- typedecl_group.go --
package stub

// Regression test for Issue #56825: file corrupted by insertion of
// methods after TypeSpec in a parenthesized TypeDecl.

import "io"

func newReadCloser() io.ReadCloser {
	return rdcloser{} //@suggestedfix("rd", re"does not implement", typedecl_group)
}

type (
	A        int
	rdcloser struct{}
	B        int
)

func _() {
	// Local types can't be stubbed as there's nowhere to put the methods.
	// The suggestedfix assertion can't express this yet. TODO(adonovan): support it.
	type local struct{}
	var _ io.ReadCloser = local{} //@diag("local", re"does not implement")
}
-- @typedecl_group/typedecl_group.go --
@@ -18 +18,10 @@
+// Close implements io.ReadCloser.
+func (r rdcloser) Close() error {
+	panic("unimplemented")
+}
+
+// Read implements io.ReadCloser.
+func (r rdcloser) Read(p []byte) (n int, err error) {
+	panic("unimplemented")
+}
+