Removed obsolete bin scripts.
[rbx.git] / test / rdoc / test_rdoc_markup.rb
blobd88743858a2ee0e96d657a24f69d507d1b02a367
1 require 'test/unit'
2 require 'rdoc/markup'
3 require 'rdoc/markup/to_test'
5 class TestRDocMarkup < Test::Unit::TestCase
7   def basic_conv(str)
8     sm = RDoc::Markup.new
9     mock = RDoc::Markup::ToTest.new
10     sm.convert(str, mock)
11     sm.content
12   end
14   def line_groups(str, expected)
15     m = RDoc::Markup.new
16     mock = RDoc::Markup::ToTest.new
18     block = m.convert(str, mock)
20     if block != expected
21       rows = (0...([expected.size, block.size].max)).collect{|i|
22         [expected[i]||"nil", block[i]||"nil"]
23       }
24       printf "\n\n%35s %35s\n", "Expected", "Got"
25       rows.each {|e,g| printf "%35s %35s\n", e.dump, g.dump }
26     end
28     assert_equal(expected, block)
29   end
31   def line_types(str, expected)
32     m = RDoc::Markup.new
33     mock = RDoc::Markup::ToTest.new
34     m.convert(str, mock)
35     assert_equal(expected, m.get_line_types.map{|type| type.to_s[0,1]}.join(''))
36   end
38   def test_groups
39     str = "now is the time"
40     line_groups(str, ["L0: Paragraph\nnow is the time"] )
42     str = "now is the time\nfor all good men"
43     line_groups(str, ["L0: Paragraph\nnow is the time for all good men"] )
45     str = %{\
46       now is the time
47         code _line_ here
48       for all good men}
50     line_groups(str,
51                 [ "L0: Paragraph\nnow is the time",
52                   "L0: Verbatim\n  code _line_ here\n",
53                   "L0: Paragraph\nfor all good men"
54                 ] )
56     str = "now is the time\n  code\n more code\nfor all good men"
57     line_groups(str,
58                 [ "L0: Paragraph\nnow is the time",
59                   "L0: Verbatim\n  code\n more code\n",
60                   "L0: Paragraph\nfor all good men"
61                 ] )
63     str = %{\
64        now is
65        * l1
66        * l2
67        the time}
68     line_groups(str,
69                 [ "L0: Paragraph\nnow is",
70                   "L1: ListStart\n",
71                   "L1: BULLET ListItem\nl1",
72                   "L1: BULLET ListItem\nl2",
73                   "L1: ListEnd\n",
74                   "L0: Paragraph\nthe time"
75                 ])
77     str = %{\
78        now is
79        * l1
80          l1+
81        * l2
82        the time}
83     line_groups(str,
84                 [ "L0: Paragraph\nnow is",
85                   "L1: ListStart\n",
86                   "L1: BULLET ListItem\nl1 l1+",
87                   "L1: BULLET ListItem\nl2",
88                   "L1: ListEnd\n",
89                   "L0: Paragraph\nthe time"
90                 ])
92     str = %{\
93        now is
94        * l1
95          * l1.1
96        * l2
97        the time}
98     line_groups(str,
99                 [ "L0: Paragraph\nnow is",
100                   "L1: ListStart\n",
101                   "L1: BULLET ListItem\nl1",
102                   "L2: ListStart\n",
103                   "L2: BULLET ListItem\nl1.1",
104                   "L2: ListEnd\n",
105                   "L1: BULLET ListItem\nl2",
106                   "L1: ListEnd\n",
107                   "L0: Paragraph\nthe time"
108                 ])
111     str = %{\
112        now is
113        * l1
114          * l1.1
115            text
116              code
117                code
119            text
120        * l2
121        the time}
122     line_groups(str,
123                 [ "L0: Paragraph\nnow is",
124                   "L1: ListStart\n",
125                   "L1: BULLET ListItem\nl1",
126                   "L2: ListStart\n",
127                   "L2: BULLET ListItem\nl1.1 text",
128                   "L2: Verbatim\n  code\n    code\n",
129                   "L2: Paragraph\ntext",
130                   "L2: ListEnd\n",
131                   "L1: BULLET ListItem\nl2",
132                   "L1: ListEnd\n",
133                   "L0: Paragraph\nthe time"
134                 ])
137     str = %{\
138        now is
139        1. l1
140           * l1.1
141        2. l2
142        the time}
143     line_groups(str,
144                 [ "L0: Paragraph\nnow is",
145                   "L1: ListStart\n",
146                   "L1: NUMBER ListItem\nl1",
147                   "L2: ListStart\n",
148                   "L2: BULLET ListItem\nl1.1",
149                   "L2: ListEnd\n",
150                   "L1: NUMBER ListItem\nl2",
151                   "L1: ListEnd\n",
152                   "L0: Paragraph\nthe time"
153                 ])
155     str = %{\
156        now is
157        [cat] l1
158              * l1.1
159        [dog] l2
160        the time}
161     line_groups(str,
162                 [ "L0: Paragraph\nnow is",
163                   "L1: ListStart\n",
164                   "L1: LABELED ListItem\ncat: l1",
165                   "L2: ListStart\n",
166                   "L2: BULLET ListItem\nl1.1",
167                   "L2: ListEnd\n",
168                   "L1: LABELED ListItem\ndog: l2",
169                   "L1: ListEnd\n",
170                   "L0: Paragraph\nthe time"
171                 ])
173     str = %{\
174        now is
175        [cat] l1
176              continuation
177        [dog] l2
178        the time}
179     line_groups(str,
180                 [ "L0: Paragraph\nnow is",
181                   "L1: ListStart\n",
182                   "L1: LABELED ListItem\ncat: l1 continuation",
183                   "L1: LABELED ListItem\ndog: l2",
184                   "L1: ListEnd\n",
185                   "L0: Paragraph\nthe time"
186                 ])
187   end
189   def test_headings
190     str = "= heading one"
191     line_groups(str,
192                 [ "L0: Heading\nheading one"
193                 ])
195     str = "=== heading three"
196     line_groups(str,
197                 [ "L0: Heading\nheading three"
198                 ])
200     str = "text\n   === heading three"
201     line_groups(str,
202                 [ "L0: Paragraph\ntext",
203                   "L0: Verbatim\n   === heading three\n"
204                 ])
206     str = "text\n   code\n   === heading three"
207     line_groups(str,
208                 [ "L0: Paragraph\ntext",
209                   "L0: Verbatim\n   code\n   === heading three\n"
210                 ])
212     str = "text\n   code\n=== heading three"
213     line_groups(str,
214                 [ "L0: Paragraph\ntext",
215                   "L0: Verbatim\n   code\n",
216                   "L0: Heading\nheading three"
217                 ])
219   end
221   def test_list_alpha
222     str = "a. alpha\nb. baker\nB. ALPHA\nA. BAKER"
224     line_groups(str,
225                 [ "L1: ListStart\n",
226                   "L1: LOWERALPHA ListItem\nalpha",
227                   "L1: LOWERALPHA ListItem\nbaker",
228                   "L1: ListEnd\n",
229                   "L1: ListStart\n",
230                   "L1: UPPERALPHA ListItem\nALPHA",
231                   "L1: UPPERALPHA ListItem\nBAKER",
232                   "L1: ListEnd\n" ])
233   end
235   def test_list_bullet_dash
236     str = "- one\n- two\n"
238     line_groups(str,
239                 [ "L1: ListStart\n",
240                   "L1: BULLET ListItem\none",
241                   "L1: BULLET ListItem\ntwo",
242                   "L1: ListEnd\n" ])
243   end
245   def test_list_bullet_star
246     str = "* one\n* two\n"
248     line_groups(str,
249                 [ "L1: ListStart\n",
250                   "L1: BULLET ListItem\none",
251                   "L1: BULLET ListItem\ntwo",
252                   "L1: ListEnd\n" ])
253   end
255   def test_list_labeled_bracket
256     str = "[one] item one\n[two] item two"
258     line_groups(str,
259                 [ "L1: ListStart\n",
260                   "L1: LABELED ListItem\none: item one",
261                   "L1: LABELED ListItem\ntwo: item two",
262                   "L1: ListEnd\n" ])
263   end
265   def test_list_labeled_bracket_continued
266     str = "[one]\n  item one\n[two]\n  item two"
268     line_groups(str,
269                 [ "L1: ListStart\n",
270                   "L1: LABELED ListItem\none: item one",
271                   "L1: LABELED ListItem\ntwo: item two",
272                   "L1: ListEnd\n" ])
273   end
275   def test_list_labeled_colon
276     str = "one:: item one\ntwo:: item two"
278     line_groups(str,
279                 [ "L1: ListStart\n",
280                   "L1: NOTE ListItem\none:: item one",
281                   "L1: NOTE ListItem\ntwo:: item two",
282                   "L1: ListEnd\n" ])
283   end
285   def test_list_labeled_colon_continued
286     str = "one::\n  item one\ntwo::\n  item two"
288     line_groups(str,
289                 [ "L1: ListStart\n",
290                   "L1: NOTE ListItem\none:: item one",
291                   "L1: NOTE ListItem\ntwo:: item two",
292                   "L1: ListEnd\n" ])
293   end
295   def test_list_nested_bullet_bullet
296     str = "* one\n* two\n  * cat\n  * dog"
298     line_groups(str,
299                 [ "L1: ListStart\n",
300                   "L1: BULLET ListItem\none",
301                   "L1: BULLET ListItem\ntwo",
302                   "L2: ListStart\n",
303                   "L2: BULLET ListItem\ncat",
304                   "L2: BULLET ListItem\ndog",
305                   "L2: ListEnd\n",
306                   "L1: ListEnd\n" ])
307   end
309   def test_list_nested_labeled_bullet
310     str = "[one]\n  * cat\n  * dog"
312     line_groups(str,
313                 [ "L1: ListStart\n",
314                   "L1: LABELED ListItem\none: ",
315                   "L2: ListStart\n",
316                   "L2: BULLET ListItem\ncat",
317                   "L2: BULLET ListItem\ndog",
318                   "L2: ListEnd\n",
319                   "L1: ListEnd\n" ])
320   end
322   def test_list_nested_labeled_bullet_bullet
323     str = "[one]\n  * cat\n    * dog"
325     line_groups(str,
326                 [ "L1: ListStart\n",
327                   "L1: LABELED ListItem\none: ",
328                   "L2: ListStart\n",
329                   "L2: BULLET ListItem\ncat",
330                   "L3: ListStart\n",
331                   "L3: BULLET ListItem\ndog",
332                   "L3: ListEnd\n",
333                   "L2: ListEnd\n",
334                   "L1: ListEnd\n" ])
335   end
337   def test_list_nested_number_number
338     str = "1. one\n1. two\n   1. cat\n   1. dog"
340     line_groups(str,
341                 [ "L1: ListStart\n",
342                   "L1: NUMBER ListItem\none",
343                   "L1: NUMBER ListItem\ntwo",
344                   "L2: ListStart\n",
345                   "L2: NUMBER ListItem\ncat",
346                   "L2: NUMBER ListItem\ndog",
347                   "L2: ListEnd\n",
348                   "L1: ListEnd\n" ])
349   end
351   def test_list_number
352     str = "1. one\n2. two\n1. three"
354     line_groups(str,
355                 [ "L1: ListStart\n",
356                   "L1: NUMBER ListItem\none",
357                   "L1: NUMBER ListItem\ntwo",
358                   "L1: NUMBER ListItem\nthree",
359                   "L1: ListEnd\n" ])
360   end
362   def test_list_split
363     str = %{\
364        now is
365        * l1
366        1. n1
367        2. n2
368        * l2
369        the time}
370     line_groups(str,
371                 [ "L0: Paragraph\nnow is",
372                   "L1: ListStart\n",
373                   "L1: BULLET ListItem\nl1",
374                   "L1: ListEnd\n",
375                   "L1: ListStart\n",
376                   "L1: NUMBER ListItem\nn1",
377                   "L1: NUMBER ListItem\nn2",
378                   "L1: ListEnd\n",
379                   "L1: ListStart\n",
380                   "L1: BULLET ListItem\nl2",
381                   "L1: ListEnd\n",
382                   "L0: Paragraph\nthe time"
383                 ])
385   end
387   def test_paragraph
388     str = "paragraph\n\n*bold* paragraph\n"
390     line_groups str, [
391       "L0: Paragraph\nparagraph",
392       "L0: BlankLine\n",
393       "L0: Paragraph\n*bold* paragraph"
394     ]
395   end
397   def test_tabs
398     str = "hello\n  dave"
399     assert_equal(str, basic_conv(str))
400     str = "hello\n\tdave"
401     assert_equal("hello\n        dave", basic_conv(str))
402     str = "hello\n \tdave"
403     assert_equal("hello\n        dave", basic_conv(str))
404     str = "hello\n  \tdave"
405     assert_equal("hello\n        dave", basic_conv(str))
406     str = "hello\n   \tdave"
407     assert_equal("hello\n        dave", basic_conv(str))
408     str = "hello\n    \tdave"
409     assert_equal("hello\n        dave", basic_conv(str))
410     str = "hello\n     \tdave"
411     assert_equal("hello\n        dave", basic_conv(str))
412     str = "hello\n      \tdave"
413     assert_equal("hello\n        dave", basic_conv(str))
414     str = "hello\n       \tdave"
415     assert_equal("hello\n        dave", basic_conv(str))
416     str = "hello\n        \tdave"
417     assert_equal("hello\n                dave", basic_conv(str))
418     str = ".\t\t."
419     assert_equal(".               .", basic_conv(str))
420   end
422   def test_types
423     str = "now is the time"
424     line_types(str, 'P')
426     str = "now is the time\nfor all good men"
427     line_types(str, 'PP')
429     str = "now is the time\n  code\nfor all good men"
430     line_types(str, 'PVP')
432     str = "now is the time\n  code\n more code\nfor all good men"
433     line_types(str, 'PVVP')
435     str = "now is\n---\nthe time"
436     line_types(str, 'PRP')
438     str = %{\
439        now is
440        * l1
441        * l2
442        the time}
443     line_types(str, 'PLLP')
445     str = %{\
446        now is
447        * l1
448          l1+
449        * l2
450        the time}
451     line_types(str, 'PLPLP')
453     str = %{\
454        now is
455        * l1
456          * l1.1
457        * l2
458        the time}
459     line_types(str, 'PLLLP')
461     str = %{\
462        now is
463        * l1
464          * l1.1
465            text
466              code
467              code
469            text
470        * l2
471        the time}
472     line_types(str, 'PLLPVVBPLP')
474     str = %{\
475        now is
476        1. l1
477           * l1.1
478        2. l2
479        the time}
480     line_types(str, 'PLLLP')
482     str = %{\
483        now is
484        [cat] l1
485              * l1.1
486        [dog] l2
487        the time}
488     line_types(str, 'PLLLP')
490     str = %{\
491        now is
492        [cat] l1
493              continuation
494        [dog] l2
495        the time}
496     line_types(str, 'PLPLP')
497   end
499   def test_verbatim
500     str = "paragraph\n  *bold* verbatim\n"
502     line_groups str, [
503       "L0: Paragraph\nparagraph",
504       "L0: Verbatim\n  *bold* verbatim\n"
505     ]
506   end
508   def test_verbatim_merge
509     str = %{\
510        now is
511           code
512        the time}
514     line_groups(str,
515                 [ "L0: Paragraph\nnow is",
516                   "L0: Verbatim\n   code\n",
517                   "L0: Paragraph\nthe time"
518                 ])
521     str = %{\
522        now is
523           code
524           code1
525        the time}
527     line_groups(str,
528                 [ "L0: Paragraph\nnow is",
529                   "L0: Verbatim\n   code\n   code1\n",
530                   "L0: Paragraph\nthe time"
531                 ])
534     str = %{\
535        now is
536           code
538           code1
539        the time}
541     line_groups(str,
542                 [ "L0: Paragraph\nnow is",
543                   "L0: Verbatim\n   code\n\n   code1\n",
544                   "L0: Paragraph\nthe time"
545                 ])
548     str = %{\
549        now is
550           code
552           code1
554        the time}
556     line_groups(str,
557                 [ "L0: Paragraph\nnow is",
558                   "L0: Verbatim\n   code\n\n   code1\n",
559                   "L0: Paragraph\nthe time"
560                 ])
563     str = %{\
564        now is
565           code
567           code1
569           code2
570        the time}
572     line_groups(str,
573                 [ "L0: Paragraph\nnow is",
574                   "L0: Verbatim\n   code\n\n   code1\n\n   code2\n",
575                   "L0: Paragraph\nthe time"
576                 ])
579     # Folds multiple blank lines
580     str = %{\
581        now is
582           code
585           code1
587        the time}
589     line_groups(str,
590                 [ "L0: Paragraph\nnow is",
591                   "L0: Verbatim\n   code\n\n   code1\n",
592                   "L0: Paragraph\nthe time"
593                 ])
596   end
598   def test_whitespace
599     assert_equal("hello", basic_conv("hello"))
600     assert_equal("hello", basic_conv(" hello "))
601     assert_equal("hello", basic_conv(" \t \t hello\t\t"))
603     assert_equal("1\n 2\n  3", basic_conv("1\n 2\n  3"))
604     assert_equal("1\n 2\n  3", basic_conv("  1\n   2\n    3"))
606     assert_equal("1\n 2\n  3\n1\n 2", basic_conv("1\n 2\n  3\n1\n 2"))
607     assert_equal("1\n 2\n  3\n1\n 2", basic_conv("  1\n   2\n    3\n  1\n   2"))
609     assert_equal("1\n 2\n\n  3", basic_conv("  1\n   2\n\n    3"))
610   end