tests: Improve the codestyle test (#12988)

Commit: 
https://github.com/vim/vim/commit/b147d314897b7a82081644edf779e22138d44f2c
Author: Christian Brabandt <[email protected]>
Date:   Fri Sep 1 17:58:35 2023 +0100

    tests: Improve the codestyle test (https://github.com/vim/vim/issues/12988)
    
    Improve it by the following:
    
    1) Also check xxd source
    2) Test_source_files():
       don't stop on the first error found, continue until the
       end of the file and report all found errors like this:
    
    Signed-off-by: Christian Brabandt <[email protected]>

diff --git a/src/testdir/test_codestyle.vim b/src/testdir/test_codestyle.vim
index 074468e77..359410d2d 100644
--- a/src/testdir/test_codestyle.vim
+++ b/src/testdir/test_codestyle.vim
@@ -6,48 +6,44 @@ def s:ReportError(fname: string, lnum: number, msg: string)
   endif
 enddef
 
+def s:PerformCheck(fname: string, pattern: string, msg: string, skip: string)
+  var lnum = 1
+  while (lnum > 0)
+    cursor(lnum, 1)
+    lnum = search(pattern, 'W', 0, 0, skip)
+    ReportError(fname, lnum, msg)
+    if (lnum > 0)
+      lnum += 1
+    endif
+  endwhile
+enddef
+
 def Test_source_files()
-  for fname in glob('../*.[ch]', 0, 1)
+  for fname in glob('../*.[ch]', 0, 1) + ['../xxd/xxd.c']
     bwipe!
     g:ignoreSwapExists = 'e'
     exe 'edit ' .. fname
 
-    cursor(1, 1)
-    var lnum = search('        ')
-    ReportError(fname, lnum, 'space before Tab')
+    PerformCheck(fname, '      ', 'space before Tab', '')
 
-    cursor(1, 1)
-    lnum = search('\s$')
-    ReportError(fname, lnum, 'trailing white space')
+    PerformCheck(fname, '\s$', 'trailing white space', '')
 
     # some files don't stick to the Vim style rules
     if fname =~ 'iscygpty.c'
       continue
     endif
 
-    # Examples in comments use "condition) {", skip them.
-    # Skip if a double quote or digit comes after the "{".
-    # Skip specific string used in os_unix.c.
-    # Also skip fold markers.
     var skip = 'getline(".") =~ "condition) {" || getline(".") =~ 
"vimglob_func" || getline(".") =~ "{\"" || getline(".") =~ "{\d" || 
getline(".") =~ "{{{"'
-    cursor(1, 1)
-    lnum = search(')\s*{', '', 0, 0, skip)
-    ReportError(fname, lnum, 'curly after closing paren')
+    PerformCheck(fname, ')\s*{', 'curly after closing paren', skip)
 
     # Examples in comments use double quotes.
     skip = "getline('.') =~ '\"'"
 
-    cursor(1, 1)
-    lnum = search('}\s*else', '', 0, 0, skip)
-    ReportError(fname, lnum, 'curly before "else"')
+    PerformCheck(fname, '}\s*else', 'curly before "else"', skip)
 
-    cursor(1, 1)
-    lnum = search('else\s*{', '', 0, 0, skip)
-    ReportError(fname, lnum, 'curly after "else"')
+    PerformCheck(fname, 'else\s*{', 'curly after "else"', skip)
 
-    cursor(1, 1)
-    lnum = search('\<\(if\|while\|for\)(', '', 0, 0, skip)
-    ReportError(fname, lnum, 'missing white space after "if"/"while"/"for"')
+    PerformCheck(fname, '\<\(if\|while\|for\)(', 'missing white space after 
"if"/"while"/"for"', skip)
   endfor
 
   bwipe!

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/E1qc7VF-00AqXo-7f%40256bit.org.

Raspunde prin e-mail lui