6
6
Package marker defines a framework for running "marker" tests, each
7
7
defined by a file in the testdata subdirectory.
8
8
9
- Use this command to run the tests:
9
+ Use this command to run the tests, from the gopls module :
10
10
11
- $ go test ./gopls/ internal/test/marker [-update]
11
+ $ go test ./internal/test/marker [-update]
12
12
13
13
A marker test uses the '//@' marker syntax of the x/tools/internal/expect package
14
14
to annotate source code with various information such as locations and
@@ -100,21 +100,17 @@ The following markers are supported within marker tests:
100
100
completion candidate produced at the given location with provided label
101
101
results in the given golden state.
102
102
103
- - codeaction(start, end, kind, golden): specifies a code action
104
- to request for the given range. To support multi-line ranges, the range
105
- is defined to be between start.Start and end.End. The golden directory
106
- contains changed file content after the code action is applied.
103
+ - codeaction(start location, kind string, end=location, edit=golden, result=golden, err=stringMatcher)
107
104
108
- TODO(rfindley): now that 'location' supports multi-line matches, replace
109
- uses of 'codeaction' with codeactionedit.
105
+ Specifies a code action to request at the location, with given kind.
110
106
111
- - codeactionedit(location, kind, golden): a shorter form of
112
- codeaction. Invokes a code action of the given kind for the given
113
- in-line range, and compares the resulting formatted unified *edits*
114
- (notably, not the full file content) with the golden directory.
107
+ If end is set, the location is defined to be between start.Start and end.End.
115
108
116
- - codeactionerr(start, end, kind, wantError): specifies a codeaction that
117
- fails with an error that matches the expectation.
109
+ Exactly one of edit, result, or err must be set.
110
+ If edit is set, it is a golden reference to the edits resulting from the code action.
111
+ If result is set, it is a golden reference to the full set of changed files
112
+ resulting from the code action.
113
+ If err is set, it is the code action error.
118
114
119
115
- codelens(location, title): specifies that a codelens is expected at the
120
116
given location, with given title. Must be used in conjunction with
@@ -136,7 +132,8 @@ The following markers are supported within marker tests:
136
132
but end positions are ignored unless exact=true.
137
133
138
134
TODO(adonovan): in the older marker framework, the annotation asserted
139
- two additional fields (source="compiler", kind="error"). Restore them?
135
+ two additional fields (source="compiler", kind="error"). Restore them using
136
+ optional named arguments.
140
137
141
138
- def(src, dst location): performs a textDocument/definition request at
142
139
the src location, and check the result points to the dst location.
@@ -208,17 +205,6 @@ The following markers are supported within marker tests:
208
205
placeholder. If placeholder is "", this is treated as a negative
209
206
assertion and prepareRename should return nil.
210
207
211
- - rename(location, new, golden): specifies a renaming of the
212
- identifier at the specified location to the new name.
213
- The golden directory contains the transformed files.
214
-
215
- - renameerr(location, new, wantError): specifies a renaming that
216
- fails with an error that matches the expectation.
217
-
218
- - signature(location, label, active): specifies that
219
- signatureHelp at the given location should match the provided string, with
220
- the active parameter (an index) highlighted.
221
-
222
208
- quickfix(location, regexp, golden): like diag, the location and
223
209
regexp identify an expected diagnostic, which must have exactly one
224
210
associated "quickfix" code action.
@@ -244,6 +230,17 @@ The following markers are supported within marker tests:
244
230
'want' locations. The first want location must be the declaration
245
231
(assumedly unique).
246
232
233
+ - rename(location, new, golden): specifies a renaming of the
234
+ identifier at the specified location to the new name.
235
+ The golden directory contains the transformed files.
236
+
237
+ - renameerr(location, new, wantError): specifies a renaming that
238
+ fails with an error that matches the expectation.
239
+
240
+ - signature(location, label, active): specifies that
241
+ signatureHelp at the given location should match the provided string, with
242
+ the active parameter (an index) highlighted.
243
+
247
244
- snippet(location, string OR completionItem, snippet): executes a
248
245
textDocument/completion request at the location, and searches for a result
249
246
with label matching that its second argument, which may be a string literal
@@ -288,20 +285,26 @@ the following tokens as defined by the Go spec:
288
285
These values are passed as arguments to the corresponding parameter of the
289
286
test function. Additional value conversions may occur for these argument ->
290
287
parameter type pairs:
288
+
291
289
- string->regexp: the argument is parsed as a regular expressions.
290
+
292
291
- string->location: the argument is converted to the location of the first
293
292
instance of the argument in the file content starting from the beginning of
294
293
the line containing the note. Multi-line matches are permitted, but the
295
294
match must begin before the note.
295
+
296
296
- regexp->location: the argument is converted to the location of the first
297
297
match for the argument in the file content starting from the beginning of
298
298
the line containing the note. Multi-line matches are permitted, but the
299
299
match must begin before the note. If the regular expression contains
300
300
exactly one subgroup, the position of the subgroup is used rather than the
301
301
position of the submatch.
302
+
302
303
- name->location: the argument is replaced by the named location.
304
+
303
305
- name->Golden: the argument is used to look up golden content prefixed by
304
306
@<argument>.
307
+
305
308
- {string,regexp,identifier}->stringMatcher: a stringMatcher type
306
309
specifies an expected string, either in the form of a substring
307
310
that must be present, a regular expression that it must match, or an
@@ -331,7 +334,7 @@ Here is a complete example:
331
334
In this example, the @hover annotation tells the test runner to run the
332
335
hoverMarker function, which has parameters:
333
336
334
- (mark marker, src, dsc protocol.Location, g *Golden).
337
+ (mark marker, src, dst protocol.Location, g *Golden).
335
338
336
339
The first argument holds the test context, including fake editor with open
337
340
files, and sandboxed directory.
@@ -369,9 +372,6 @@ Note that -update does not cause missing @diag or @loc markers to be added.
369
372
- Provide some means by which locations in the standard library
370
373
(or builtin.go) can be named, so that, for example, we can we
371
374
can assert that MyError implements the built-in error type.
372
- - If possible, improve handling for optional arguments. Rather than have
373
- multiple variations of a marker, it would be nice to support a more
374
- flexible signature: can codeaction, codeactionedit, codeactionerr, and
375
- quickfix be consolidated?
375
+ - Eliminate all *err markers, preferring named arguments.
376
376
*/
377
377
package marker
0 commit comments