@@ -477,6 +477,12 @@ function! Test_goReceiverHighlight() abort
477
477
\ ' ValueReceiverType' : {' group' : ' goReceiverType' , ' value' : " t T\x1f " },
478
478
\ ' PointerReceiverTypeOmittedVar' : {' group' : ' goReceiverType' , ' value' : " *T\x1f " },
479
479
\ ' ValueReceiverTypeOmittedVar' : {' group' : ' goReceiverType' , ' value' : " T\x1f " },
480
+ \ ' GenericPointerReceiverVar' : {' group' : ' goReceiverVar' , ' value' : " g\x1f *G[int]" },
481
+ \ ' GenericValueReceiverVar' : {' group' : ' goReceiverVar' , ' value' : " g\x1f G[int]" },
482
+ \ ' GenericPointerReceiverType' : {' group' : ' goReceiverType' , ' value' : " g *G\x1f [int]" },
483
+ \ ' GenericValueReceiverType' : {' group' : ' goReceiverType' , ' value' : " g G\x1f [int]" },
484
+ \ ' GenericPointerReceiverTypeOmittedVar' : {' group' : ' goReceiverType' , ' value' : " *G\x1f [int]" },
485
+ \ ' GenericValueReceiverTypeOmittedVar' : {' group' : ' goReceiverType' , ' value' : " G\x1f [int]" },
480
486
\ }
481
487
482
488
let g: go_highlight_function_parameters = 1
@@ -493,6 +499,7 @@ function! s:receiverHighlightGroup(testname, value)
493
499
\ printf (' package %s' , l: package ),
494
500
\ ' ' ,
495
501
\ ' type T struct{}' ,
502
+ \ ' type G[T any] struct{}' ,
496
503
\ printf (' func (%s) Foo() {}' , a: value ),
497
504
\ ])
498
505
@@ -505,6 +512,109 @@ function! s:receiverHighlightGroup(testname, value)
505
512
endtry
506
513
endfunc
507
514
515
+ function ! Test_GoTypeHighlight () abort
516
+ syntax on
517
+
518
+ let l: tests = {
519
+ \ ' StandardType' : {' group' : ' goTypeName' , ' value' : " T\x1f " },
520
+ \ ' GenericType' : {' group' : ' goTypeName' , ' value' : " G\x1f [T any]" },
521
+ \ }
522
+
523
+ let g: go_highlight_types = 1
524
+ for l: kv in items (l: tests )
525
+ let l: actual = s: typeHighlightGroup (l: kv [0 ], l: kv [1 ].value)
526
+ call assert_equal (l: kv [1 ].group, l: actual , l: kv [0 ])
527
+ endfor
528
+ unlet g: go_highlight_types
529
+ endfunc
530
+
531
+ function ! s: typeHighlightGroup (testname, value)
532
+ let l: package = tolower (a: testname )
533
+ let l: dir = gotest#write_file (printf (' %s/%s.go' , l: package , a: testname ), [
534
+ \ printf (' package %s' , l: package ),
535
+ \ ' ' ,
536
+ \ printf (' type %s struct{}' , a: value ),
537
+ \ ])
538
+
539
+ try
540
+ let l: pos = getcurpos ()
541
+ let l: actual = synIDattr (synID (l: pos [1 ], l: pos [2 ], 1 ), ' name' )
542
+ return l: actual
543
+ finally
544
+ call delete (l: dir , ' rf' )
545
+ endtry
546
+ endfunc
547
+
548
+ function ! Test_goFunction () abort
549
+ syntax on
550
+
551
+ let l: tests = {
552
+ \ ' StandardFunction' : {' group' : ' goFunction' , ' value' : " F\x1f (){}" },
553
+ \ ' GenericFunction' : {' group' : ' goFunction' , ' value' : " G\x1f [T any](_ T){}" },
554
+ \ }
555
+
556
+ let g: go_highlight_functions = 1
557
+ for l: kv in items (l: tests )
558
+ let l: actual = s: functionHighlightGroup (l: kv [0 ], l: kv [1 ].value)
559
+ call assert_equal (l: kv [1 ].group, l: actual , l: kv [0 ])
560
+ endfor
561
+ unlet g: go_highlight_functions
562
+ endfunc
563
+
564
+ function ! s: functionHighlightGroup (testname, value)
565
+ let l: package = tolower (a: testname )
566
+ let l: dir = gotest#write_file (printf (' %s/%s.go' , l: package , a: testname ), [
567
+ \ printf (' package %s' , l: package ),
568
+ \ ' ' ,
569
+ \ printf (' func %s' , a: value ),
570
+ \ ])
571
+
572
+ try
573
+ let l: pos = getcurpos ()
574
+ let l: actual = synIDattr (synID (l: pos [1 ], l: pos [2 ], 1 ), ' name' )
575
+ return l: actual
576
+ finally
577
+ call delete (l: dir , ' rf' )
578
+ endtry
579
+ endfunc
580
+
581
+ function ! Test_goFunctionCall () abort
582
+ syntax on
583
+
584
+ let l: tests = {
585
+ \ ' StandardFunctionCall' : {' group' : ' goFunctionCall' , ' value' : " f\x1f ()" },
586
+ \ ' GenericFunctionCall' : {' group' : ' goFunctionCall' , ' value' : " g\x1f [int](i)" },
587
+ \ }
588
+
589
+ let g: go_highlight_function_calls = 1
590
+ for l: kv in items (l: tests )
591
+ let l: actual = s: functionCallHighlightGroup (l: kv [0 ], l: kv [1 ].value)
592
+ call assert_equal (l: kv [1 ].group, l: actual , l: kv [0 ])
593
+ endfor
594
+ unlet g: go_highlight_function_calls
595
+ endfunc
596
+
597
+ function ! s: functionCallHighlightGroup (testname, value)
598
+ let l: package = tolower (a: testname )
599
+ let l: dir = gotest#write_file (printf (' %s/%s.go' , l: package , a: testname ), [
600
+ \ printf (' package %s' , l: package ),
601
+ \ ' ' ,
602
+ \ ' func f() {}' ,
603
+ \ ' func g[T any](i T) {}' ,
604
+ \ ' func init() {' ,
605
+ \ printf (" \t %s" , a: value ),
606
+ \ ' }' ,
607
+ \ ])
608
+
609
+ try
610
+ let l: pos = getcurpos ()
611
+ let l: actual = synIDattr (synID (l: pos [1 ], l: pos [2 ], 1 ), ' name' )
612
+ return l: actual
613
+ finally
614
+ call delete (l: dir , ' rf' )
615
+ endtry
616
+ endfunc
617
+
508
618
" restore Vi compatibility settings
509
619
let &cpo = s: cpo_save
510
620
unlet s: cpo_save
0 commit comments