3 require 'rdoc/markup/to_test'
5 class TestRDocMarkup < Test::Unit::TestCase
9 mock = RDoc::Markup::ToTest.new
14 def line_groups(str, expected)
16 mock = RDoc::Markup::ToTest.new
18 block = m.convert(str, mock)
21 rows = (0...([expected.size, block.size].max)).collect{|i|
22 [expected[i]||"nil", block[i]||"nil"]
24 printf "\n\n%35s %35s\n", "Expected", "Got"
25 rows.each {|e,g| printf "%35s %35s\n", e.dump, g.dump }
28 assert_equal(expected, block)
31 def line_types(str, expected)
33 mock = RDoc::Markup::ToTest.new
35 assert_equal(expected, m.get_line_types.map{|type| type.to_s[0,1]}.join(''))
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"] )
51 [ "L0: Paragraph\nnow is the time",
52 "L0: Verbatim\n code _line_ here\n",
53 "L0: Paragraph\nfor all good men"
56 str = "now is the time\n code\n more code\nfor all good men"
58 [ "L0: Paragraph\nnow is the time",
59 "L0: Verbatim\n code\n more code\n",
60 "L0: Paragraph\nfor all good men"
69 [ "L0: Paragraph\nnow is",
71 "L1: BULLET ListItem\nl1",
72 "L1: BULLET ListItem\nl2",
74 "L0: Paragraph\nthe time"
84 [ "L0: Paragraph\nnow is",
86 "L1: BULLET ListItem\nl1 l1+",
87 "L1: BULLET ListItem\nl2",
89 "L0: Paragraph\nthe time"
99 [ "L0: Paragraph\nnow is",
101 "L1: BULLET ListItem\nl1",
103 "L2: BULLET ListItem\nl1.1",
105 "L1: BULLET ListItem\nl2",
107 "L0: Paragraph\nthe time"
123 [ "L0: Paragraph\nnow is",
125 "L1: BULLET ListItem\nl1",
127 "L2: BULLET ListItem\nl1.1 text",
128 "L2: Verbatim\n code\n code\n",
129 "L2: Paragraph\ntext",
131 "L1: BULLET ListItem\nl2",
133 "L0: Paragraph\nthe time"
144 [ "L0: Paragraph\nnow is",
146 "L1: NUMBER ListItem\nl1",
148 "L2: BULLET ListItem\nl1.1",
150 "L1: NUMBER ListItem\nl2",
152 "L0: Paragraph\nthe time"
162 [ "L0: Paragraph\nnow is",
164 "L1: LABELED ListItem\ncat: l1",
166 "L2: BULLET ListItem\nl1.1",
168 "L1: LABELED ListItem\ndog: l2",
170 "L0: Paragraph\nthe time"
180 [ "L0: Paragraph\nnow is",
182 "L1: LABELED ListItem\ncat: l1 continuation",
183 "L1: LABELED ListItem\ndog: l2",
185 "L0: Paragraph\nthe time"
190 str = "= heading one"
192 [ "L0: Heading\nheading one"
195 str = "=== heading three"
197 [ "L0: Heading\nheading three"
200 str = "text\n === heading three"
202 [ "L0: Paragraph\ntext",
203 "L0: Verbatim\n === heading three\n"
206 str = "text\n code\n === heading three"
208 [ "L0: Paragraph\ntext",
209 "L0: Verbatim\n code\n === heading three\n"
212 str = "text\n code\n=== heading three"
214 [ "L0: Paragraph\ntext",
215 "L0: Verbatim\n code\n",
216 "L0: Heading\nheading three"
222 str = "a. alpha\nb. baker\nB. ALPHA\nA. BAKER"
226 "L1: LOWERALPHA ListItem\nalpha",
227 "L1: LOWERALPHA ListItem\nbaker",
230 "L1: UPPERALPHA ListItem\nALPHA",
231 "L1: UPPERALPHA ListItem\nBAKER",
235 def test_list_bullet_dash
236 str = "- one\n- two\n"
240 "L1: BULLET ListItem\none",
241 "L1: BULLET ListItem\ntwo",
245 def test_list_bullet_star
246 str = "* one\n* two\n"
250 "L1: BULLET ListItem\none",
251 "L1: BULLET ListItem\ntwo",
255 def test_list_labeled_bracket
256 str = "[one] item one\n[two] item two"
260 "L1: LABELED ListItem\none: item one",
261 "L1: LABELED ListItem\ntwo: item two",
265 def test_list_labeled_bracket_continued
266 str = "[one]\n item one\n[two]\n item two"
270 "L1: LABELED ListItem\none: item one",
271 "L1: LABELED ListItem\ntwo: item two",
275 def test_list_labeled_colon
276 str = "one:: item one\ntwo:: item two"
280 "L1: NOTE ListItem\none:: item one",
281 "L1: NOTE ListItem\ntwo:: item two",
285 def test_list_labeled_colon_continued
286 str = "one::\n item one\ntwo::\n item two"
290 "L1: NOTE ListItem\none:: item one",
291 "L1: NOTE ListItem\ntwo:: item two",
295 def test_list_nested_bullet_bullet
296 str = "* one\n* two\n * cat\n * dog"
300 "L1: BULLET ListItem\none",
301 "L1: BULLET ListItem\ntwo",
303 "L2: BULLET ListItem\ncat",
304 "L2: BULLET ListItem\ndog",
309 def test_list_nested_labeled_bullet
310 str = "[one]\n * cat\n * dog"
314 "L1: LABELED ListItem\none: ",
316 "L2: BULLET ListItem\ncat",
317 "L2: BULLET ListItem\ndog",
322 def test_list_nested_labeled_bullet_bullet
323 str = "[one]\n * cat\n * dog"
327 "L1: LABELED ListItem\none: ",
329 "L2: BULLET ListItem\ncat",
331 "L3: BULLET ListItem\ndog",
337 def test_list_nested_number_number
338 str = "1. one\n1. two\n 1. cat\n 1. dog"
342 "L1: NUMBER ListItem\none",
343 "L1: NUMBER ListItem\ntwo",
345 "L2: NUMBER ListItem\ncat",
346 "L2: NUMBER ListItem\ndog",
352 str = "1. one\n2. two\n1. three"
356 "L1: NUMBER ListItem\none",
357 "L1: NUMBER ListItem\ntwo",
358 "L1: NUMBER ListItem\nthree",
371 [ "L0: Paragraph\nnow is",
373 "L1: BULLET ListItem\nl1",
376 "L1: NUMBER ListItem\nn1",
377 "L1: NUMBER ListItem\nn2",
380 "L1: BULLET ListItem\nl2",
382 "L0: Paragraph\nthe time"
388 str = "paragraph\n\n*bold* paragraph\n"
391 "L0: Paragraph\nparagraph",
393 "L0: Paragraph\n*bold* paragraph"
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))
419 assert_equal(". .", basic_conv(str))
423 str = "now is the time"
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')
443 line_types(str, 'PLLP')
451 line_types(str, 'PLPLP')
459 line_types(str, 'PLLLP')
472 line_types(str, 'PLLPVVBPLP')
480 line_types(str, 'PLLLP')
488 line_types(str, 'PLLLP')
496 line_types(str, 'PLPLP')
500 str = "paragraph\n *bold* verbatim\n"
503 "L0: Paragraph\nparagraph",
504 "L0: Verbatim\n *bold* verbatim\n"
508 def test_verbatim_merge
515 [ "L0: Paragraph\nnow is",
516 "L0: Verbatim\n code\n",
517 "L0: Paragraph\nthe time"
528 [ "L0: Paragraph\nnow is",
529 "L0: Verbatim\n code\n code1\n",
530 "L0: Paragraph\nthe time"
542 [ "L0: Paragraph\nnow is",
543 "L0: Verbatim\n code\n\n code1\n",
544 "L0: Paragraph\nthe time"
557 [ "L0: Paragraph\nnow is",
558 "L0: Verbatim\n code\n\n code1\n",
559 "L0: Paragraph\nthe time"
573 [ "L0: Paragraph\nnow is",
574 "L0: Verbatim\n code\n\n code1\n\n code2\n",
575 "L0: Paragraph\nthe time"
579 # Folds multiple blank lines
590 [ "L0: Paragraph\nnow is",
591 "L0: Verbatim\n code\n\n code1\n",
592 "L0: Paragraph\nthe time"
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"))