/benchmark/app/rdoc-2.4.3/test/test_rdoc_markup.rb

https://github.com/johnbender/rubinius · Ruby · 626 lines · 518 code · 107 blank · 1 comment · 3 complexity · 6e16cc5593af4f04fa7d55ab0f4c7cdb MD5 · raw file

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