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