Bram Moolenaar | c0fe497 | 2018-10-25 16:53:19 +0200 | [diff] [blame] | 1 | TESTING INDENT SCRIPTS |
| 2 | |
| 3 | We'll use FILETYPE for the filetype name here. |
| 4 | |
| 5 | |
| 6 | FORMAT OF THE FILETYPE.IN FILE |
| 7 | |
| 8 | First of all, create a FILETYPE.in file. It should contain: |
| 9 | |
| 10 | - A modeline setting the 'filetype' and any other option values. |
| 11 | This must work like a comment for FILETYPE. E.g. for vim: |
| 12 | " vim: set ft=vim sw=4 : |
| 13 | |
| 14 | - At least one block of lines to indent, prefixed with START_INDENT and |
| 15 | followed by END_INDENT. These lines must also look like a comment for your |
| 16 | FILETYPE. You would normally leave out all indent, so that the effect of |
| 17 | the indent command results in adding indent. Example: |
| 18 | |
| 19 | " START_INDENT |
| 20 | func Some() |
| 21 | let x = 1 |
| 22 | endfunc |
| 23 | " END_INDENT |
| 24 | |
Bram Moolenaar | ba3ff53 | 2018-11-04 14:45:49 +0100 | [diff] [blame] | 25 | If you just want to test normal indenting with default options, you can make |
| 26 | this a large number of lines. Just add all kinds of language constructs, |
| 27 | nested statements, etc. with valid syntax. |
| 28 | |
| 29 | - Optionally, add lines with INDENT_EXE after START_INDENT, followed by a Vim |
| 30 | command. This will be executed before indenting the lines. Example: |
Bram Moolenaar | c0fe497 | 2018-10-25 16:53:19 +0200 | [diff] [blame] | 31 | |
| 32 | " START_INDENT |
| 33 | " INDENT_EXE let g:vim_indent_cont = 6 |
| 34 | let cmd = |
| 35 | \ 'some ' |
| 36 | \ 'string' |
| 37 | " END_INDENT |
| 38 | |
Aliaksei Budavei | 5ecb452 | 2025-04-13 22:24:46 +0300 | [diff] [blame^] | 39 | When an indent script utilises timed "search*()"es and supports related |
| 40 | timeout configuration, consider setting a generous timeout value from |
| 41 | INDENT_EXE lines (look at "g:vim_indent" in "testdir/vim.in" for details). |
Bram Moolenaar | c0fe497 | 2018-10-25 16:53:19 +0200 | [diff] [blame] | 42 | Note that the command is not undone, you may need to reverse the effect for |
| 43 | the next block of lines. |
| 44 | |
| 45 | - Alternatively to indenting all the lines between START_INDENT and |
Bram Moolenaar | ba3ff53 | 2018-11-04 14:45:49 +0100 | [diff] [blame] | 46 | END_INDENT, use an INDENT_AT line, which specifies a pattern to find the |
| 47 | line to indent. Example: |
Bram Moolenaar | c0fe497 | 2018-10-25 16:53:19 +0200 | [diff] [blame] | 48 | |
| 49 | " START_INDENT |
| 50 | " INDENT_AT this-line |
| 51 | func Some() |
| 52 | let f = x " this-line |
| 53 | endfunc |
| 54 | " END_INDENT |
| 55 | |
| 56 | Alternatively you can use INDENT_NEXT to indent the line below the matching |
Bram Moolenaar | ba3ff53 | 2018-11-04 14:45:49 +0100 | [diff] [blame] | 57 | pattern. Keep in mind that quite often it will indent relative to the |
| 58 | matching line: |
Bram Moolenaar | c0fe497 | 2018-10-25 16:53:19 +0200 | [diff] [blame] | 59 | |
| 60 | " START_INDENT |
| 61 | " INDENT_NEXT next-line |
| 62 | func Some() |
| 63 | " next-line |
| 64 | let f = x |
| 65 | endfunc |
| 66 | " END_INDENT |
| 67 | |
| 68 | Or use INDENT_PREV to indent the line above the matching pattern: |
| 69 | |
| 70 | " START_INDENT |
| 71 | " INDENT_PREV prev-line |
| 72 | func Some() |
| 73 | let f = x |
| 74 | " prev-line |
| 75 | endfunc |
| 76 | " END_INDENT |
| 77 | |
| 78 | It's best to keep the whole file valid for FILETYPE, so that syntax |
| 79 | highlighting works normally, and any indenting that depends on the syntax |
| 80 | highlighting also works. |
| 81 | |
| 82 | |
| 83 | RUNNING THE TEST |
| 84 | |
| 85 | Before running the test, create a FILETYPE.ok file. You can leave it empty at |
| 86 | first. |
| 87 | |
Bram Moolenaar | 63b74a8 | 2019-03-24 15:09:13 +0100 | [diff] [blame] | 88 | Now run "make test" from the parent directory. After Vim has done the |
| 89 | indenting you will see a FILETYPE.fail file. This contains the actual result |
| 90 | of indenting, and it's different from the FILETYPE.ok file. |
Bram Moolenaar | c0fe497 | 2018-10-25 16:53:19 +0200 | [diff] [blame] | 91 | |
| 92 | Check the contents of the FILETYPE.fail file. If it is perfectly OK, then |
| 93 | rename it to overwrite the FILETYPE.ok file. If you now run "make test" again, |
| 94 | the test will pass and create a FILETYPE.out file, which is identical to the |
Bram Moolenaar | ba3ff53 | 2018-11-04 14:45:49 +0100 | [diff] [blame] | 95 | FILETYPE.ok file. The FILETYPE.fail file will be deleted. |
Bram Moolenaar | c0fe497 | 2018-10-25 16:53:19 +0200 | [diff] [blame] | 96 | |
| 97 | If you try to run "make test" again you will notice that nothing happens, |
| 98 | because the FILETYPE.out file already exists. Delete it, or do "make clean", |
| 99 | so that the text runs again. If you edit the FILETYPE.in file, so that it's |
| 100 | newer than the FILETYPE.out file, the test will also run. |