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 | |
| 39 | Note that the command is not undone, you may need to reverse the effect for |
| 40 | the next block of lines. |
| 41 | |
| 42 | - Alternatively to indenting all the lines between START_INDENT and |
Bram Moolenaar | ba3ff53 | 2018-11-04 14:45:49 +0100 | [diff] [blame] | 43 | END_INDENT, use an INDENT_AT line, which specifies a pattern to find the |
| 44 | line to indent. Example: |
Bram Moolenaar | c0fe497 | 2018-10-25 16:53:19 +0200 | [diff] [blame] | 45 | |
| 46 | " START_INDENT |
| 47 | " INDENT_AT this-line |
| 48 | func Some() |
| 49 | let f = x " this-line |
| 50 | endfunc |
| 51 | " END_INDENT |
| 52 | |
| 53 | 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] | 54 | pattern. Keep in mind that quite often it will indent relative to the |
| 55 | matching line: |
Bram Moolenaar | c0fe497 | 2018-10-25 16:53:19 +0200 | [diff] [blame] | 56 | |
| 57 | " START_INDENT |
| 58 | " INDENT_NEXT next-line |
| 59 | func Some() |
| 60 | " next-line |
| 61 | let f = x |
| 62 | endfunc |
| 63 | " END_INDENT |
| 64 | |
| 65 | Or use INDENT_PREV to indent the line above the matching pattern: |
| 66 | |
| 67 | " START_INDENT |
| 68 | " INDENT_PREV prev-line |
| 69 | func Some() |
| 70 | let f = x |
| 71 | " prev-line |
| 72 | endfunc |
| 73 | " END_INDENT |
| 74 | |
| 75 | It's best to keep the whole file valid for FILETYPE, so that syntax |
| 76 | highlighting works normally, and any indenting that depends on the syntax |
| 77 | highlighting also works. |
| 78 | |
| 79 | |
| 80 | RUNNING THE TEST |
| 81 | |
| 82 | Before running the test, create a FILETYPE.ok file. You can leave it empty at |
| 83 | first. |
| 84 | |
Bram Moolenaar | 63b74a8 | 2019-03-24 15:09:13 +0100 | [diff] [blame] | 85 | Now run "make test" from the parent directory. After Vim has done the |
| 86 | indenting you will see a FILETYPE.fail file. This contains the actual result |
| 87 | of indenting, and it's different from the FILETYPE.ok file. |
Bram Moolenaar | c0fe497 | 2018-10-25 16:53:19 +0200 | [diff] [blame] | 88 | |
| 89 | Check the contents of the FILETYPE.fail file. If it is perfectly OK, then |
| 90 | rename it to overwrite the FILETYPE.ok file. If you now run "make test" again, |
| 91 | 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] | 92 | FILETYPE.ok file. The FILETYPE.fail file will be deleted. |
Bram Moolenaar | c0fe497 | 2018-10-25 16:53:19 +0200 | [diff] [blame] | 93 | |
| 94 | If you try to run "make test" again you will notice that nothing happens, |
| 95 | because the FILETYPE.out file already exists. Delete it, or do "make clean", |
| 96 | so that the text runs again. If you edit the FILETYPE.in file, so that it's |
| 97 | newer than the FILETYPE.out file, the test will also run. |