Mercurial > vim
diff runtime/indent/testdir/runtest.vim @ 14970:19b757c6c6a7 v8.1.0496
patch 8.1.0496: no tests for indent files
commit https://github.com/vim/vim/commit/c0fe4978f2311be9a0221d4c2369251c719b399a
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Oct 25 16:53:19 2018 +0200
patch 8.1.0496: no tests for indent files
Problem: No tests for indent files.
Solution: Add a mechanism for running indent file tests. Add a first test
for Vim indenting.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 25 Oct 2018 17:00:07 +0200 |
parents | |
children | 3f82f25df8d2 |
line wrap: on
line diff
new file mode 100644 --- /dev/null +++ b/runtime/indent/testdir/runtest.vim @@ -0,0 +1,117 @@ +" Runs all the indent tests for which there is no .out file + +set nocp +filetype indent on +set nowrapscan + +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 + +qall!