PageRenderTime 27ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/training-web/vendor/bundle/gems/rdoc-3.12.2/lib/rdoc/markup/formatter_test_case.rb

https://bitbucket.org/ohimmelreich/asalia-training
Ruby | 698 lines | 320 code | 228 blank | 150 comment | 0 complexity | a9c017e1a7c40321b5f1f661aea9d010 MD5 | raw file
  1. require 'minitest/unit'
  2. ##
  3. # Test case for creating new RDoc::Markup formatters. See
  4. # test/test_rdoc_markup_to_*.rb for examples.
  5. #
  6. # This test case adds a variety of tests to your subclass when
  7. # #add_visitor_tests is called. Most tests set up a scenario then call a
  8. # method you will provide to perform the assertion on the output.
  9. #
  10. # Your subclass must instantiate a visitor and assign it to <tt>@to</tt>.
  11. #
  12. # For example, test_accept_blank_line sets up a RDoc::Markup::BlockLine then
  13. # calls accept_blank_line on your visitor. You are responsible for asserting
  14. # that the output is correct.
  15. #
  16. # Example:
  17. #
  18. # class TestRDocMarkupToNewFormat < RDoc::Markup::FormatterTestCase
  19. #
  20. # add_visitor_tests
  21. #
  22. # def setup
  23. # super
  24. #
  25. # @to = RDoc::Markup::ToNewFormat.new
  26. # end
  27. #
  28. # def accept_blank_line
  29. # assert_equal :junk, @to.res.join
  30. # end
  31. #
  32. # # ...
  33. #
  34. # end
  35. class RDoc::Markup::FormatterTestCase < MiniTest::Unit::TestCase
  36. ##
  37. # Call #setup when inheriting from this test case.
  38. #
  39. # Provides the following instance variables:
  40. #
  41. # +@m+:: RDoc::Markup.new
  42. # +@RM+:: RDoc::Markup # to reduce typing
  43. # +@bullet_list+:: @RM::List.new :BULLET, # ...
  44. # +@label_list+:: @RM::List.new :LABEL, # ...
  45. # +@lalpha_list+:: @RM::List.new :LALPHA, # ...
  46. # +@note_list+:: @RM::List.new :NOTE, # ...
  47. # +@number_list+:: @RM::List.new :NUMBER, # ...
  48. # +@ualpha_list+:: @RM::List.new :UALPHA, # ...
  49. def setup
  50. super
  51. @RM = RDoc::Markup
  52. @m = @RM.new
  53. @bullet_list = @RM::List.new(:BULLET,
  54. @RM::ListItem.new(nil, @RM::Paragraph.new('l1')),
  55. @RM::ListItem.new(nil, @RM::Paragraph.new('l2')))
  56. @label_list = @RM::List.new(:LABEL,
  57. @RM::ListItem.new('cat', @RM::Paragraph.new('cats are cool')),
  58. @RM::ListItem.new('dog', @RM::Paragraph.new('dogs are cool too')))
  59. @lalpha_list = @RM::List.new(:LALPHA,
  60. @RM::ListItem.new(nil, @RM::Paragraph.new('l1')),
  61. @RM::ListItem.new(nil, @RM::Paragraph.new('l2')))
  62. @note_list = @RM::List.new(:NOTE,
  63. @RM::ListItem.new('cat', @RM::Paragraph.new('cats are cool')),
  64. @RM::ListItem.new('dog', @RM::Paragraph.new('dogs are cool too')))
  65. @number_list = @RM::List.new(:NUMBER,
  66. @RM::ListItem.new(nil, @RM::Paragraph.new('l1')),
  67. @RM::ListItem.new(nil, @RM::Paragraph.new('l2')))
  68. @ualpha_list = @RM::List.new(:UALPHA,
  69. @RM::ListItem.new(nil, @RM::Paragraph.new('l1')),
  70. @RM::ListItem.new(nil, @RM::Paragraph.new('l2')))
  71. end
  72. ##
  73. # Call to add the visitor tests to your test case
  74. def self.add_visitor_tests
  75. self.class_eval do
  76. ##
  77. # Calls start_accepting which needs to verify startup state
  78. def test_start_accepting
  79. @to.start_accepting
  80. start_accepting
  81. end
  82. ##
  83. # Calls end_accepting on your test case which needs to call
  84. # <tt>@to.end_accepting</tt> and verify document generation
  85. def test_end_accepting
  86. @to.start_accepting
  87. @to.res << 'hi'
  88. end_accepting
  89. end
  90. ##
  91. # Calls accept_blank_line
  92. def test_accept_blank_line
  93. @to.start_accepting
  94. @to.accept_blank_line @RM::BlankLine.new
  95. accept_blank_line
  96. end
  97. ##
  98. # Test case that calls <tt>@to.accept_document</tt>
  99. def test_accept_document
  100. @to.start_accepting
  101. @to.accept_document @RM::Document.new @RM::Paragraph.new 'hello'
  102. accept_document
  103. end
  104. ##
  105. # Calls accept_heading with a level 5 RDoc::Markup::Heading
  106. def test_accept_heading
  107. @to.start_accepting
  108. @to.accept_heading @RM::Heading.new(5, 'Hello')
  109. accept_heading
  110. end
  111. ##
  112. # Calls accept_heading_1 with a level 1 RDoc::Markup::Heading
  113. def test_accept_heading_1
  114. @to.start_accepting
  115. @to.accept_heading @RM::Heading.new(1, 'Hello')
  116. accept_heading_1
  117. end
  118. ##
  119. # Calls accept_heading_2 with a level 2 RDoc::Markup::Heading
  120. def test_accept_heading_2
  121. @to.start_accepting
  122. @to.accept_heading @RM::Heading.new(2, 'Hello')
  123. accept_heading_2
  124. end
  125. ##
  126. # Calls accept_heading_3 with a level 3 RDoc::Markup::Heading
  127. def test_accept_heading_3
  128. # HACK this doesn't belong here
  129. skip "No String#chars, upgrade your ruby" unless ''.respond_to? :chars
  130. @to.start_accepting
  131. @to.accept_heading @RM::Heading.new(3, 'Hello')
  132. accept_heading_3
  133. end
  134. ##
  135. # Calls accept_heading_4 with a level 4 RDoc::Markup::Heading
  136. def test_accept_heading_4
  137. @to.start_accepting
  138. @to.accept_heading @RM::Heading.new(4, 'Hello')
  139. accept_heading_4
  140. end
  141. ##
  142. # Calls accept_heading_b with a bold level 1 RDoc::Markup::Heading
  143. def test_accept_heading_b
  144. @to.start_accepting
  145. @to.accept_heading @RM::Heading.new(1, '*Hello*')
  146. accept_heading_b
  147. end
  148. ##
  149. # Calls accept_heading_suppressed_crossref with a level 1
  150. # RDoc::Markup::Heading containing a suppressed crossref
  151. def test_accept_heading_suppressed_crossref # HACK to_html_crossref test
  152. @to.start_accepting
  153. @to.accept_heading @RM::Heading.new(1, '\\Hello')
  154. accept_heading_suppressed_crossref
  155. end
  156. ##
  157. # Calls accept_paragraph
  158. def test_accept_paragraph
  159. @to.start_accepting
  160. @to.accept_paragraph @RM::Paragraph.new('hi')
  161. accept_paragraph
  162. end
  163. ##
  164. # Calls accept_paragraph_b with a RDoc::Markup::Paragraph containing
  165. # bold words
  166. def test_accept_paragraph_b
  167. @to.start_accepting
  168. @to.accept_paragraph @RM::Paragraph.new('reg <b>bold words</b> reg')
  169. accept_paragraph_b
  170. end
  171. ##
  172. # Calls accept_paragraph_i with a RDoc::Markup::Paragraph containing
  173. # emphasized words
  174. def test_accept_paragraph_i
  175. @to.start_accepting
  176. @to.accept_paragraph @RM::Paragraph.new('reg <em>italic words</em> reg')
  177. accept_paragraph_i
  178. end
  179. ##
  180. # Calls accept_paragraph_plus with a RDoc::Markup::Paragraph containing
  181. # teletype words
  182. def test_accept_paragraph_plus
  183. @to.start_accepting
  184. @to.accept_paragraph @RM::Paragraph.new('reg +teletype+ reg')
  185. accept_paragraph_plus
  186. end
  187. ##
  188. # Calls accept_paragraph_star with a RDoc::Markup::Paragraph containing
  189. # bold words
  190. def test_accept_paragraph_star
  191. @to.start_accepting
  192. @to.accept_paragraph @RM::Paragraph.new('reg *bold* reg')
  193. accept_paragraph_star
  194. end
  195. ##
  196. # Calls accept_paragraph_underscore with a RDoc::Markup::Paragraph
  197. # containing emphasized words
  198. def test_accept_paragraph_underscore
  199. @to.start_accepting
  200. @to.accept_paragraph @RM::Paragraph.new('reg _italic_ reg')
  201. accept_paragraph_underscore
  202. end
  203. ##
  204. # Calls accept_verbatim with a RDoc::Markup::Verbatim
  205. def test_accept_verbatim
  206. @to.start_accepting
  207. @to.accept_verbatim @RM::Verbatim.new("hi\n", " world\n")
  208. accept_verbatim
  209. end
  210. ##
  211. # Calls accept_raw with a RDoc::Markup::Raw
  212. def test_accept_raw
  213. @to.start_accepting
  214. @to.accept_raw @RM::Raw.new("<table>",
  215. "<tr><th>Name<th>Count",
  216. "<tr><td>a<td>1",
  217. "<tr><td>b<td>2",
  218. "</table>")
  219. accept_raw
  220. end
  221. ##
  222. # Calls accept_rule with a RDoc::Markup::Rule
  223. def test_accept_rule
  224. @to.start_accepting
  225. @to.accept_rule @RM::Rule.new(4)
  226. accept_rule
  227. end
  228. ##
  229. # Calls accept_list_item_start_bullet
  230. def test_accept_list_item_start_bullet
  231. @to.start_accepting
  232. @to.accept_list_start @bullet_list
  233. @to.accept_list_item_start @bullet_list.items.first
  234. accept_list_item_start_bullet
  235. end
  236. ##
  237. # Calls accept_list_item_start_label
  238. def test_accept_list_item_start_label
  239. @to.start_accepting
  240. @to.accept_list_start @label_list
  241. @to.accept_list_item_start @label_list.items.first
  242. accept_list_item_start_label
  243. end
  244. ##
  245. # Calls accept_list_item_start_lalpha
  246. def test_accept_list_item_start_lalpha
  247. @to.start_accepting
  248. @to.accept_list_start @lalpha_list
  249. @to.accept_list_item_start @lalpha_list.items.first
  250. accept_list_item_start_lalpha
  251. end
  252. ##
  253. # Calls accept_list_item_start_note
  254. def test_accept_list_item_start_note
  255. @to.start_accepting
  256. @to.accept_list_start @note_list
  257. @to.accept_list_item_start @note_list.items.first
  258. accept_list_item_start_note
  259. end
  260. ##
  261. # Calls accept_list_item_start_note_2
  262. def test_accept_list_item_start_note_2
  263. list = @RM::List.new(:NOTE,
  264. @RM::ListItem.new('<tt>teletype</tt>',
  265. @RM::Paragraph.new('teletype description')))
  266. @to.start_accepting
  267. list.accept @to
  268. @to.end_accepting
  269. accept_list_item_start_note_2
  270. end
  271. ##
  272. # Calls accept_list_item_start_number
  273. def test_accept_list_item_start_number
  274. @to.start_accepting
  275. @to.accept_list_start @number_list
  276. @to.accept_list_item_start @number_list.items.first
  277. accept_list_item_start_number
  278. end
  279. ##
  280. # Calls accept_list_item_start_ualpha
  281. def test_accept_list_item_start_ualpha
  282. @to.start_accepting
  283. @to.accept_list_start @ualpha_list
  284. @to.accept_list_item_start @ualpha_list.items.first
  285. accept_list_item_start_ualpha
  286. end
  287. ##
  288. # Calls accept_list_item_end_bullet
  289. def test_accept_list_item_end_bullet
  290. @to.start_accepting
  291. @to.accept_list_start @bullet_list
  292. @to.accept_list_item_start @bullet_list.items.first
  293. @to.accept_list_item_end @bullet_list.items.first
  294. accept_list_item_end_bullet
  295. end
  296. ##
  297. # Calls accept_list_item_end_label
  298. def test_accept_list_item_end_label
  299. @to.start_accepting
  300. @to.accept_list_start @label_list
  301. @to.accept_list_item_start @label_list.items.first
  302. @to.accept_list_item_end @label_list.items.first
  303. accept_list_item_end_label
  304. end
  305. ##
  306. # Calls accept_list_item_end_lalpha
  307. def test_accept_list_item_end_lalpha
  308. @to.start_accepting
  309. @to.accept_list_start @lalpha_list
  310. @to.accept_list_item_start @lalpha_list.items.first
  311. @to.accept_list_item_end @lalpha_list.items.first
  312. accept_list_item_end_lalpha
  313. end
  314. ##
  315. # Calls accept_list_item_end_note
  316. def test_accept_list_item_end_note
  317. @to.start_accepting
  318. @to.accept_list_start @note_list
  319. @to.accept_list_item_start @note_list.items.first
  320. @to.accept_list_item_end @note_list.items.first
  321. accept_list_item_end_note
  322. end
  323. ##
  324. # Calls accept_list_item_end_number
  325. def test_accept_list_item_end_number
  326. @to.start_accepting
  327. @to.accept_list_start @number_list
  328. @to.accept_list_item_start @number_list.items.first
  329. @to.accept_list_item_end @number_list.items.first
  330. accept_list_item_end_number
  331. end
  332. ##
  333. # Calls accept_list_item_end_ualpha
  334. def test_accept_list_item_end_ualpha
  335. @to.start_accepting
  336. @to.accept_list_start @ualpha_list
  337. @to.accept_list_item_start @ualpha_list.items.first
  338. @to.accept_list_item_end @ualpha_list.items.first
  339. accept_list_item_end_ualpha
  340. end
  341. ##
  342. # Calls accept_list_start_bullet
  343. def test_accept_list_start_bullet
  344. @to.start_accepting
  345. @to.accept_list_start @bullet_list
  346. accept_list_start_bullet
  347. end
  348. ##
  349. # Calls accept_list_start_label
  350. def test_accept_list_start_label
  351. @to.start_accepting
  352. @to.accept_list_start @label_list
  353. accept_list_start_label
  354. end
  355. ##
  356. # Calls accept_list_start_lalpha
  357. def test_accept_list_start_lalpha
  358. @to.start_accepting
  359. @to.accept_list_start @lalpha_list
  360. accept_list_start_lalpha
  361. end
  362. ##
  363. # Calls accept_list_start_note
  364. def test_accept_list_start_note
  365. @to.start_accepting
  366. @to.accept_list_start @note_list
  367. accept_list_start_note
  368. end
  369. ##
  370. # Calls accept_list_start_number
  371. def test_accept_list_start_number
  372. @to.start_accepting
  373. @to.accept_list_start @number_list
  374. accept_list_start_number
  375. end
  376. ##
  377. # Calls accept_list_start_ualpha
  378. def test_accept_list_start_ualpha
  379. @to.start_accepting
  380. @to.accept_list_start @ualpha_list
  381. accept_list_start_ualpha
  382. end
  383. ##
  384. # Calls accept_list_end_bullet
  385. def test_accept_list_end_bullet
  386. @to.start_accepting
  387. @to.accept_list_start @bullet_list
  388. @to.accept_list_end @bullet_list
  389. accept_list_end_bullet
  390. end
  391. ##
  392. # Calls accept_list_end_label
  393. def test_accept_list_end_label
  394. @to.start_accepting
  395. @to.accept_list_start @label_list
  396. @to.accept_list_end @label_list
  397. accept_list_end_label
  398. end
  399. ##
  400. # Calls accept_list_end_lalpha
  401. def test_accept_list_end_lalpha
  402. @to.start_accepting
  403. @to.accept_list_start @lalpha_list
  404. @to.accept_list_end @lalpha_list
  405. accept_list_end_lalpha
  406. end
  407. ##
  408. # Calls accept_list_end_number
  409. def test_accept_list_end_number
  410. @to.start_accepting
  411. @to.accept_list_start @number_list
  412. @to.accept_list_end @number_list
  413. accept_list_end_number
  414. end
  415. ##
  416. # Calls accept_list_end_note
  417. def test_accept_list_end_note
  418. @to.start_accepting
  419. @to.accept_list_start @note_list
  420. @to.accept_list_end @note_list
  421. accept_list_end_note
  422. end
  423. ##
  424. # Calls accept_list_end_ulpha
  425. def test_accept_list_end_ualpha
  426. @to.start_accepting
  427. @to.accept_list_start @ualpha_list
  428. @to.accept_list_end @ualpha_list
  429. accept_list_end_ualpha
  430. end
  431. ##
  432. # Calls list_nested with a two-level list
  433. def test_list_nested
  434. doc = @RM::Document.new(
  435. @RM::List.new(:BULLET,
  436. @RM::ListItem.new(nil,
  437. @RM::Paragraph.new('l1'),
  438. @RM::List.new(:BULLET,
  439. @RM::ListItem.new(nil,
  440. @RM::Paragraph.new('l1.1')))),
  441. @RM::ListItem.new(nil,
  442. @RM::Paragraph.new('l2'))))
  443. doc.accept @to
  444. list_nested
  445. end
  446. ##
  447. # Calls list_verbatim with a list containing a verbatim block
  448. def test_list_verbatim # HACK overblown
  449. doc = @RM::Document.new(
  450. @RM::List.new(:BULLET,
  451. @RM::ListItem.new(nil,
  452. @RM::Paragraph.new('list', 'stuff'),
  453. @RM::BlankLine.new,
  454. @RM::Verbatim.new("* list\n",
  455. " with\n",
  456. "\n",
  457. " second\n",
  458. "\n",
  459. " 1. indented\n",
  460. " 2. numbered\n",
  461. "\n",
  462. " third\n",
  463. "\n",
  464. "* second\n"))))
  465. doc.accept @to
  466. list_verbatim
  467. end
  468. end
  469. end
  470. end