commit f791ae82e5b1480fb3baab7100338f04dcbbdb2c
parent 41c850e2c8dc56284db8eacb9581beafd27690a8
Author: brianhuster <phambinhanctb2004@gmail.com>
Date: Fri, 23 May 2025 08:40:01 +0700
vim-patch:9.1.1404: wrong link to Chapter 2 in new-tutor
Problem: wrong link to Chapter 2 in vim-01-beginner.tutor
Solution: Fix the link to Chapter 2, add test for links in tutor files
(Phạm Bình An)
In order to write the test, I exposed the function `s:GlobTutorials` as
`tutor#GlobTutorials` and make it also accept a `locale` argument.
closes: vim/vim#17356
https://github.com/vim/vim/commit/e8302da74aee55fe8f6496b5b711fed7d92318c5
Co-authored-by: Phạm Bình An <111893501+brianhuster@users.noreply.github.com>
Diffstat:
3 files changed, 25 insertions(+), 5 deletions(-)
diff --git a/runtime/autoload/tutor.vim b/runtime/autoload/tutor.vim
@@ -167,12 +167,14 @@ function! s:Sort(a, b)
return retval
endfunction
-function! s:GlobTutorials(name)
+" returns a list of all tutor files matching the given name
+function! tutor#GlobTutorials(name, locale)
+ let locale = a:locale
" search for tutorials:
" 1. non-localized
let l:tutors = s:GlobPath(&rtp, 'tutor/'.a:name.'.tutor')
" 2. localized for current locale
- let l:locale_tutors = s:GlobPath(&rtp, 'tutor/'.s:Locale()[0].'/'.a:name.'.tutor')
+ let l:locale_tutors = s:GlobPath(&rtp, 'tutor/'.locale.'/'.a:name.'.tutor')
" 3. fallback to 'en'
if len(l:locale_tutors) == 0
let l:locale_tutors = s:GlobPath(&rtp, 'tutor/en/'.a:name.'.tutor')
@@ -197,7 +199,7 @@ function! tutor#TutorCmd(tutor_name)
let l:tutor_name = fnamemodify(l:tutor_name, ':r')
endif
- let l:tutors = s:GlobTutorials(l:tutor_name)
+ let l:tutors = tutor#GlobTutorials(l:tutor_name, s:Locale()[0])
if len(l:tutors) == 0
echom "No tutorial with that name found"
@@ -225,7 +227,7 @@ function! tutor#TutorCmd(tutor_name)
endfunction
function! tutor#TutorCmdComplete(lead,line,pos)
- let l:tutors = s:GlobTutorials('*')
+ let l:tutors = tutor#GlobTutorials('*', s:Locale()[0])
let l:names = uniq(sort(map(l:tutors, 'fnamemodify(v:val, ":t:r")'), 's:Sort'))
return join(l:names, "\n")
endfunction
diff --git a/runtime/tutor/en/vim-01-beginner.tutor b/runtime/tutor/en/vim-01-beginner.tutor
@@ -981,7 +981,7 @@ Run `:help nvim-quickstart`{vim} for more information on extending Nvim.
# CONCLUSION
This concludes Chapter 1 of the Vim Tutor. Consider continuing with
-[Chapter 2](@tutor:tutor:vim-02-beginner).
+[Chapter 2](@tutor:vim-02-beginner).
This was intended to give a brief overview of the Neovim editor, just enough to
allow you to use it fairly easily. It is far from complete as Neovim has
diff --git a/test/old/testdir/test_plugin_tutor.vim b/test/old/testdir/test_plugin_tutor.vim
@@ -14,3 +14,21 @@ func Test_auto_enable_interactive()
call assert_true(empty(&buftype))
call assert_match('tutor#EnableInteractive', b:undo_ftplugin)
endfunc
+
+func Test_tutor_link()
+ let tutor_files = globpath($VIMRUNTIME, 'tutor/**/*.tutor', 0, 1)
+ let pattern = '\[.\{-}@tutor:\zs[^)\]]*\ze[)\]]'
+
+ for tutor_file in tutor_files
+ let lang = fnamemodify(tutor_file, ':h:t')
+ if lang == 'tutor'
+ let lang = 'en'
+ endif
+
+ let text = readfile(tutor_file)
+ let links = matchstrlist(text, pattern)->map({_, v -> v.text})
+ for link in links
+ call assert_true(tutor#GlobTutorials(link, lang)->len() > 0)
+ endfor
+ endfor
+endfunc