Debian Codegraph @

testsuite/pdfgrep.tests/context.exp

raw
1 # These are tests for the context system (i.e the options -A, -B and -C).
2
3 ######################################################################
4 ####### Context after ###############################################
5 ######################################################################
6
7 set test "Context after"
8
9 clear_pdfdir
10 set pdf [mkpdf lines {
11 line one\\
12 line two\\
13 line three\\
14 line four\\
15 line five\\
16 line six
17 }]
18
19 pdfgrep_expect -A1 "one\|five" $pdf \
20 "line one
21 line two
22 --
23 line five
24 line six"
25
26 ######################################################################
27
28 set test "Context after -- edge case"
29
30 pdfgrep_expect -A1 "six" $pdf \
31 "line six"
32
33 ######################################################################
34
35 set test "Context after -- continuous"
36
37 pdfgrep_expect -A1 "one\|two" $pdf \
38 "line one
39 line two
40 line three"
41
42 ######################################################################
43
44 set test "Context after -- line numbers"
45
46 pdfgrep_expect -nA1 "one\|five" $pdf \
47 "1:line one
48 1-line two
49 --
50 1:line five
51 1-line six"
52
53 ######################################################################
54
55 set test "Context after -- line numbers and filename"
56
57 pdfgrep_expect -nHA1 "one\|five" $pdf \
58 "$pdf:1:line one
59 $pdf-1-line two
60 --
61 $pdf:1:line five
62 $pdf-1-line six"
63
64 ######################################################################
65
66 set test "Context after -- zero context lines"
67
68 pdfgrep_expect -nHA0 "one\|five" $pdf \
69 "$pdf:1:line one
70 --
71 $pdf:1:line five"
72
73 ######################################################################
74
75 set test "Context after -- only matching"
76
77 pdfgrep_expect_with_err -oA1 "one\|five" $pdf \
78 "pdfgrep: warning: .*
79 one
80 five"
81
82 ######################################################################
83
84 set test "Context after -- page breaks"
85
86 set pages [mkpdf pages {
87 page one
88 \newpage
89 page two
90 }]
91
92 pdfgrep_expect -nA2 "page" $pages \
93 "1:page one
94 --
95 2:page two"
96
97 ######################################################################
98
99 set test "Context after -- max-count"
100
101 pdfgrep_expect -A1 -m2 "line" $pdf \
102 "line one
103 line two
104 line three"
105
106 ######################################################################
107
108 set test "Context after -- count"
109
110 pdfgrep_expect -A1 -c "one" $pdf \
111 "1"
112
113 ######################################################################
114
115 set test "Context after -- page count"
116
117 pdfgrep_expect -A1 --page-count "one" $pdf \
118 "1:1"
119
120 ######################################################################
121 ####### Context before ##############################################
122 ######################################################################
123
124 set test "Context before"
125
126 pdfgrep_expect -B1 "two\|six" $pdf \
127 "line one
128 line two
129 --
130 line five
131 line six"
132
133 ######################################################################
134
135 set test "Context before -- edge case"
136
137 pdfgrep_expect -B1 "one" $pdf \
138 "line one"
139
140 ######################################################################
141
142 set test "Context before -- continuous"
143
144 pdfgrep_expect -B1 "two\|three" $pdf \
145 "line one
146 line two
147 line three"
148
149 ######################################################################
150
151 set test "Context before -- line numbers"
152
153 pdfgrep_expect -nB1 "two\|six" $pdf \
154 "1-line one
155 1:line two
156 --
157 1-line five
158 1:line six"
159
160 ######################################################################
161
162 set test "Context before -- line numbers and filename"
163
164 pdfgrep_expect -nHB1 "two\|six" $pdf \
165 "$pdf-1-line one
166 $pdf:1:line two
167 --
168 $pdf-1-line five
169 $pdf:1:line six"
170
171 ######################################################################
172
173 set test "Context before -- zero context lines"
174
175 pdfgrep_expect -nHB0 "two\|six" $pdf \
176 "$pdf:1:line two
177 --
178 $pdf:1:line six"
179
180 ######################################################################
181
182 set test "Context before -- only matching"
183
184 pdfgrep_expect_with_err -oB2 "two\|six" $pdf \
185 "pdfgrep: warning: .*
186 two
187 six"
188
189 ######################################################################
190
191 set test "Context before -- page breaks"
192
193 pdfgrep_expect -nB2 "page" $pages \
194 "1:page one
195 --
196 2:page two"
197
198 ######################################################################
199
200 set test "Context before -- max-count"
201
202 pdfgrep_expect -B1 -m2 "two\|three\|four" $pdf \
203 "line one
204 line two
205 line three"
206
207 ######################################################################
208
209 set test "Context before -- count"
210
211 pdfgrep_expect -B1 -c "one" $pdf \
212 "1"
213
214 ######################################################################
215
216 set test "Context before -- page count"
217
218 pdfgrep_expect -B1 --page-count "one" $pdf \
219 "1:1"
220
221 ######################################################################
222 ####### Context around ##############################################
223 ######################################################################
224
225 set test "Context"
226
227 pdfgrep_expect -C1 "one\|five" $pdf \
228 "line one
229 line two
230 --
231 line four
232 line five
233 line six"
234
235 ######################################################################
236
237 set test "Context -- edge case 1"
238
239 pdfgrep_expect -C1 "one" $pdf \
240 "line one
241 line two"
242
243 ######################################################################
244
245 set test "Context -- edge case 2"
246
247 pdfgrep_expect -C1 "six" $pdf \
248 "line five
249 line six"
250
251 ######################################################################
252
253 set test "Context -- continuous"
254
255 pdfgrep_expect -C1 "two\|four" $pdf \
256 "line one
257 line two
258 line three
259 line four
260 line five"
261
262 ######################################################################
263
264 set test "Context -- line numbers"
265
266 pdfgrep_expect -nC1 "one\|six" $pdf \
267 "1:line one
268 1-line two
269 --
270 1-line five
271 1:line six"
272
273 ######################################################################
274
275 set test "Context -- line numbers and filename"
276
277 pdfgrep_expect -nHC1 "one\|six" $pdf \
278 "$pdf:1:line one
279 $pdf-1-line two
280 --
281 $pdf-1-line five
282 $pdf:1:line six"
283
284 ######################################################################
285
286 set test "Context -- zero context lines"
287
288 pdfgrep_expect -nHC0 "two\|six" $pdf \
289 "$pdf:1:line two
290 --
291 $pdf:1:line six"
292
293 ######################################################################
294
295 set test "Context -- only matching"
296
297 pdfgrep_expect_with_err -oC2 "two\|six" $pdf \
298 "pdfgrep: warning: .*
299 two
300 six"
301
302 ######################################################################
303
304 set test "Context -- page breaks"
305
306 pdfgrep_expect -nC1 "page" $pages \
307 "1:page one
308 --
309 2:page two"
310
311 ######################################################################
312
313 set test "Context -- max-count"
314
315 pdfgrep_expect -C1 -m2 "two\|three\|five" $pdf \
316 "line one
317 line two
318 line three
319 line four"
320
321 ######################################################################
322
323 set test "Context -- count"
324
325 pdfgrep_expect -C1 -c "one" $pdf \
326 "1"
327
328 ######################################################################
329
330 set test "Context -- page count"
331
332 pdfgrep_expect -C1 --page-count "one" $pdf \
333 "1:1"
334
335 ######################################################################
336
337 set test "Context -- exact meeting"
338
339 pdfgrep_expect -A1 -B2 "one\|five" $pdf \
340 "line one
341 line two
342 line three
343 line four
344 line five
345 line six"