@@ -15,6 +15,7 @@ import (
15
15
"io/ioutil"
16
16
"path/filepath"
17
17
"sort"
18
+ "strconv"
18
19
"strings"
19
20
"sync"
20
21
"testing"
@@ -39,13 +40,13 @@ var UpdateGolden = flag.Bool("golden", false, "Update golden files")
39
40
40
41
type Diagnostics map [span.URI ][]source.Diagnostic
41
42
type CompletionItems map [token.Pos ]* source.CompletionItem
42
- type Completions map [span.Span ]Completion
43
- type CompletionSnippets map [span.Span ]CompletionSnippet
44
- type UnimportedCompletions map [span.Span ]Completion
45
- type DeepCompletions map [span.Span ]Completion
46
- type FuzzyCompletions map [span.Span ]Completion
47
- type CaseSensitiveCompletions map [span.Span ]Completion
48
- type RankCompletions map [span.Span ]Completion
43
+ type Completions map [span.Span ][] Completion
44
+ type CompletionSnippets map [span.Span ][] CompletionSnippet
45
+ type UnimportedCompletions map [span.Span ][] Completion
46
+ type DeepCompletions map [span.Span ][] Completion
47
+ type FuzzyCompletions map [span.Span ][] Completion
48
+ type CaseSensitiveCompletions map [span.Span ][] Completion
49
+ type RankCompletions map [span.Span ][] Completion
49
50
type FoldingRanges []span.Span
50
51
type Formats []span.Span
51
52
type Imports []span.Span
@@ -343,80 +344,67 @@ func Run(t *testing.T, tests Tests, data *Data) {
343
344
t .Helper ()
344
345
checkData (t , data )
345
346
346
- t . Run ( " Completion" , func (t * testing.T ) {
347
+ eachCompletion := func ( t * testing. T , cases map [span. Span ][] Completion , test func (* testing.T , span. Span , Completion , CompletionItems ) ) {
347
348
t .Helper ()
348
- for src , test := range data .Completions {
349
- t .Run (spanName (src ), func (t * testing.T ) {
350
- t .Helper ()
351
- tests .Completion (t , src , test , data .CompletionItems )
352
- })
349
+
350
+ for src , exp := range cases {
351
+ for i , e := range exp {
352
+ t .Run (spanName (src )+ "_" + strconv .Itoa (i ), func (t * testing.T ) {
353
+ t .Helper ()
354
+ test (t , src , e , data .CompletionItems )
355
+ })
356
+ }
357
+
353
358
}
359
+ }
360
+
361
+ t .Run ("Completion" , func (t * testing.T ) {
362
+ t .Helper ()
363
+ eachCompletion (t , data .Completions , tests .Completion )
354
364
})
355
365
356
366
t .Run ("CompletionSnippets" , func (t * testing.T ) {
357
367
t .Helper ()
358
368
for _ , placeholders := range []bool {true , false } {
359
- for src , expected := range data .CompletionSnippets {
360
- name := spanName (src )
361
- if placeholders {
362
- name += "_placeholders"
369
+ for src , expecteds := range data .CompletionSnippets {
370
+ for i , expected := range expecteds {
371
+ name := spanName (src ) + "_" + strconv .Itoa (i + 1 )
372
+ if placeholders {
373
+ name += "_placeholders"
374
+ }
375
+
376
+ t .Run (name , func (t * testing.T ) {
377
+ t .Helper ()
378
+ tests .CompletionSnippet (t , src , expected , placeholders , data .CompletionItems )
379
+ })
363
380
}
364
- t .Run (name , func (t * testing.T ) {
365
- t .Helper ()
366
- tests .CompletionSnippet (t , src , expected , placeholders , data .CompletionItems )
367
- })
368
381
}
369
382
}
370
383
})
371
384
372
385
t .Run ("UnimportedCompletion" , func (t * testing.T ) {
373
386
t .Helper ()
374
- for src , test := range data .UnimportedCompletions {
375
- t .Run (spanName (src ), func (t * testing.T ) {
376
- t .Helper ()
377
- tests .UnimportedCompletion (t , src , test , data .CompletionItems )
378
- })
379
- }
387
+ eachCompletion (t , data .UnimportedCompletions , tests .UnimportedCompletion )
380
388
})
381
389
382
390
t .Run ("DeepCompletion" , func (t * testing.T ) {
383
391
t .Helper ()
384
- for src , test := range data .DeepCompletions {
385
- t .Run (spanName (src ), func (t * testing.T ) {
386
- t .Helper ()
387
- tests .DeepCompletion (t , src , test , data .CompletionItems )
388
- })
389
- }
392
+ eachCompletion (t , data .DeepCompletions , tests .DeepCompletion )
390
393
})
391
394
392
395
t .Run ("FuzzyCompletion" , func (t * testing.T ) {
393
396
t .Helper ()
394
- for src , test := range data .FuzzyCompletions {
395
- t .Run (spanName (src ), func (t * testing.T ) {
396
- t .Helper ()
397
- tests .FuzzyCompletion (t , src , test , data .CompletionItems )
398
- })
399
- }
397
+ eachCompletion (t , data .FuzzyCompletions , tests .FuzzyCompletion )
400
398
})
401
399
402
400
t .Run ("CaseSensitiveCompletion" , func (t * testing.T ) {
403
401
t .Helper ()
404
- for src , test := range data .CaseSensitiveCompletions {
405
- t .Run (spanName (src ), func (t * testing.T ) {
406
- t .Helper ()
407
- tests .CaseSensitiveCompletion (t , src , test , data .CompletionItems )
408
- })
409
- }
402
+ eachCompletion (t , data .CaseSensitiveCompletions , tests .CaseSensitiveCompletion )
410
403
})
411
404
412
405
t .Run ("RankCompletions" , func (t * testing.T ) {
413
406
t .Helper ()
414
- for src , test := range data .RankCompletions {
415
- t .Run (spanName (src ), func (t * testing.T ) {
416
- t .Helper ()
417
- tests .RankCompletion (t , src , test , data .CompletionItems )
418
- })
419
- }
407
+ eachCompletion (t , data .RankCompletions , tests .RankCompletion )
420
408
})
421
409
422
410
t .Run ("Diagnostics" , func (t * testing.T ) {
@@ -594,13 +582,25 @@ func checkData(t *testing.T, data *Data) {
594
582
}
595
583
}
596
584
597
- fmt .Fprintf (buf , "CompletionsCount = %v\n " , len (data .Completions ))
598
- fmt .Fprintf (buf , "CompletionSnippetCount = %v\n " , len (data .CompletionSnippets ))
599
- fmt .Fprintf (buf , "UnimportedCompletionsCount = %v\n " , len (data .UnimportedCompletions ))
600
- fmt .Fprintf (buf , "DeepCompletionsCount = %v\n " , len (data .DeepCompletions ))
601
- fmt .Fprintf (buf , "FuzzyCompletionsCount = %v\n " , len (data .FuzzyCompletions ))
602
- fmt .Fprintf (buf , "RankedCompletionsCount = %v\n " , len (data .RankCompletions ))
603
- fmt .Fprintf (buf , "CaseSensitiveCompletionsCount = %v\n " , len (data .CaseSensitiveCompletions ))
585
+ snippetCount := 0
586
+ for _ , want := range data .CompletionSnippets {
587
+ snippetCount += len (want )
588
+ }
589
+
590
+ countCompletions := func (c map [span.Span ][]Completion ) (count int ) {
591
+ for _ , want := range c {
592
+ count += len (want )
593
+ }
594
+ return count
595
+ }
596
+
597
+ fmt .Fprintf (buf , "CompletionsCount = %v\n " , countCompletions (data .Completions ))
598
+ fmt .Fprintf (buf , "CompletionSnippetCount = %v\n " , snippetCount )
599
+ fmt .Fprintf (buf , "UnimportedCompletionsCount = %v\n " , countCompletions (data .UnimportedCompletions ))
600
+ fmt .Fprintf (buf , "DeepCompletionsCount = %v\n " , countCompletions (data .DeepCompletions ))
601
+ fmt .Fprintf (buf , "FuzzyCompletionsCount = %v\n " , countCompletions (data .FuzzyCompletions ))
602
+ fmt .Fprintf (buf , "RankedCompletionsCount = %v\n " , countCompletions (data .RankCompletions ))
603
+ fmt .Fprintf (buf , "CaseSensitiveCompletionsCount = %v\n " , countCompletions (data .CaseSensitiveCompletions ))
604
604
fmt .Fprintf (buf , "DiagnosticsCount = %v\n " , diagnosticsCount )
605
605
fmt .Fprintf (buf , "FoldingRangesCount = %v\n " , len (data .FoldingRanges ))
606
606
fmt .Fprintf (buf , "FormatCount = %v\n " , len (data .Formats ))
@@ -723,10 +723,10 @@ func (data *Data) collectDiagnostics(spn span.Span, msgSource, msg string) {
723
723
}
724
724
725
725
func (data * Data ) collectCompletions (typ CompletionTestType ) func (span.Span , []token.Pos ) {
726
- result := func (m map [span.Span ]Completion , src span.Span , expected []token.Pos ) {
727
- m [src ] = Completion {
726
+ result := func (m map [span.Span ][] Completion , src span.Span , expected []token.Pos ) {
727
+ m [src ] = append ( m [ src ], Completion {
728
728
CompletionItems : expected ,
729
- }
729
+ })
730
730
}
731
731
switch typ {
732
732
case CompletionDeep :
@@ -896,11 +896,11 @@ func (data *Data) collectSignatures(spn span.Span, signature string, activeParam
896
896
}
897
897
898
898
func (data * Data ) collectCompletionSnippets (spn span.Span , item token.Pos , plain , placeholder string ) {
899
- data .CompletionSnippets [spn ] = CompletionSnippet {
899
+ data .CompletionSnippets [spn ] = append ( data . CompletionSnippets [ spn ], CompletionSnippet {
900
900
CompletionItem : item ,
901
901
PlainSnippet : plain ,
902
902
PlaceholderSnippet : placeholder ,
903
- }
903
+ })
904
904
}
905
905
906
906
func (data * Data ) collectLinks (spn span.Span , link string , note * expect.Note , fset * token.FileSet ) {
0 commit comments