diff options
author | Bram Moolenaar <Bram@vim.org> | 2023-01-22 21:14:53 +0000 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2023-01-22 21:14:53 +0000 |
commit | ebfec1c531f32d424bb2aca6e7391ef3bfcbfe20 (patch) | |
tree | d017ab5fcc15f2eef851de089c3b2aef39d7a387 /src/testdir | |
parent | 3d79f0a4309995956bd8889940cca22f7a15881d (diff) |
patch 9.0.1234: the code style has to be checked manuallyv9.0.1234
Problem: The code style has to be checked manually.
Solution: Add basic code style checks in a test. Fix or avoid uncovered
problems.
Diffstat (limited to 'src/testdir')
-rw-r--r-- | src/testdir/Make_all.mak | 2 | ||||
-rw-r--r-- | src/testdir/test_codestyle.vim | 45 |
2 files changed, 47 insertions, 0 deletions
diff --git a/src/testdir/Make_all.mak b/src/testdir/Make_all.mak index fdca9f4193..f198217169 100644 --- a/src/testdir/Make_all.mak +++ b/src/testdir/Make_all.mak @@ -97,6 +97,7 @@ NEW_TESTS = \ test_cmdline \ test_cmdmods \ test_cmdwin \ + test_codestyle \ test_command_count \ test_comments \ test_comparators \ @@ -359,6 +360,7 @@ NEW_TESTS_RES = \ test_cmdline.res \ test_cmdmods.res \ test_cmdwin.res \ + test_codestyle.res \ test_command_count.res \ test_comments.res \ test_comparators.res \ diff --git a/src/testdir/test_codestyle.vim b/src/testdir/test_codestyle.vim new file mode 100644 index 0000000000..beb4a6818d --- /dev/null +++ b/src/testdir/test_codestyle.vim @@ -0,0 +1,45 @@ +" Test for checking the source code style. + +def Test_source_files() + for fname in glob('../*.[ch]', 0, 1) + exe 'edit ' .. fname + + cursor(1, 1) + var lnum = search(' \t') + assert_equal(0, lnum, fname .. ': space before tab') + + cursor(1, 1) + lnum = search('\s$') + assert_equal(0, lnum, fname .. ': 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) + assert_equal(0, lnum, fname .. ': curly after closing paren') + + cursor(1, 1) + # Examples in comments use double quotes. + skip = "getline('.') =~ '\"'" + # Avoid examples that contain: "} else + lnum = search('[^"]}\s*else', '', 0, 0, skip) + assert_equal(0, lnum, fname .. ': curly before "else"') + + cursor(1, 1) + lnum = search('else\s*{', '', 0, 0, skip) + assert_equal(0, lnum, fname .. ': curly after "else"') + endfor + + bwipe! +enddef + + +" vim: shiftwidth=2 sts=2 expandtab |