source: extensions/gsdl-video/trunk/installed/cmdline/lib/ruby/1.8/rdoc/markup/test/TestParse.rb@ 18425

Last change on this file since 18425 was 18425, checked in by davidb, 15 years ago

Video extension to Greenstone

File size: 11.2 KB
Line 
1require 'test/unit'
2
3$:.unshift "../../.."
4
5require 'rdoc/markup/simple_markup'
6
7include SM
8
9class TestParse < Test::Unit::TestCase
10
11 class MockOutput
12 def start_accepting
13 @res = []
14 end
15
16 def end_accepting
17 @res
18 end
19
20 def accept_paragraph(am, fragment)
21 @res << fragment.to_s
22 end
23
24 def accept_verbatim(am, fragment)
25 @res << fragment.to_s
26 end
27
28 def accept_list_start(am, fragment)
29 @res << fragment.to_s
30 end
31
32 def accept_list_end(am, fragment)
33 @res << fragment.to_s
34 end
35
36 def accept_list_item(am, fragment)
37 @res << fragment.to_s
38 end
39
40 def accept_blank_line(am, fragment)
41 @res << fragment.to_s
42 end
43
44 def accept_heading(am, fragment)
45 @res << fragment.to_s
46 end
47
48 def accept_rule(am, fragment)
49 @res << fragment.to_s
50 end
51
52 end
53
54 def basic_conv(str)
55 sm = SimpleMarkup.new
56 mock = MockOutput.new
57 sm.convert(str, mock)
58 sm.content
59 end
60
61 def line_types(str, expected)
62 p = SimpleMarkup.new
63 mock = MockOutput.new
64 p.convert(str, mock)
65 assert_equal(expected, p.get_line_types.map{|type| type.to_s[0,1]}.join(''))
66 end
67
68 def line_groups(str, expected)
69 p = SimpleMarkup.new
70 mock = MockOutput.new
71
72 block = p.convert(str, mock)
73
74 if block != expected
75 rows = (0...([expected.size, block.size].max)).collect{|i|
76 [expected[i]||"nil", block[i]||"nil"]
77 }
78 printf "\n\n%35s %35s\n", "Expected", "Got"
79 rows.each {|e,g| printf "%35s %35s\n", e.dump, g.dump }
80 end
81
82 assert_equal(expected, block)
83 end
84
85 def test_tabs
86 str = "hello\n dave"
87 assert_equal(str, basic_conv(str))
88 str = "hello\n\tdave"
89 assert_equal("hello\n dave", basic_conv(str))
90 str = "hello\n \tdave"
91 assert_equal("hello\n dave", basic_conv(str))
92 str = "hello\n \tdave"
93 assert_equal("hello\n dave", basic_conv(str))
94 str = "hello\n \tdave"
95 assert_equal("hello\n dave", basic_conv(str))
96 str = "hello\n \tdave"
97 assert_equal("hello\n dave", basic_conv(str))
98 str = "hello\n \tdave"
99 assert_equal("hello\n dave", basic_conv(str))
100 str = "hello\n \tdave"
101 assert_equal("hello\n dave", basic_conv(str))
102 str = "hello\n \tdave"
103 assert_equal("hello\n dave", basic_conv(str))
104 str = "hello\n \tdave"
105 assert_equal("hello\n dave", basic_conv(str))
106 str = ".\t\t."
107 assert_equal(". .", basic_conv(str))
108 end
109
110 def test_whitespace
111 assert_equal("hello", basic_conv("hello"))
112 assert_equal("hello", basic_conv(" hello "))
113 assert_equal("hello", basic_conv(" \t \t hello\t\t"))
114
115 assert_equal("1\n 2\n 3", basic_conv("1\n 2\n 3"))
116 assert_equal("1\n 2\n 3", basic_conv(" 1\n 2\n 3"))
117
118 assert_equal("1\n 2\n 3\n1\n 2", basic_conv("1\n 2\n 3\n1\n 2"))
119 assert_equal("1\n 2\n 3\n1\n 2", basic_conv(" 1\n 2\n 3\n 1\n 2"))
120
121 assert_equal("1\n 2\n\n 3", basic_conv(" 1\n 2\n\n 3"))
122 end
123
124 def test_types
125 str = "now is the time"
126 line_types(str, 'P')
127
128 str = "now is the time\nfor all good men"
129 line_types(str, 'PP')
130
131 str = "now is the time\n code\nfor all good men"
132 line_types(str, 'PVP')
133
134 str = "now is the time\n code\n more code\nfor all good men"
135 line_types(str, 'PVVP')
136
137 str = "now is\n---\nthe time"
138 line_types(str, 'PRP')
139
140 str = %{\
141 now is
142 * l1
143 * l2
144 the time}
145 line_types(str, 'PLLP')
146
147 str = %{\
148 now is
149 * l1
150 l1+
151 * l2
152 the time}
153 line_types(str, 'PLPLP')
154
155 str = %{\
156 now is
157 * l1
158 * l1.1
159 * l2
160 the time}
161 line_types(str, 'PLLLP')
162
163 str = %{\
164 now is
165 * l1
166 * l1.1
167 text
168 code
169 code
170
171 text
172 * l2
173 the time}
174 line_types(str, 'PLLPVVBPLP')
175
176 str = %{\
177 now is
178 1. l1
179 * l1.1
180 2. l2
181 the time}
182 line_types(str, 'PLLLP')
183
184 str = %{\
185 now is
186 [cat] l1
187 * l1.1
188 [dog] l2
189 the time}
190 line_types(str, 'PLLLP')
191
192 str = %{\
193 now is
194 [cat] l1
195 continuation
196 [dog] l2
197 the time}
198 line_types(str, 'PLPLP')
199 end
200
201 def test_groups
202 str = "now is the time"
203 line_groups(str, ["L0: Paragraph\nnow is the time"] )
204
205 str = "now is the time\nfor all good men"
206 line_groups(str, ["L0: Paragraph\nnow is the time for all good men"] )
207
208 str = %{\
209 now is the time
210 code _line_ here
211 for all good men}
212
213 line_groups(str,
214 [ "L0: Paragraph\nnow is the time",
215 "L0: Verbatim\n code _line_ here\n",
216 "L0: Paragraph\nfor all good men"
217 ] )
218
219 str = "now is the time\n code\n more code\nfor all good men"
220 line_groups(str,
221 [ "L0: Paragraph\nnow is the time",
222 "L0: Verbatim\n code\n more code\n",
223 "L0: Paragraph\nfor all good men"
224 ] )
225
226 str = %{\
227 now is
228 * l1
229 * l2
230 the time}
231 line_groups(str,
232 [ "L0: Paragraph\nnow is",
233 "L1: ListStart\n",
234 "L1: ListItem\nl1",
235 "L1: ListItem\nl2",
236 "L1: ListEnd\n",
237 "L0: Paragraph\nthe time"
238 ])
239
240 str = %{\
241 now is
242 * l1
243 l1+
244 * l2
245 the time}
246 line_groups(str,
247 [ "L0: Paragraph\nnow is",
248 "L1: ListStart\n",
249 "L1: ListItem\nl1 l1+",
250 "L1: ListItem\nl2",
251 "L1: ListEnd\n",
252 "L0: Paragraph\nthe time"
253 ])
254
255 str = %{\
256 now is
257 * l1
258 * l1.1
259 * l2
260 the time}
261 line_groups(str,
262 [ "L0: Paragraph\nnow is",
263 "L1: ListStart\n",
264 "L1: ListItem\nl1",
265 "L2: ListStart\n",
266 "L2: ListItem\nl1.1",
267 "L2: ListEnd\n",
268 "L1: ListItem\nl2",
269 "L1: ListEnd\n",
270 "L0: Paragraph\nthe time"
271 ])
272
273
274 str = %{\
275 now is
276 * l1
277 * l1.1
278 text
279 code
280 code
281
282 text
283 * l2
284 the time}
285 line_groups(str,
286 [ "L0: Paragraph\nnow is",
287 "L1: ListStart\n",
288 "L1: ListItem\nl1",
289 "L2: ListStart\n",
290 "L2: ListItem\nl1.1 text",
291 "L2: Verbatim\n code\n code\n",
292 "L2: Paragraph\ntext",
293 "L2: ListEnd\n",
294 "L1: ListItem\nl2",
295 "L1: ListEnd\n",
296 "L0: Paragraph\nthe time"
297 ])
298
299
300 str = %{\
301 now is
302 1. l1
303 * l1.1
304 2. l2
305 the time}
306 line_groups(str,
307 [ "L0: Paragraph\nnow is",
308 "L1: ListStart\n",
309 "L1: ListItem\nl1",
310 "L2: ListStart\n",
311 "L2: ListItem\nl1.1",
312 "L2: ListEnd\n",
313 "L1: ListItem\nl2",
314 "L1: ListEnd\n",
315 "L0: Paragraph\nthe time"
316 ])
317
318 str = %{\
319 now is
320 [cat] l1
321 * l1.1
322 [dog] l2
323 the time}
324 line_groups(str,
325 [ "L0: Paragraph\nnow is",
326 "L1: ListStart\n",
327 "L1: ListItem\nl1",
328 "L2: ListStart\n",
329 "L2: ListItem\nl1.1",
330 "L2: ListEnd\n",
331 "L1: ListItem\nl2",
332 "L1: ListEnd\n",
333 "L0: Paragraph\nthe time"
334 ])
335
336 str = %{\
337 now is
338 [cat] l1
339 continuation
340 [dog] l2
341 the time}
342 line_groups(str,
343 [ "L0: Paragraph\nnow is",
344 "L1: ListStart\n",
345 "L1: ListItem\nl1 continuation",
346 "L1: ListItem\nl2",
347 "L1: ListEnd\n",
348 "L0: Paragraph\nthe time"
349 ])
350
351
352 end
353
354 def test_verbatim_merge
355 str = %{\
356 now is
357 code
358 the time}
359
360 line_groups(str,
361 [ "L0: Paragraph\nnow is",
362 "L0: Verbatim\n code\n",
363 "L0: Paragraph\nthe time"
364 ])
365
366
367 str = %{\
368 now is
369 code
370 code1
371 the time}
372
373 line_groups(str,
374 [ "L0: Paragraph\nnow is",
375 "L0: Verbatim\n code\n code1\n",
376 "L0: Paragraph\nthe time"
377 ])
378
379
380 str = %{\
381 now is
382 code
383
384 code1
385 the time}
386
387 line_groups(str,
388 [ "L0: Paragraph\nnow is",
389 "L0: Verbatim\n code\n\n code1\n",
390 "L0: Paragraph\nthe time"
391 ])
392
393
394 str = %{\
395 now is
396 code
397
398 code1
399
400 the time}
401
402 line_groups(str,
403 [ "L0: Paragraph\nnow is",
404 "L0: Verbatim\n code\n\n code1\n",
405 "L0: Paragraph\nthe time"
406 ])
407
408
409 str = %{\
410 now is
411 code
412
413 code1
414
415 code2
416 the time}
417
418 line_groups(str,
419 [ "L0: Paragraph\nnow is",
420 "L0: Verbatim\n code\n\n code1\n\n code2\n",
421 "L0: Paragraph\nthe time"
422 ])
423
424
425 # Folds multiple blank lines
426 str = %{\
427 now is
428 code
429
430
431 code1
432
433 the time}
434
435 line_groups(str,
436 [ "L0: Paragraph\nnow is",
437 "L0: Verbatim\n code\n\n code1\n",
438 "L0: Paragraph\nthe time"
439 ])
440
441
442 end
443
444 def test_list_split
445 str = %{\
446 now is
447 * l1
448 1. n1
449 2. n2
450 * l2
451 the time}
452 line_groups(str,
453 [ "L0: Paragraph\nnow is",
454 "L1: ListStart\n",
455 "L1: ListItem\nl1",
456 "L1: ListEnd\n",
457 "L1: ListStart\n",
458 "L1: ListItem\nn1",
459 "L1: ListItem\nn2",
460 "L1: ListEnd\n",
461 "L1: ListStart\n",
462 "L1: ListItem\nl2",
463 "L1: ListEnd\n",
464 "L0: Paragraph\nthe time"
465 ])
466
467 end
468
469
470 def test_headings
471 str = "= heading one"
472 line_groups(str,
473 [ "L0: Heading\nheading one"
474 ])
475
476 str = "=== heading three"
477 line_groups(str,
478 [ "L0: Heading\nheading three"
479 ])
480
481 str = "text\n === heading three"
482 line_groups(str,
483 [ "L0: Paragraph\ntext",
484 "L0: Verbatim\n === heading three\n"
485 ])
486
487 str = "text\n code\n === heading three"
488 line_groups(str,
489 [ "L0: Paragraph\ntext",
490 "L0: Verbatim\n code\n === heading three\n"
491 ])
492
493 str = "text\n code\n=== heading three"
494 line_groups(str,
495 [ "L0: Paragraph\ntext",
496 "L0: Verbatim\n code\n",
497 "L0: Heading\nheading three"
498 ])
499
500 end
501
502
503end
Note: See TracBrowser for help on using the repository browser.