@@ -6,48 +6,44 @@ def s:ReportError(fname: string, lnum: number, msg: string)
66 endif
77enddef
88
9+ def s: PerformCheck (fname: string , pattern: string , msg: string , skip : string )
10+ var lnum = 1
11+ while (lnum > 0 )
12+ cursor (lnum, 1 )
13+ lnum = search (pattern, ' W' , 0 , 0 , skip )
14+ ReportError (fname, lnum, msg)
15+ if (lnum > 0 )
16+ lnum += 1
17+ endif
18+ endwhile
19+ enddef
20+
921def Test_source_files ()
10- for fname in glob (' ../*.[ch]' , 0 , 1 )
22+ for fname in glob (' ../*.[ch]' , 0 , 1 ) + [ ' ../xxd/xxd.c ' ]
1123 bwipe!
1224 g: ignoreSwapExists = ' e'
1325 exe ' edit ' .. fname
1426
15- cursor (1 , 1 )
16- var lnum = search (' \t' )
17- ReportError (fname, lnum, ' space before Tab' )
27+ PerformCheck (fname, ' \t' , ' space before Tab' , ' ' )
1828
19- cursor (1 , 1 )
20- lnum = search (' \s$' )
21- ReportError (fname, lnum, ' trailing white space' )
29+ PerformCheck (fname, ' \s$' , ' trailing white space' , ' ' )
2230
2331 # some files don't stick to the Vim style rules
2432 if fname = ~ ' iscygpty.c'
2533 continue
2634 endif
2735
28- # Examples in comments use " condition) {" , skip them.
29- # Skip if a double quote or digit comes after the " {" .
30- # Skip specific string used in os_unix.c .
31- # Also skip fold markers.
3236 var skip = ' getline(".") =~ "condition) {" || getline(".") =~ "vimglob_func" || getline(".") =~ "{\"" || getline(".") =~ "{\\d" || getline(".") =~ "{{{"'
33- cursor (1 , 1 )
34- lnum = search (' )\s*{' , ' ' , 0 , 0 , skip )
35- ReportError (fname, lnum, ' curly after closing paren' )
37+ PerformCheck (fname, ' )\s*{' , ' curly after closing paren' , skip )
3638
3739 # Examples in comments use double quotes.
3840 skip = " getline('.') =~ '\" '"
3941
40- cursor (1 , 1 )
41- lnum = search (' }\s*else' , ' ' , 0 , 0 , skip )
42- ReportError (fname, lnum, ' curly before "else"' )
42+ PerformCheck (fname, ' }\s*else' , ' curly before "else"' , skip )
4343
44- cursor (1 , 1 )
45- lnum = search (' else\s*{' , ' ' , 0 , 0 , skip )
46- ReportError (fname, lnum, ' curly after "else"' )
44+ PerformCheck (fname, ' else\s*{' , ' curly after "else"' , skip )
4745
48- cursor (1 , 1 )
49- lnum = search (' \<\(if\|while\|for\)(' , ' ' , 0 , 0 , skip )
50- ReportError (fname, lnum, ' missing white space after "if"/"while"/"for"' )
46+ PerformCheck (fname, ' \<\(if\|while\|for\)(' , ' missing white space after "if"/"while"/"for"' , skip )
5147 endfor
5248
5349 bwipe!
0 commit comments