1" Runs all the indent tests for which there is no .out file. 2" 3" Current directory must be runtime/indent. 4 5" Only do this with the +eval feature 6if 1 7 8set nocp 9filetype indent on 10set nowrapscan 11set report=9999 12 13au! SwapExists * call HandleSwapExists() 14func HandleSwapExists() 15 " Ignore finding a swap file for the test input and output, the user might be 16 " editing them and that's OK. 17 if expand('<afile>') =~ '.*\.\(in\|out\|fail\|ok\)' 18 let v:swapchoice = 'e' 19 endif 20endfunc 21 22for fname in glob('testdir/*.in', 1, 1) 23 let root = substitute(fname, '\.in', '', '') 24 25 " Execute the test if the .out file does not exist of when the .in file is 26 " newer. 27 let in_time = getftime(fname) 28 let out_time = getftime(root . '.out') 29 if out_time < 0 || in_time > out_time 30 call delete(root . '.fail') 31 call delete(root . '.out') 32 33 set sw& ts& filetype= 34 exe 'split ' . fname 35 36 let did_some = 0 37 let failed = 0 38 let end = 1 39 while 1 40 " Indent all the lines between "START_INDENT" and "END_INDENT" 41 exe end 42 let start = search('\<START_INDENT\>') 43 let end = search('\<END_INDENT\>') 44 if start <= 0 || end <= 0 || end <= start 45 if did_some == 0 46 call append(0, 'ERROR: START_INDENT and/or END_INDENT not found') 47 let failed = 1 48 endif 49 break 50 else 51 let did_some = 1 52 53 " Execute all commands marked with INDENT_EXE and find any pattern. 54 let lnum = start 55 let pattern = '' 56 let at = '' 57 while 1 58 exe lnum + 1 59 let lnum_exe = search('\<INDENT_EXE\>') 60 exe lnum + 1 61 let indent_at = search('\<INDENT_\(AT\|NEXT\|PREV\)\>') 62 if lnum_exe > 0 && lnum_exe < end && (indent_at <= 0 || lnum_exe < indent_at) 63 exe substitute(getline(lnum_exe), '.*INDENT_EXE', '', '') 64 let lnum = lnum_exe 65 let start = lnum 66 elseif indent_at > 0 && indent_at < end 67 if pattern != '' 68 call append(indent_at, 'ERROR: duplicate pattern') 69 let failed = 1 70 break 71 endif 72 let text = getline(indent_at) 73 let pattern = substitute(text, '.*INDENT_\S*\s*', '', '') 74 let at = substitute(text, '.*INDENT_\(\S*\).*', '\1', '') 75 let lnum = indent_at 76 let start = lnum 77 else 78 break 79 endif 80 endwhile 81 82 exe start + 1 83 if pattern == '' 84 exe 'normal =' . (end - 1) . 'G' 85 else 86 let lnum = search(pattern) 87 if lnum <= 0 88 call append(indent_at, 'ERROR: pattern not found: ' . pattern) 89 let failed = 1 90 break 91 endif 92 if at == 'AT' 93 exe lnum 94 elseif at == 'NEXT' 95 exe lnum + 1 96 else 97 exe lnum - 1 98 endif 99 normal == 100 endif 101 endif 102 endwhile 103 104 if !failed 105 " Check the resulting text equals the .ok file. 106 if getline(1, '$') != readfile(root . '.ok') 107 let failed = 1 108 endif 109 endif 110 111 if failed 112 exe 'write ' . root . '.fail' 113 echoerr 'Test ' . fname . ' FAILED!' 114 sleep 2 115 else 116 exe 'write ' . root . '.out' 117 endif 118 119 quit! " close the indented file 120 endif 121endfor 122 123" Matching "if 1" at the start. 124endif 125 126qall! 127