Skip to content

Commit

Permalink
add tests for generic functions
Browse files Browse the repository at this point in the history
  • Loading branch information
bhcleek committed Apr 13, 2022
1 parent 23abf94 commit 6aeeba2
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions autoload/go/highlight_test.vim
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,76 @@ function! s:typeHighlightGroup(testname, value)
endtry
endfunc

function! Test_goFunction() abort
syntax on

let l:tests = {
\ 'StandardFunction': {'group': 'goFunction', 'value': "F\x1f(){}"},
\ 'GenericFunction': {'group': 'goFunction', 'value': "G\x1f[T any](_ T){}"},
\ }

let g:go_highlight_functions = 1
for l:kv in items(l:tests)
let l:actual = s:functionHighlightGroup(l:kv[0], l:kv[1].value)
call assert_equal(l:kv[1].group, l:actual, l:kv[0])
endfor
unlet g:go_highlight_functions
endfunc

function! s:functionHighlightGroup(testname, value)
let l:package = tolower(a:testname)
let l:dir = gotest#write_file(printf('%s/%s.go', l:package, a:testname), [
\ printf('package %s', l:package),
\ '',
\ printf('func %s', a:value),
\ ])

try
let l:pos = getcurpos()
let l:actual = synIDattr(synID(l:pos[1], l:pos[2], 1), 'name')
return l:actual
finally
call delete(l:dir, 'rf')
endtry
endfunc

function! Test_goFunctionCall() abort
syntax on

let l:tests = {
\ 'StandardFunctionCall': {'group': 'goFunctionCall', 'value': "f\x1f()"},
\ 'GenericFunctionCall': {'group': 'goFunctionCall', 'value': "g\x1f[int](i)"},
\ }

let g:go_highlight_function_calls = 1
for l:kv in items(l:tests)
let l:actual = s:functionCallHighlightGroup(l:kv[0], l:kv[1].value)
call assert_equal(l:kv[1].group, l:actual, l:kv[0])
endfor
unlet g:go_highlight_function_calls
endfunc

function! s:functionCallHighlightGroup(testname, value)
let l:package = tolower(a:testname)
let l:dir = gotest#write_file(printf('%s/%s.go', l:package, a:testname), [
\ printf('package %s', l:package),
\ '',
\ 'func f() {}',
\ 'func g[T any](i T) {}',
\ 'func init() {',
\ printf("\t%s", a:value),
\ '}',
\ ])

try
let l:pos = getcurpos()
let l:actual = synIDattr(synID(l:pos[1], l:pos[2], 1), 'name')
return l:actual
finally
call delete(l:dir, 'rf')
endtry
endfunc

" restore Vi compatibility settings
let &cpo = s:cpo_save
unlet s:cpo_save
Expand Down

0 comments on commit 6aeeba2

Please sign in to comment.