blob: 7454210ef03b659f918ed17d5a19b90959feb09e [file] [log] [blame]
Bram Moolenaarc0fe4972018-10-25 16:53:19 +02001TESTING INDENT SCRIPTS
2
3We'll use FILETYPE for the filetype name here.
4
5
6FORMAT OF THE FILETYPE.IN FILE
7
8First 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 Moolenaarba3ff532018-11-04 14:45:49 +010025 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 Moolenaarc0fe4972018-10-25 16:53:19 +020031
32 " START_INDENT
33 " INDENT_EXE let g:vim_indent_cont = 6
34 let cmd =
35 \ 'some '
36 \ 'string'
37 " END_INDENT
38
Aliaksei Budavei5ecb4522025-04-13 22:24:46 +030039 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 Moolenaarc0fe4972018-10-25 16:53:19 +020042 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 Moolenaarba3ff532018-11-04 14:45:49 +010046 END_INDENT, use an INDENT_AT line, which specifies a pattern to find the
47 line to indent. Example:
Bram Moolenaarc0fe4972018-10-25 16:53:19 +020048
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 Moolenaarba3ff532018-11-04 14:45:49 +010057 pattern. Keep in mind that quite often it will indent relative to the
58 matching line:
Bram Moolenaarc0fe4972018-10-25 16:53:19 +020059
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
78It's best to keep the whole file valid for FILETYPE, so that syntax
79highlighting works normally, and any indenting that depends on the syntax
80highlighting also works.
81
82
83RUNNING THE TEST
84
85Before running the test, create a FILETYPE.ok file. You can leave it empty at
86first.
87
Bram Moolenaar63b74a82019-03-24 15:09:13 +010088Now run "make test" from the parent directory. After Vim has done the
89indenting you will see a FILETYPE.fail file. This contains the actual result
90of indenting, and it's different from the FILETYPE.ok file.
Bram Moolenaarc0fe4972018-10-25 16:53:19 +020091
92Check the contents of the FILETYPE.fail file. If it is perfectly OK, then
93rename it to overwrite the FILETYPE.ok file. If you now run "make test" again,
94the test will pass and create a FILETYPE.out file, which is identical to the
Bram Moolenaarba3ff532018-11-04 14:45:49 +010095FILETYPE.ok file. The FILETYPE.fail file will be deleted.
Bram Moolenaarc0fe4972018-10-25 16:53:19 +020096
97If you try to run "make test" again you will notice that nothing happens,
98because the FILETYPE.out file already exists. Delete it, or do "make clean",
99so that the text runs again. If you edit the FILETYPE.in file, so that it's
100newer than the FILETYPE.out file, the test will also run.