Skip to content

Commit 6aeeba2

Browse files
committed
add tests for generic functions
1 parent 23abf94 commit 6aeeba2

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

autoload/go/highlight_test.vim

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,76 @@ function! s:typeHighlightGroup(testname, value)
545545
endtry
546546
endfunc
547547

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+
548618
" restore Vi compatibility settings
549619
let &cpo = s:cpo_save
550620
unlet s:cpo_save

0 commit comments

Comments
 (0)