summaryrefslogtreecommitdiffstats
path: root/runtime/indent/testdir
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--runtime/indent/testdir/README.txt97
-rw-r--r--runtime/indent/testdir/cleantest.vim11
-rw-r--r--runtime/indent/testdir/html.in26
-rw-r--r--runtime/indent/testdir/html.ok26
-rw-r--r--runtime/indent/testdir/matlab.in80
-rw-r--r--runtime/indent/testdir/matlab.ok80
-rw-r--r--runtime/indent/testdir/runtest.vim126
-rw-r--r--runtime/indent/testdir/tcl.in19
-rw-r--r--runtime/indent/testdir/tcl.ok19
-rw-r--r--runtime/indent/testdir/vim.in46
-rw-r--r--runtime/indent/testdir/vim.ok46
-rw-r--r--runtime/indent/testdir/xml.in32
-rw-r--r--runtime/indent/testdir/xml.ok32
13 files changed, 640 insertions, 0 deletions
diff --git a/runtime/indent/testdir/README.txt b/runtime/indent/testdir/README.txt
new file mode 100644
index 0000000..28c1628
--- /dev/null
+++ b/runtime/indent/testdir/README.txt
@@ -0,0 +1,97 @@
+TESTING INDENT SCRIPTS
+
+We'll use FILETYPE for the filetype name here.
+
+
+FORMAT OF THE FILETYPE.IN FILE
+
+First of all, create a FILETYPE.in file. It should contain:
+
+- A modeline setting the 'filetype' and any other option values.
+ This must work like a comment for FILETYPE. E.g. for vim:
+ " vim: set ft=vim sw=4 :
+
+- At least one block of lines to indent, prefixed with START_INDENT and
+ followed by END_INDENT. These lines must also look like a comment for your
+ FILETYPE. You would normally leave out all indent, so that the effect of
+ the indent command results in adding indent. Example:
+
+ " START_INDENT
+ func Some()
+ let x = 1
+ endfunc
+ " END_INDENT
+
+ If you just want to test normal indenting with default options, you can make
+ this a large number of lines. Just add all kinds of language constructs,
+ nested statements, etc. with valid syntax.
+
+- Optionally, add lines with INDENT_EXE after START_INDENT, followed by a Vim
+ command. This will be executed before indenting the lines. Example:
+
+ " START_INDENT
+ " INDENT_EXE let g:vim_indent_cont = 6
+ let cmd =
+ \ 'some '
+ \ 'string'
+ " END_INDENT
+
+ Note that the command is not undone, you may need to reverse the effect for
+ the next block of lines.
+
+- Alternatively to indenting all the lines between START_INDENT and
+ END_INDENT, use an INDENT_AT line, which specifies a pattern to find the
+ line to indent. Example:
+
+ " START_INDENT
+ " INDENT_AT this-line
+ func Some()
+ let f = x " this-line
+ endfunc
+ " END_INDENT
+
+ Alternatively you can use INDENT_NEXT to indent the line below the matching
+ pattern. Keep in mind that quite often it will indent relative to the
+ matching line:
+
+ " START_INDENT
+ " INDENT_NEXT next-line
+ func Some()
+ " next-line
+ let f = x
+ endfunc
+ " END_INDENT
+
+ Or use INDENT_PREV to indent the line above the matching pattern:
+
+ " START_INDENT
+ " INDENT_PREV prev-line
+ func Some()
+ let f = x
+ " prev-line
+ endfunc
+ " END_INDENT
+
+It's best to keep the whole file valid for FILETYPE, so that syntax
+highlighting works normally, and any indenting that depends on the syntax
+highlighting also works.
+
+
+RUNNING THE TEST
+
+Before running the test, create a FILETYPE.ok file. You can leave it empty at
+first.
+
+Now run "make test". After Vim has done the indenting you will see a
+FILETYPE.fail file. This contains the actual result of indenting, and it's
+different from the FILETYPE.ok file.
+
+Check the contents of the FILETYPE.fail file. If it is perfectly OK, then
+rename it to overwrite the FILETYPE.ok file. If you now run "make test" again,
+the test will pass and create a FILETYPE.out file, which is identical to the
+FILETYPE.ok file. The FILETYPE.fail file will be deleted.
+
+If you try to run "make test" again you will notice that nothing happens,
+because the FILETYPE.out file already exists. Delete it, or do "make clean",
+so that the text runs again. If you edit the FILETYPE.in file, so that it's
+newer than the FILETYPE.out file, the test will also run.
diff --git a/runtime/indent/testdir/cleantest.vim b/runtime/indent/testdir/cleantest.vim
new file mode 100644
index 0000000..69c0a1d
--- /dev/null
+++ b/runtime/indent/testdir/cleantest.vim
@@ -0,0 +1,11 @@
+" Only do this with the +eval feature
+if 1
+
+ " Deletes all the test output files: *.fail and *.out
+ for fname in glob('testdir/*.out', 1, 1) + glob('testdir/*.fail', 1, 1)
+ call delete(fname)
+ endfor
+
+endif
+
+quit
diff --git a/runtime/indent/testdir/html.in b/runtime/indent/testdir/html.in
new file mode 100644
index 0000000..9c776d6
--- /dev/null
+++ b/runtime/indent/testdir/html.in
@@ -0,0 +1,26 @@
+" vim: set ft=html sw=4 :
+
+
+" START_INDENT
+<div>
+<div>
+text
+</div>
+</div>
+
+<div
+class="foo bar">
+text
+</div>
+
+<div class="foo bar"
+data="something">
+text
+</div>
+
+<div class="foo
+bar">
+text
+</div>
+
+" END_INDENT
diff --git a/runtime/indent/testdir/html.ok b/runtime/indent/testdir/html.ok
new file mode 100644
index 0000000..524d57b
--- /dev/null
+++ b/runtime/indent/testdir/html.ok
@@ -0,0 +1,26 @@
+" vim: set ft=html sw=4 :
+
+
+" START_INDENT
+<div>
+ <div>
+ text
+ </div>
+</div>
+
+<div
+ class="foo bar">
+ text
+</div>
+
+<div class="foo bar"
+ data="something">
+ text
+</div>
+
+<div class="foo
+ bar">
+ text
+</div>
+
+" END_INDENT
diff --git a/runtime/indent/testdir/matlab.in b/runtime/indent/testdir/matlab.in
new file mode 100644
index 0000000..5bba1a5
--- /dev/null
+++ b/runtime/indent/testdir/matlab.in
@@ -0,0 +1,80 @@
+% vim: set ft=matlab sw=4 :
+
+% START_INDENT
+if true
+disp foo
+elseif false
+disp bar
+end
+% END_INDENT
+
+% START_INDENT
+try
+statements
+catch exception
+statements
+end
+% END_INDENT
+
+% START_INDENT
+if true, ...
+if true
+disp hello
+end
+end
+% END_INDENT
+
+% START_INDENT
+switch a
+case expr
+if true, foo; end
+disp hello
+otherwise
+disp bar
+end
+% END_INDENT
+
+% START_INDENT
+if true
+A(1:end - 1)
+disp foo
+end
+% END_INDENT
+
+% START_INDENT
+A = [{
+}
+] ...
+disp foo
+disp bar
+% END_INDENT
+
+% START_INDENT
+% INDENT_EXE let b:MATLAB_function_indent = 0
+function foo
+disp foo
+function nested
+disp bar
+end
+end
+% END_INDENT
+
+% START_INDENT
+% INDENT_EXE let b:MATLAB_function_indent = 1
+function foo
+disp foo
+function nested
+disp bar
+end
+end
+% END_INDENT
+
+% START_INDENT
+% INDENT_EXE let b:MATLAB_function_indent = 2
+function foo
+disp foo
+function nested
+disp bar
+end
+end
+% END_INDENT
diff --git a/runtime/indent/testdir/matlab.ok b/runtime/indent/testdir/matlab.ok
new file mode 100644
index 0000000..b111226
--- /dev/null
+++ b/runtime/indent/testdir/matlab.ok
@@ -0,0 +1,80 @@
+% vim: set ft=matlab sw=4 :
+
+% START_INDENT
+if true
+ disp foo
+elseif false
+ disp bar
+end
+% END_INDENT
+
+% START_INDENT
+try
+ statements
+catch exception
+ statements
+end
+% END_INDENT
+
+% START_INDENT
+if true, ...
+ if true
+ disp hello
+ end
+end
+% END_INDENT
+
+% START_INDENT
+switch a
+ case expr
+ if true, foo; end
+ disp hello
+ otherwise
+ disp bar
+end
+% END_INDENT
+
+% START_INDENT
+if true
+ A(1:end - 1)
+ disp foo
+end
+% END_INDENT
+
+% START_INDENT
+A = [{
+ }
+ ] ...
+ disp foo
+disp bar
+% END_INDENT
+
+% START_INDENT
+% INDENT_EXE let b:MATLAB_function_indent = 0
+function foo
+disp foo
+ function nested
+ disp bar
+ end
+end
+% END_INDENT
+
+% START_INDENT
+% INDENT_EXE let b:MATLAB_function_indent = 1
+function foo
+disp foo
+ function nested
+ disp bar
+ end
+end
+% END_INDENT
+
+% START_INDENT
+% INDENT_EXE let b:MATLAB_function_indent = 2
+function foo
+ disp foo
+ function nested
+ disp bar
+ end
+end
+% END_INDENT
diff --git a/runtime/indent/testdir/runtest.vim b/runtime/indent/testdir/runtest.vim
new file mode 100644
index 0000000..2943152
--- /dev/null
+++ b/runtime/indent/testdir/runtest.vim
@@ -0,0 +1,126 @@
+" Runs all the indent tests for which there is no .out file.
+"
+" Current directory must be runtime/indent.
+
+" Only do this with the +eval feature
+if 1
+
+set nocp
+filetype indent on
+set nowrapscan
+set report=9999
+
+au! SwapExists * call HandleSwapExists()
+func HandleSwapExists()
+ " Ignore finding a swap file for the test input and output, the user might be
+ " editing them and that's OK.
+ if expand('<afile>') =~ '.*\.\(in\|out\|fail\|ok\)'
+ let v:swapchoice = 'e'
+ endif
+endfunc
+
+for fname in glob('testdir/*.in', 1, 1)
+ let root = substitute(fname, '\.in', '', '')
+
+ " Execute the test if the .out file does not exist of when the .in file is
+ " newer.
+ let in_time = getftime(fname)
+ let out_time = getftime(root . '.out')
+ if out_time < 0 || in_time > out_time
+ call delete(root . '.fail')
+ call delete(root . '.out')
+
+ set sw& ts& filetype=
+ exe 'split ' . fname
+
+ let did_some = 0
+ let failed = 0
+ let end = 1
+ while 1
+ " Indent all the lines between "START_INDENT" and "END_INDENT"
+ exe end
+ let start = search('\<START_INDENT\>')
+ let end = search('\<END_INDENT\>')
+ if start <= 0 || end <= 0 || end <= start
+ if did_some == 0
+ call append(0, 'ERROR: START_INDENT and/or END_INDENT not found')
+ let failed = 1
+ endif
+ break
+ else
+ let did_some = 1
+
+ " Execute all commands marked with INDENT_EXE and find any pattern.
+ let lnum = start
+ let pattern = ''
+ let at = ''
+ while 1
+ exe lnum + 1
+ let lnum_exe = search('\<INDENT_EXE\>')
+ exe lnum + 1
+ let indent_at = search('\<INDENT_\(AT\|NEXT\|PREV\)\>')
+ if lnum_exe > 0 && lnum_exe < end && (indent_at <= 0 || lnum_exe < indent_at)
+ exe substitute(getline(lnum_exe), '.*INDENT_EXE', '', '')
+ let lnum = lnum_exe
+ let start = lnum
+ elseif indent_at > 0 && indent_at < end
+ if pattern != ''
+ call append(indent_at, 'ERROR: duplicate pattern')
+ let failed = 1
+ break
+ endif
+ let text = getline(indent_at)
+ let pattern = substitute(text, '.*INDENT_\S*\s*', '', '')
+ let at = substitute(text, '.*INDENT_\(\S*\).*', '\1', '')
+ let lnum = indent_at
+ let start = lnum
+ else
+ break
+ endif
+ endwhile
+
+ exe start + 1
+ if pattern == ''
+ exe 'normal =' . (end - 1) . 'G'
+ else
+ let lnum = search(pattern)
+ if lnum <= 0
+ call append(indent_at, 'ERROR: pattern not found: ' . pattern)
+ let failed = 1
+ break
+ endif
+ if at == 'AT'
+ exe lnum
+ elseif at == 'NEXT'
+ exe lnum + 1
+ else
+ exe lnum - 1
+ endif
+ normal ==
+ endif
+ endif
+ endwhile
+
+ if !failed
+ " Check the resulting text equals the .ok file.
+ if getline(1, '$') != readfile(root . '.ok')
+ let failed = 1
+ endif
+ endif
+
+ if failed
+ exe 'write ' . root . '.fail'
+ echoerr 'Test ' . fname . ' FAILED!'
+ sleep 2
+ else
+ exe 'write ' . root . '.out'
+ endif
+
+ quit! " close the indented file
+ endif
+endfor
+
+" Matching "if 1" at the start.
+endif
+
+qall!
diff --git a/runtime/indent/testdir/tcl.in b/runtime/indent/testdir/tcl.in
new file mode 100644
index 0000000..c769d5b
--- /dev/null
+++ b/runtime/indent/testdir/tcl.in
@@ -0,0 +1,19 @@
+# vim: set filetype=tcl shiftwidth=4 tabstop=8 expandtab :
+
+# START_INDENT
+proc abc {} {
+set a 5
+if {[some_cmd]==1} {
+foreach i [list {1 2 3}] {
+# Does this comment affect anything?
+puts $i
+}
+}
+}
+
+command_with_a_long_time -arg1 "First" \
+-arg2 "Second" \
+-arg3 "Third"
+
+puts "Move indent back after line continuation is complete"
+# END_INDENT \ No newline at end of file
diff --git a/runtime/indent/testdir/tcl.ok b/runtime/indent/testdir/tcl.ok
new file mode 100644
index 0000000..77f24e9
--- /dev/null
+++ b/runtime/indent/testdir/tcl.ok
@@ -0,0 +1,19 @@
+# vim: set filetype=tcl shiftwidth=4 tabstop=8 expandtab :
+
+# START_INDENT
+proc abc {} {
+ set a 5
+ if {[some_cmd]==1} {
+ foreach i [list {1 2 3}] {
+ # Does this comment affect anything?
+ puts $i
+ }
+ }
+}
+
+command_with_a_long_time -arg1 "First" \
+ -arg2 "Second" \
+ -arg3 "Third"
+
+puts "Move indent back after line continuation is complete"
+# END_INDENT
diff --git a/runtime/indent/testdir/vim.in b/runtime/indent/testdir/vim.in
new file mode 100644
index 0000000..ca105f6
--- /dev/null
+++ b/runtime/indent/testdir/vim.in
@@ -0,0 +1,46 @@
+" vim: set ft=vim sw=4 :
+
+" START_INDENT
+
+func Some()
+let x = 1
+endfunc
+
+let cmd =
+\ 'some '
+\ 'string'
+
+" END_INDENT
+
+" START_INDENT
+" INDENT_EXE let g:vim_indent_cont = 6
+
+let cmd =
+\ 'some '
+\ 'string'
+
+" END_INDENT
+
+" START_INDENT
+" INDENT_EXE unlet g:vim_indent_cont
+" INDENT_AT this-line
+func Some()
+let f = x " this-line
+endfunc
+" END_INDENT
+
+" START_INDENT
+" INDENT_NEXT next-line
+func Some()
+ " next-line
+let f = x
+endfunc
+" END_INDENT
+
+" START_INDENT
+" INDENT_PREV prev-line
+func Some()
+let f = x
+" prev-line
+endfunc
+" END_INDENT
diff --git a/runtime/indent/testdir/vim.ok b/runtime/indent/testdir/vim.ok
new file mode 100644
index 0000000..542861e
--- /dev/null
+++ b/runtime/indent/testdir/vim.ok
@@ -0,0 +1,46 @@
+" vim: set ft=vim sw=4 :
+
+" START_INDENT
+
+func Some()
+ let x = 1
+endfunc
+
+let cmd =
+ \ 'some '
+ \ 'string'
+
+" END_INDENT
+
+" START_INDENT
+" INDENT_EXE let g:vim_indent_cont = 6
+
+let cmd =
+ \ 'some '
+ \ 'string'
+
+" END_INDENT
+
+" START_INDENT
+" INDENT_EXE unlet g:vim_indent_cont
+" INDENT_AT this-line
+func Some()
+ let f = x " this-line
+endfunc
+" END_INDENT
+
+" START_INDENT
+" INDENT_NEXT next-line
+func Some()
+ " next-line
+ let f = x
+endfunc
+" END_INDENT
+
+" START_INDENT
+" INDENT_PREV prev-line
+func Some()
+ let f = x
+" prev-line
+endfunc
+" END_INDENT
diff --git a/runtime/indent/testdir/xml.in b/runtime/indent/testdir/xml.in
new file mode 100644
index 0000000..b633334
--- /dev/null
+++ b/runtime/indent/testdir/xml.in
@@ -0,0 +1,32 @@
+<!-- vim: set ft=xml ts=8 sw=0 sts=-1 et : -->
+<!-- START_INDENT -->
+<?xml version="1.0" encoding="utf-8"?>
+<tag0>
+ <tag1>
+<!-- comment -->
+<tag2>
+ <tag3/>
+</tag2>
+<!-- text comment -->
+
+<!--
+text comment
+-->
+</tag1>
+<!--
+text comment
+end coment -->
+</tag0>
+<!-- END_INDENT -->
+
+<!-- START_INDENT -->
+<?xml version="1.0" encoding="utf-8"?>
+<tag0>
+ <tag1>
+<!-- comment -->
+<tag2>
+ <tag3/>
+</tag2>
+</tag1>
+</tag0>
+<!-- END_INDENT -->
diff --git a/runtime/indent/testdir/xml.ok b/runtime/indent/testdir/xml.ok
new file mode 100644
index 0000000..5291985
--- /dev/null
+++ b/runtime/indent/testdir/xml.ok
@@ -0,0 +1,32 @@
+<!-- vim: set ft=xml ts=8 sw=0 sts=-1 et : -->
+<!-- START_INDENT -->
+<?xml version="1.0" encoding="utf-8"?>
+<tag0>
+ <tag1>
+ <!-- comment -->
+ <tag2>
+ <tag3/>
+ </tag2>
+ <!-- text comment -->
+
+ <!--
+ text comment
+ -->
+ </tag1>
+ <!--
+ text comment
+ end coment -->
+</tag0>
+<!-- END_INDENT -->
+
+<!-- START_INDENT -->
+<?xml version="1.0" encoding="utf-8"?>
+<tag0>
+ <tag1>
+ <!-- comment -->
+ <tag2>
+ <tag3/>
+ </tag2>
+ </tag1>
+</tag0>
+<!-- END_INDENT -->