]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1404: wrong link to Chapter 2 in new-tutor v9.1.1404
authorPhạm Bình An <111893501+brianhuster@users.noreply.github.com>
Thu, 22 May 2025 20:53:28 +0000 (22:53 +0200)
committerChristian Brabandt <cb@256bit.org>
Thu, 22 May 2025 20:53:28 +0000 (22:53 +0200)
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 expose the function `s:GlobTutorials` as
`tutor#GlobTutorials` and make it also accept a `locale` argument.

closes: #17356

Signed-off-by: Phạm Bình An <111893501+brianhuster@users.noreply.github.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
runtime/autoload/tutor.vim
runtime/tutor/en/vim-01-beginner.tutor
src/testdir/test_plugin_tutor.vim
src/version.c

index 6ab796020dba5c16c7974d145a54dcbccc34cc03..b21e20f814defc9405f3274ae46f79f097e0fb8a 100644 (file)
@@ -157,12 +157,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')
@@ -187,7 +189,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"
@@ -214,7 +216,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
index 86efa78561a9e492ee21d9ead7f8f70183f0a229..8af5d465cf94a4ab03a3ccd84dad5f914bae9c99 100644 (file)
@@ -970,7 +970,7 @@ NOTE: Completion works for many commands. It is especially useful for
 # 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 Vim editor, just enough to
 allow you to use the editor fairly easily. It is far from complete as Vim has
index 61cea3faff2c282ee6614255ea80c2c3f92cbf99..3dc46fd16e8103daeb63e57dc36e9e348d5b7d59 100644 (file)
@@ -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
index f94dbe3e431f3a7b31e0447ec69d2bcf6921feb9..9cecc0be8be5bab833867160b62606d548603ffd 100644 (file)
@@ -709,6 +709,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1404,
 /**/
     1403,
 /**/