Skip to content

Commit 92af479

Browse files
fixup! Add syntax support for toolchain directive
1 parent 90858be commit 92af479

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed

autoload/go/highlight_test.vim

+111
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,117 @@ function! s:functionCallHighlightGroup(testname, value)
671671
endtry
672672
endfunc
673673

674+
function! Test_gomodToolchainVersion_highlight() abort
675+
try
676+
syntax on
677+
678+
let g:go_gopls_enabled = 0
679+
let l:wd = getcwd()
680+
let l:dir = gotest#write_file('gomodtest/go.mod', [
681+
\ 'module github.com/fatih/vim-go',
682+
\ '',
683+
\ 'toolchain go1.21',
684+
\ 'toolchain go1.21rc3',
685+
\ 'toolchain go1.21',
686+
\ 'toolchain go1.21.3-somesuffix',
687+
\ 'toolchain go1.21rc4-somesuffix more suffix',
688+
\ ''])
689+
690+
let l:lineno = 3
691+
let l:lineclose = line('$')
692+
while l:lineno < l:lineclose
693+
let l:line = getline(l:lineno)
694+
let l:split_idx = stridx(l:line, ' ')
695+
let l:idx = 0
696+
let l:col = 1
697+
698+
while l:idx < len(l:line) - 1
699+
call cursor(l:lineno, l:col)
700+
let l:synname = synIDattr(synID(l:lineno, l:col, 1), 'name')
701+
let l:errlen = len(v:errors)
702+
703+
if l:idx < l:split_idx
704+
call assert_equal('gomodToolchain', l:synname, 'toolchain on line ' . l:lineno . ' and col ' . l:col)
705+
elseif l:idx > l:split_idx
706+
call assert_equal('gomodToolchainVersion', l:synname, 'version on line ' . l:lineno . ' and col ' . l:col)
707+
endif
708+
709+
if l:errlen < len(v:errors)
710+
break
711+
endif
712+
713+
let l:col += 1
714+
let l:idx += 1
715+
endwhile
716+
let l:lineno += 1
717+
endwhile
718+
719+
finally
720+
call go#util#Chdir(l:wd)
721+
call delete(l:dir, 'rf')
722+
endtry
723+
endfunc
724+
725+
function! Test_gomodToolchainVersion_invalid_highlight() abort
726+
try
727+
syntax on
728+
let g:go_gopls_enabled = 0
729+
let l:wd = getcwd()
730+
731+
" 1. No release candidate for patch versions
732+
" 2+3. Release version can only be followed by 'rcN' or a valid suffix
733+
" 4+5. toolchain version must start with 'go'
734+
let l:dir = gotest#write_file('gomodtest/go.mod', [
735+
\ 'module github.com/fatih/vim-go',
736+
\ '',
737+
\ 'toolchain go1.21.1rc2',
738+
\ 'toolchain go1.21abc',
739+
\ 'toolchain go1.21!some-suffix',
740+
\ 'toolchain 1.21rc2',
741+
\ 'toolchain 1.21.3',
742+
\ ''])
743+
744+
let l:lineno = 3
745+
let l:lineclose = line('$')
746+
while l:lineno < l:lineclose
747+
let l:line = getline(l:lineno)
748+
let l:col = col([l:lineno, '$']) - 1
749+
let l:idx = len(l:line) - 1
750+
" e.g. go1.21.1rc2 is valid until 'rc2'
751+
" each 'go*' test above has last version number '1'
752+
let l:valid_version_start_idx = strridx(l:line, '1')
753+
754+
if l:valid_version_start_idx != -1
755+
let l:end_idx = l:valid_version_start_idx
756+
else
757+
" the whole version is invalid
758+
let l:end_idx = stridx(l:line, ' ') + 1
759+
endif
760+
761+
while l:idx > l:end_idx
762+
call cursor(l:lineno, l:col)
763+
let l:synname = synIDattr(synID(l:lineno, l:col, 1), 'name')
764+
let l:errlen = len(v:errors)
765+
766+
call assert_notequal('gomodToolchainVersion', l:synname, 'version on line ' . l:lineno . ' and col ' . l:col)
767+
768+
if l:errlen < len(v:errors)
769+
break
770+
endif
771+
772+
let l:col -= 1
773+
let l:idx -= 1
774+
endwhile
775+
let l:lineno += 1
776+
endwhile
777+
778+
finally
779+
call go#util#Chdir(l:wd)
780+
call delete(l:dir, 'rf')
781+
endtry
782+
endfunc
783+
784+
674785
" restore Vi compatibility settings
675786
let &cpo = s:cpo_save
676787
unlet s:cpo_save

0 commit comments

Comments
 (0)