@@ -36,10 +36,9 @@ onStart => {
36
36
}
37
37
s := New (newMapFSWithoutModTime (m ), nil , fileMapGetter (m ))
38
38
39
- paramsForMainSpx := & DocumentLinkParams {
39
+ linksForMainSpx , err := s . textDocumentDocumentLink ( & DocumentLinkParams {
40
40
TextDocument : TextDocumentIdentifier {URI : "file:///main.spx" },
41
- }
42
- linksForMainSpx , err := s .textDocumentDocumentLink (paramsForMainSpx )
41
+ })
43
42
require .NoError (t , err )
44
43
require .Len (t , linksForMainSpx , 14 )
45
44
assert .Contains (t , linksForMainSpx , DocumentLink {
@@ -153,10 +152,9 @@ onStart => {
153
152
Target : toURI ("gop:github.com/goplus/spx?Game.Title" ),
154
153
})
155
154
156
- paramsForMySpriteSpx := & DocumentLinkParams {
155
+ linksForMySpriteSpx , err := s . textDocumentDocumentLink ( & DocumentLinkParams {
157
156
TextDocument : TextDocumentIdentifier {URI : "file:///MySprite.spx" },
158
- }
159
- linksForMySpriteSpx , err := s .textDocumentDocumentLink (paramsForMySpriteSpx )
157
+ })
160
158
require .NoError (t , err )
161
159
require .Len (t , linksForMySpriteSpx , 21 )
162
160
assert .Contains (t , linksForMySpriteSpx , DocumentLink {
@@ -263,22 +261,20 @@ onStart => {
263
261
"main.gop" : []byte (`echo "Hello, Go+!"` ),
264
262
}
265
263
s := New (newMapFSWithoutModTime (m ), nil , fileMapGetter (m ))
266
- params := & DocumentLinkParams {
267
- TextDocument : TextDocumentIdentifier {URI : "file:///main.gop" },
268
- }
269
264
270
- links , err := s .textDocumentDocumentLink (params )
265
+ links , err := s .textDocumentDocumentLink (& DocumentLinkParams {
266
+ TextDocument : TextDocumentIdentifier {URI : "file:///main.gop" },
267
+ })
271
268
assert .EqualError (t , err , `file "main.gop" does not have .spx extension` )
272
269
assert .Nil (t , links )
273
270
})
274
271
275
272
t .Run ("FileNotFound" , func (t * testing.T ) {
276
273
s := New (newMapFSWithoutModTime (map [string ][]byte {}), nil , fileMapGetter (map [string ][]byte {}))
277
- params := & DocumentLinkParams {
278
- TextDocument : TextDocumentIdentifier {URI : "file:///notexist.spx" },
279
- }
280
274
281
- links , err := s .textDocumentDocumentLink (params )
275
+ links , err := s .textDocumentDocumentLink (& DocumentLinkParams {
276
+ TextDocument : TextDocumentIdentifier {URI : "file:///notexist.spx" },
277
+ })
282
278
assert .ErrorIs (t , err , errNoMainSpxFile )
283
279
assert .Nil (t , links )
284
280
})
@@ -294,11 +290,10 @@ var (
294
290
"assets/sounds/MySound/index.json" : []byte (`{}` ),
295
291
}
296
292
s := New (newMapFSWithoutModTime (m ), nil , fileMapGetter (m ))
297
- params := & DocumentLinkParams {
298
- TextDocument : TextDocumentIdentifier {URI : "file:///main.spx" },
299
- }
300
293
301
- links , err := s .textDocumentDocumentLink (params )
294
+ links , err := s .textDocumentDocumentLink (& DocumentLinkParams {
295
+ TextDocument : TextDocumentIdentifier {URI : "file:///main.spx" },
296
+ })
302
297
require .NoError (t , err )
303
298
require .Len (t , links , 3 )
304
299
assert .Contains (t , links , DocumentLink {
@@ -326,4 +321,50 @@ var (
326
321
Target : toURI ("gop:github.com/goplus/spx?Sound" ),
327
322
})
328
323
})
324
+
325
+ t .Run ("AutoBindingSpriteAsEmbeddedField" , func (t * testing.T ) {
326
+ m := map [string ][]byte {
327
+ "main.spx" : []byte (`
328
+ var (
329
+ MySprite
330
+ )
331
+ ` ),
332
+ "MySprite.spx" : []byte (`` ),
333
+ "assets/sprites/MySprite/index.json" : []byte (`{}` ),
334
+ }
335
+ s := New (newMapFSWithoutModTime (m ), nil , fileMapGetter (m ))
336
+
337
+ links , err := s .textDocumentDocumentLink (& DocumentLinkParams {
338
+ TextDocument : TextDocumentIdentifier {URI : "file:///main.spx" },
339
+ })
340
+ require .NoError (t , err )
341
+ require .Len (t , links , 3 )
342
+ assert .Contains (t , links , DocumentLink {
343
+ Range : Range {
344
+ Start : Position {Line : 2 , Character : 1 },
345
+ End : Position {Line : 2 , Character : 9 },
346
+ },
347
+ Target : toURI ("spx://resources/sprites/MySprite" ),
348
+ Data : SpxResourceRefDocumentLinkData {
349
+ Kind : SpxResourceRefKindAutoBinding ,
350
+ },
351
+ })
352
+ assert .NotContains (t , links , DocumentLink {
353
+ Range : Range {
354
+ Start : Position {Line : 2 , Character : 1 },
355
+ End : Position {Line : 2 , Character : 9 },
356
+ },
357
+ Target : toURI ("spx://resources/sprites/MySprite" ),
358
+ Data : SpxResourceRefDocumentLinkData {
359
+ Kind : SpxResourceRefKindAutoBindingReference ,
360
+ },
361
+ })
362
+ assert .Contains (t , links , DocumentLink {
363
+ Range : Range {
364
+ Start : Position {Line : 2 , Character : 1 },
365
+ End : Position {Line : 2 , Character : 9 },
366
+ },
367
+ Target : toURI ("gop:main?Game.MySprite" ),
368
+ })
369
+ })
329
370
}
0 commit comments