Bram Moolenaar | ebfec1c | 2023-01-22 21:14:53 +0000 | [diff] [blame] | 1 | " Test for checking the source code style. |
| 2 | |
| 3 | def Test_source_files() |
| 4 | for fname in glob('../*.[ch]', 0, 1) |
| 5 | exe 'edit ' .. fname |
| 6 | |
| 7 | cursor(1, 1) |
| 8 | var lnum = search(' \t') |
| 9 | assert_equal(0, lnum, fname .. ': space before tab') |
| 10 | |
| 11 | cursor(1, 1) |
| 12 | lnum = search('\s$') |
| 13 | assert_equal(0, lnum, fname .. ': trailing white space') |
| 14 | |
| 15 | # some files don't stick to the Vim style rules |
| 16 | if fname =~ 'iscygpty.c' |
| 17 | continue |
| 18 | endif |
| 19 | |
| 20 | # Examples in comments use "condition) {", skip them. |
| 21 | # Skip if a double quote or digit comes after the "{". |
| 22 | # Skip specific string used in os_unix.c. |
| 23 | # Also skip fold markers. |
| 24 | var skip = 'getline(".") =~ "condition) {" || getline(".") =~ "vimglob_func" || getline(".") =~ "{\"" || getline(".") =~ "{\\d" || getline(".") =~ "{{{"' |
| 25 | cursor(1, 1) |
| 26 | lnum = search(')\s*{', '', 0, 0, skip) |
| 27 | assert_equal(0, lnum, fname .. ': curly after closing paren') |
| 28 | |
| 29 | cursor(1, 1) |
| 30 | # Examples in comments use double quotes. |
| 31 | skip = "getline('.') =~ '\"'" |
| 32 | # Avoid examples that contain: "} else |
| 33 | lnum = search('[^"]}\s*else', '', 0, 0, skip) |
| 34 | assert_equal(0, lnum, fname .. ': curly before "else"') |
| 35 | |
| 36 | cursor(1, 1) |
| 37 | lnum = search('else\s*{', '', 0, 0, skip) |
| 38 | assert_equal(0, lnum, fname .. ': curly after "else"') |
| 39 | endfor |
| 40 | |
| 41 | bwipe! |
| 42 | enddef |
| 43 | |
| 44 | |
| 45 | " vim: shiftwidth=2 sts=2 expandtab |