rdoc 4.2.1 → 6.3.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rdoc might be problematic. Click here for more details.

Files changed (277) hide show
  1. checksums.yaml +5 -5
  2. data/CONTRIBUTING.rdoc +8 -7
  3. data/Gemfile +12 -0
  4. data/History.rdoc +48 -4
  5. data/LEGAL.rdoc +2 -2
  6. data/README.rdoc +5 -5
  7. data/Rakefile +73 -155
  8. data/bin/console +7 -0
  9. data/bin/setup +6 -0
  10. data/{bin → exe}/rdoc +0 -0
  11. data/{bin → exe}/ri +0 -0
  12. data/lib/rdoc/alias.rb +1 -0
  13. data/lib/rdoc/anon_class.rb +1 -0
  14. data/lib/rdoc/any_method.rb +59 -14
  15. data/lib/rdoc/attr.rb +1 -0
  16. data/lib/rdoc/class_module.rb +5 -2
  17. data/lib/rdoc/code_object.rb +3 -11
  18. data/lib/rdoc/code_objects.rb +1 -0
  19. data/lib/rdoc/comment.rb +32 -11
  20. data/lib/rdoc/constant.rb +3 -2
  21. data/lib/rdoc/context/section.rb +7 -13
  22. data/lib/rdoc/context.rb +78 -23
  23. data/lib/rdoc/cross_reference.rb +33 -14
  24. data/lib/rdoc/encoding.rb +92 -55
  25. data/lib/rdoc/erb_partial.rb +2 -1
  26. data/lib/rdoc/erbio.rb +8 -3
  27. data/lib/rdoc/extend.rb +1 -0
  28. data/lib/rdoc/generator/darkfish.rb +62 -32
  29. data/lib/rdoc/generator/json_index.rb +8 -5
  30. data/lib/rdoc/generator/markup.rb +3 -12
  31. data/lib/rdoc/generator/pot/message_extractor.rb +68 -0
  32. data/lib/rdoc/generator/pot/po.rb +84 -0
  33. data/lib/rdoc/generator/pot/po_entry.rb +141 -0
  34. data/lib/rdoc/generator/pot.rb +4 -3
  35. data/lib/rdoc/generator/ri.rb +1 -0
  36. data/lib/rdoc/generator/template/darkfish/_footer.rhtml +2 -2
  37. data/lib/rdoc/generator/template/darkfish/_head.rhtml +11 -8
  38. data/lib/rdoc/generator/template/darkfish/_sidebar_VCS_info.rhtml +2 -2
  39. data/lib/rdoc/generator/template/darkfish/_sidebar_classes.rhtml +2 -2
  40. data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +7 -7
  41. data/lib/rdoc/generator/template/darkfish/_sidebar_in_files.rhtml +2 -2
  42. data/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +7 -7
  43. data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +6 -6
  44. data/lib/rdoc/generator/template/darkfish/_sidebar_methods.rhtml +5 -5
  45. data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +5 -5
  46. data/lib/rdoc/generator/template/darkfish/_sidebar_parent.rhtml +5 -5
  47. data/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml +4 -4
  48. data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +4 -4
  49. data/lib/rdoc/generator/template/darkfish/class.rhtml +45 -47
  50. data/lib/rdoc/generator/template/darkfish/css/fonts.css +6 -6
  51. data/lib/rdoc/generator/template/darkfish/css/rdoc.css +55 -6
  52. data/lib/rdoc/generator/template/darkfish/index.rhtml +3 -4
  53. data/lib/rdoc/generator/template/darkfish/js/darkfish.js +23 -100
  54. data/lib/rdoc/generator/template/darkfish/js/search.js +32 -31
  55. data/lib/rdoc/generator/template/darkfish/servlet_root.rhtml +15 -16
  56. data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +16 -16
  57. data/lib/rdoc/generator/template/json_index/js/navigation.js +4 -41
  58. data/lib/rdoc/generator/template/json_index/js/searcher.js +7 -6
  59. data/lib/rdoc/generator.rb +1 -1
  60. data/lib/rdoc/ghost_method.rb +1 -0
  61. data/lib/rdoc/i18n/locale.rb +2 -1
  62. data/lib/rdoc/i18n/text.rb +5 -4
  63. data/lib/rdoc/i18n.rb +3 -2
  64. data/lib/rdoc/include.rb +1 -0
  65. data/lib/rdoc/known_classes.rb +1 -0
  66. data/lib/rdoc/markdown/entities.rb +1 -0
  67. data/lib/rdoc/markdown/{literals_1_9.kpeg → literals.kpeg} +1 -0
  68. data/lib/rdoc/markdown/{literals_1_9.rb → literals.rb} +1 -4
  69. data/lib/rdoc/markdown.kpeg +94 -51
  70. data/lib/rdoc/markdown.rb +1171 -619
  71. data/lib/rdoc/markup/attr_changer.rb +1 -0
  72. data/lib/rdoc/markup/attr_span.rb +9 -2
  73. data/lib/rdoc/markup/attribute_manager.rb +115 -49
  74. data/lib/rdoc/markup/attributes.rb +7 -6
  75. data/lib/rdoc/markup/blank_line.rb +1 -0
  76. data/lib/rdoc/markup/block_quote.rb +1 -0
  77. data/lib/rdoc/markup/document.rb +1 -0
  78. data/lib/rdoc/markup/formatter.rb +25 -23
  79. data/lib/rdoc/markup/hard_break.rb +1 -0
  80. data/lib/rdoc/markup/heading.rb +4 -3
  81. data/lib/rdoc/markup/include.rb +1 -0
  82. data/lib/rdoc/markup/indented_paragraph.rb +1 -0
  83. data/lib/rdoc/markup/list.rb +1 -0
  84. data/lib/rdoc/markup/list_item.rb +1 -0
  85. data/lib/rdoc/markup/paragraph.rb +1 -0
  86. data/lib/rdoc/markup/parser.rb +78 -61
  87. data/lib/rdoc/markup/pre_process.rb +12 -9
  88. data/lib/rdoc/markup/raw.rb +1 -0
  89. data/lib/rdoc/markup/regexp_handling.rb +41 -0
  90. data/lib/rdoc/markup/rule.rb +1 -0
  91. data/lib/rdoc/markup/to_ansi.rb +1 -0
  92. data/lib/rdoc/markup/to_bs.rb +4 -5
  93. data/lib/rdoc/markup/to_html.rb +71 -25
  94. data/lib/rdoc/markup/to_html_crossref.rb +41 -25
  95. data/lib/rdoc/markup/to_html_snippet.rb +10 -9
  96. data/lib/rdoc/markup/to_joined_paragraph.rb +7 -31
  97. data/lib/rdoc/markup/to_label.rb +10 -9
  98. data/lib/rdoc/markup/to_markdown.rb +9 -8
  99. data/lib/rdoc/markup/to_rdoc.rb +35 -6
  100. data/lib/rdoc/markup/to_table_of_contents.rb +2 -0
  101. data/lib/rdoc/markup/to_test.rb +1 -0
  102. data/lib/rdoc/markup/to_tt_only.rb +3 -2
  103. data/lib/rdoc/markup/verbatim.rb +1 -0
  104. data/lib/rdoc/markup.rb +14 -16
  105. data/lib/rdoc/meta_method.rb +1 -0
  106. data/lib/rdoc/method_attr.rb +2 -1
  107. data/lib/rdoc/mixin.rb +1 -0
  108. data/lib/rdoc/normal_class.rb +3 -2
  109. data/lib/rdoc/normal_module.rb +1 -0
  110. data/lib/rdoc/options.rb +92 -58
  111. data/lib/rdoc/parser/c.rb +219 -223
  112. data/lib/rdoc/parser/changelog.rb +155 -18
  113. data/lib/rdoc/parser/markdown.rb +1 -0
  114. data/lib/rdoc/parser/rd.rb +1 -0
  115. data/lib/rdoc/parser/ripper_state_lex.rb +590 -0
  116. data/lib/rdoc/parser/ruby.rb +635 -468
  117. data/lib/rdoc/parser/ruby_tools.rb +33 -33
  118. data/lib/rdoc/parser/simple.rb +3 -3
  119. data/lib/rdoc/parser/text.rb +1 -0
  120. data/lib/rdoc/parser.rb +17 -50
  121. data/lib/rdoc/rd/block_parser.rb +66 -65
  122. data/lib/rdoc/rd/block_parser.ry +3 -3
  123. data/lib/rdoc/rd/inline.rb +5 -4
  124. data/lib/rdoc/rd/inline_parser.rb +52 -51
  125. data/lib/rdoc/rd/inline_parser.ry +1 -1
  126. data/lib/rdoc/rd.rb +1 -0
  127. data/lib/rdoc/rdoc.rb +68 -63
  128. data/lib/rdoc/require.rb +1 -0
  129. data/lib/rdoc/ri/driver.rb +133 -58
  130. data/lib/rdoc/ri/formatter.rb +1 -0
  131. data/lib/rdoc/ri/paths.rb +4 -20
  132. data/lib/rdoc/ri/store.rb +1 -0
  133. data/lib/rdoc/ri/task.rb +71 -0
  134. data/lib/rdoc/ri.rb +1 -0
  135. data/lib/rdoc/rubygems_hook.rb +5 -12
  136. data/lib/rdoc/servlet.rb +24 -14
  137. data/lib/rdoc/single_class.rb +1 -0
  138. data/lib/rdoc/stats/normal.rb +20 -21
  139. data/lib/rdoc/stats/quiet.rb +1 -0
  140. data/lib/rdoc/stats/verbose.rb +1 -0
  141. data/lib/rdoc/stats.rb +1 -0
  142. data/lib/rdoc/store.rb +41 -41
  143. data/lib/rdoc/task.rb +2 -3
  144. data/lib/rdoc/text.rb +19 -38
  145. data/lib/rdoc/token_stream.rb +56 -32
  146. data/lib/rdoc/tom_doc.rb +17 -11
  147. data/lib/rdoc/top_level.rb +9 -2
  148. data/lib/rdoc/version.rb +8 -0
  149. data/lib/rdoc.rb +24 -10
  150. data/man/ri.1 +247 -0
  151. data/rdoc.gemspec +248 -0
  152. metadata +43 -236
  153. data/.autotest +0 -24
  154. data/.document +0 -5
  155. data/Manifest.txt +0 -306
  156. data/lib/gauntlet_rdoc.rb +0 -84
  157. data/lib/rdoc/generator/template/darkfish/js/jquery.js +0 -4
  158. data/lib/rdoc/markdown/literals_1_8.kpeg +0 -18
  159. data/lib/rdoc/markdown/literals_1_8.rb +0 -416
  160. data/lib/rdoc/markup/formatter_test_case.rb +0 -767
  161. data/lib/rdoc/markup/inline.rb +0 -1
  162. data/lib/rdoc/markup/special.rb +0 -40
  163. data/lib/rdoc/markup/text_formatter_test_case.rb +0 -114
  164. data/lib/rdoc/ruby_lex.rb +0 -1377
  165. data/lib/rdoc/ruby_token.rb +0 -460
  166. data/lib/rdoc/test_case.rb +0 -217
  167. data/test/MarkdownTest_1.0.3/Amps and angle encoding.text +0 -21
  168. data/test/MarkdownTest_1.0.3/Auto links.text +0 -13
  169. data/test/MarkdownTest_1.0.3/Backslash escapes.text +0 -120
  170. data/test/MarkdownTest_1.0.3/Blockquotes with code blocks.text +0 -11
  171. data/test/MarkdownTest_1.0.3/Code Blocks.text +0 -14
  172. data/test/MarkdownTest_1.0.3/Code Spans.text +0 -6
  173. data/test/MarkdownTest_1.0.3/Hard-wrapped paragraphs with list-like lines.text +0 -8
  174. data/test/MarkdownTest_1.0.3/Horizontal rules.text +0 -67
  175. data/test/MarkdownTest_1.0.3/Inline HTML (Advanced).text +0 -15
  176. data/test/MarkdownTest_1.0.3/Inline HTML (Simple).text +0 -69
  177. data/test/MarkdownTest_1.0.3/Inline HTML comments.text +0 -13
  178. data/test/MarkdownTest_1.0.3/Links, inline style.text +0 -12
  179. data/test/MarkdownTest_1.0.3/Links, reference style.text +0 -71
  180. data/test/MarkdownTest_1.0.3/Links, shortcut references.text +0 -20
  181. data/test/MarkdownTest_1.0.3/Literal quotes in titles.text +0 -7
  182. data/test/MarkdownTest_1.0.3/Markdown Documentation - Basics.text +0 -306
  183. data/test/MarkdownTest_1.0.3/Markdown Documentation - Syntax.text +0 -888
  184. data/test/MarkdownTest_1.0.3/Nested blockquotes.text +0 -5
  185. data/test/MarkdownTest_1.0.3/Ordered and unordered lists.text +0 -131
  186. data/test/MarkdownTest_1.0.3/Strong and em together.text +0 -7
  187. data/test/MarkdownTest_1.0.3/Tabs.text +0 -21
  188. data/test/MarkdownTest_1.0.3/Tidyness.text +0 -5
  189. data/test/README +0 -1
  190. data/test/binary.dat +0 -0
  191. data/test/hidden.zip.txt +0 -1
  192. data/test/test.ja.largedoc +0 -3
  193. data/test/test.ja.rdoc +0 -10
  194. data/test/test.ja.txt +0 -8
  195. data/test/test.txt +0 -1
  196. data/test/test_rdoc_alias.rb +0 -13
  197. data/test/test_rdoc_any_method.rb +0 -460
  198. data/test/test_rdoc_attr.rb +0 -190
  199. data/test/test_rdoc_class_module.rb +0 -1492
  200. data/test/test_rdoc_code_object.rb +0 -450
  201. data/test/test_rdoc_comment.rb +0 -504
  202. data/test/test_rdoc_constant.rb +0 -181
  203. data/test/test_rdoc_context.rb +0 -901
  204. data/test/test_rdoc_context_section.rb +0 -130
  205. data/test/test_rdoc_cross_reference.rb +0 -192
  206. data/test/test_rdoc_encoding.rb +0 -227
  207. data/test/test_rdoc_extend.rb +0 -94
  208. data/test/test_rdoc_generator_darkfish.rb +0 -229
  209. data/test/test_rdoc_generator_json_index.rb +0 -324
  210. data/test/test_rdoc_generator_markup.rb +0 -59
  211. data/test/test_rdoc_generator_pot.rb +0 -91
  212. data/test/test_rdoc_generator_pot_po.rb +0 -51
  213. data/test/test_rdoc_generator_pot_po_entry.rb +0 -139
  214. data/test/test_rdoc_generator_ri.rb +0 -78
  215. data/test/test_rdoc_i18n_locale.rb +0 -73
  216. data/test/test_rdoc_i18n_text.rb +0 -123
  217. data/test/test_rdoc_include.rb +0 -108
  218. data/test/test_rdoc_markdown.rb +0 -980
  219. data/test/test_rdoc_markdown_test.rb +0 -1884
  220. data/test/test_rdoc_markup.rb +0 -95
  221. data/test/test_rdoc_markup_attribute_manager.rb +0 -364
  222. data/test/test_rdoc_markup_attributes.rb +0 -39
  223. data/test/test_rdoc_markup_document.rb +0 -207
  224. data/test/test_rdoc_markup_formatter.rb +0 -175
  225. data/test/test_rdoc_markup_hard_break.rb +0 -31
  226. data/test/test_rdoc_markup_heading.rb +0 -29
  227. data/test/test_rdoc_markup_include.rb +0 -19
  228. data/test/test_rdoc_markup_indented_paragraph.rb +0 -53
  229. data/test/test_rdoc_markup_paragraph.rb +0 -32
  230. data/test/test_rdoc_markup_parser.rb +0 -1680
  231. data/test/test_rdoc_markup_pre_process.rb +0 -473
  232. data/test/test_rdoc_markup_raw.rb +0 -22
  233. data/test/test_rdoc_markup_to_ansi.rb +0 -369
  234. data/test/test_rdoc_markup_to_bs.rb +0 -366
  235. data/test/test_rdoc_markup_to_html.rb +0 -662
  236. data/test/test_rdoc_markup_to_html_crossref.rb +0 -225
  237. data/test/test_rdoc_markup_to_html_snippet.rb +0 -711
  238. data/test/test_rdoc_markup_to_joined_paragraph.rb +0 -32
  239. data/test/test_rdoc_markup_to_label.rb +0 -112
  240. data/test/test_rdoc_markup_to_markdown.rb +0 -389
  241. data/test/test_rdoc_markup_to_rdoc.rb +0 -377
  242. data/test/test_rdoc_markup_to_table_of_contents.rb +0 -126
  243. data/test/test_rdoc_markup_to_tt_only.rb +0 -246
  244. data/test/test_rdoc_markup_verbatim.rb +0 -29
  245. data/test/test_rdoc_method_attr.rb +0 -193
  246. data/test/test_rdoc_normal_class.rb +0 -47
  247. data/test/test_rdoc_normal_module.rb +0 -42
  248. data/test/test_rdoc_options.rb +0 -766
  249. data/test/test_rdoc_parser.rb +0 -327
  250. data/test/test_rdoc_parser_c.rb +0 -1896
  251. data/test/test_rdoc_parser_changelog.rb +0 -315
  252. data/test/test_rdoc_parser_markdown.rb +0 -61
  253. data/test/test_rdoc_parser_rd.rb +0 -55
  254. data/test/test_rdoc_parser_ruby.rb +0 -3322
  255. data/test/test_rdoc_parser_simple.rb +0 -115
  256. data/test/test_rdoc_rd.rb +0 -30
  257. data/test/test_rdoc_rd_block_parser.rb +0 -535
  258. data/test/test_rdoc_rd_inline.rb +0 -63
  259. data/test/test_rdoc_rd_inline_parser.rb +0 -177
  260. data/test/test_rdoc_rdoc.rb +0 -455
  261. data/test/test_rdoc_require.rb +0 -25
  262. data/test/test_rdoc_ri_driver.rb +0 -1436
  263. data/test/test_rdoc_ri_paths.rb +0 -155
  264. data/test/test_rdoc_ruby_lex.rb +0 -421
  265. data/test/test_rdoc_ruby_token.rb +0 -19
  266. data/test/test_rdoc_rubygems_hook.rb +0 -251
  267. data/test/test_rdoc_servlet.rb +0 -534
  268. data/test/test_rdoc_single_class.rb +0 -20
  269. data/test/test_rdoc_stats.rb +0 -722
  270. data/test/test_rdoc_store.rb +0 -993
  271. data/test/test_rdoc_task.rb +0 -173
  272. data/test/test_rdoc_text.rb +0 -557
  273. data/test/test_rdoc_token_stream.rb +0 -42
  274. data/test/test_rdoc_tom_doc.rb +0 -520
  275. data/test/test_rdoc_top_level.rb +0 -287
  276. data/test/xref_data.rb +0 -76
  277. data/test/xref_test_case.rb +0 -67
@@ -1,1680 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'rdoc/test_case'
4
-
5
- class TestRDocMarkupParser < RDoc::TestCase
6
-
7
- def setup
8
- super
9
-
10
- @have_byteslice = ''.respond_to? :byteslice
11
-
12
- @RMP = @RM::Parser
13
- end
14
-
15
- def test_build_heading
16
- parser = @RMP.new
17
-
18
- parser.tokens.replace [
19
- [:TEXT, 'heading three', 4, 0],
20
- [:NEWLINE, "\n", 17, 0],
21
- ]
22
-
23
- assert_equal @RM::Heading.new(3, 'heading three'), parser.build_heading(3)
24
- end
25
-
26
- def test_char_pos
27
- parser = @RMP.new
28
- s = parser.setup_scanner 'cät'
29
-
30
- s.scan(/\S+/)
31
-
32
- if @have_byteslice or @have_encoding then
33
- assert_equal 3, parser.char_pos(s.pos)
34
- else
35
- assert_equal 4, parser.char_pos(s.pos)
36
- end
37
- end
38
-
39
- def test_get
40
- parser = util_parser
41
-
42
- assert_equal [:HEADER, 1, 0, 0], parser.get
43
-
44
- assert_equal 7, parser.tokens.length
45
- end
46
-
47
- def test_parse_bullet
48
- str = <<-STR
49
- * l1
50
- * l2
51
- STR
52
-
53
- expected = [
54
- @RM::List.new(:BULLET, *[
55
- @RM::ListItem.new(nil,
56
- @RM::Paragraph.new('l1')),
57
- @RM::ListItem.new(nil,
58
- @RM::Paragraph.new('l2'))])]
59
-
60
- assert_equal expected, @RMP.parse(str).parts
61
- end
62
-
63
- def test_parse_bullet_utf_8
64
- str = <<-STR
65
- * 新しい機能
66
- STR
67
-
68
- expected = [
69
- @RM::List.new(:BULLET, *[
70
- @RM::ListItem.new(nil,
71
- @RM::Paragraph.new('新しい機能'))])]
72
-
73
- assert_equal expected, @RMP.parse(str).parts
74
- end
75
-
76
- def test_parse_bullet_verbatim_heading
77
- str = <<-STR
78
- * l1
79
- v
80
-
81
- = H
82
- STR
83
-
84
- expected = [
85
- @RM::List.new(:BULLET, *[
86
- @RM::ListItem.new(nil,
87
- @RM::Paragraph.new('l1'),
88
- @RM::Verbatim.new("v\n"))]),
89
- @RM::Heading.new(1, 'H')]
90
-
91
- assert_equal expected, @RMP.parse(str).parts
92
- end
93
-
94
- def test_parse_bullet_heading
95
- str = <<-STR
96
- * = l1
97
- STR
98
-
99
- expected = [
100
- @RM::List.new(:BULLET, *[
101
- @RM::ListItem.new(nil,
102
- @RM::Heading.new(1, 'l1'))])]
103
-
104
- assert_equal expected, @RMP.parse(str).parts
105
- end
106
-
107
- def test_parse_bullet_indent
108
- str = <<-STR
109
- * l1
110
- * l1.1
111
- * l2
112
- STR
113
-
114
- expected = [
115
- @RM::List.new(:BULLET, *[
116
- @RM::ListItem.new(nil,
117
- @RM::Paragraph.new('l1'),
118
- @RM::List.new(:BULLET, *[
119
- @RM::ListItem.new(nil,
120
- @RM::Paragraph.new('l1.1'))])),
121
- @RM::ListItem.new(nil,
122
- @RM::Paragraph.new('l2'))])]
123
-
124
- assert_equal expected, @RMP.parse(str).parts
125
- end
126
-
127
- def test_parse_bullet_paragraph
128
- str = <<-STR
129
- now is
130
- * l1
131
- * l2
132
- the time
133
- STR
134
-
135
- expected = [
136
- @RM::Paragraph.new('now is'),
137
- @RM::List.new(:BULLET, *[
138
- @RM::ListItem.new(nil,
139
- @RM::Paragraph.new('l1')),
140
- @RM::ListItem.new(nil,
141
- @RM::Paragraph.new('l2')),
142
- ]),
143
- @RM::Paragraph.new('the time'),
144
- ]
145
-
146
- assert_equal expected, @RMP.parse(str).parts
147
- end
148
-
149
- def test_parse_bullet_multiline
150
- str = <<-STR
151
- * l1
152
- l1+
153
- * l2
154
- STR
155
-
156
- expected = [
157
- list(:BULLET,
158
- item(nil,
159
- para('l1 ', 'l1+')),
160
- item(nil,
161
- para('l2')))]
162
-
163
- assert_equal expected, @RMP.parse(str).parts
164
- end
165
-
166
- def test_parse_bullet_multiparagraph
167
- str = <<-STR
168
- * l1
169
-
170
- l1+
171
- STR
172
-
173
- expected = [
174
- @RM::List.new(:BULLET, *[
175
- @RM::ListItem.new(nil,
176
- @RM::Paragraph.new('l1'),
177
- @RM::BlankLine.new,
178
- @RM::Paragraph.new('l1+')),
179
- ]),
180
- ]
181
-
182
- assert_equal expected, @RMP.parse(str).parts
183
- end
184
-
185
- def test_parse_bullet_indent_verbatim
186
- str = <<-STR
187
- * l1
188
- * l1.1
189
- text
190
- code
191
- code
192
-
193
- text
194
- * l2
195
- STR
196
-
197
- expected = [
198
- list(:BULLET,
199
- item(nil,
200
- para('l1'),
201
- list(:BULLET,
202
- item(nil,
203
- para('l1.1 ', 'text'),
204
- verb("code\n", " code\n"),
205
- para('text')))),
206
- item(nil,
207
- para('l2')))]
208
-
209
- assert_equal expected, @RMP.parse(str).parts
210
- end
211
-
212
- def test_parse_dash
213
- str = <<-STR
214
- - one
215
- - two
216
- STR
217
-
218
- expected = [
219
- @RM::List.new(:BULLET, *[
220
- @RM::ListItem.new(nil,
221
- @RM::Paragraph.new('one')),
222
- @RM::ListItem.new(nil,
223
- @RM::Paragraph.new('two'))])]
224
-
225
- assert_equal expected, @RMP.parse(str).parts
226
- end
227
-
228
- def test_parse_heading
229
- str = '= heading one'
230
-
231
- expected = [
232
- @RM::Heading.new(1, 'heading one')]
233
-
234
- assert_equal expected, @RMP.parse(str).parts
235
- end
236
-
237
- def test_parse_heading_three
238
- str = '=== heading three'
239
-
240
- expected = [
241
- @RM::Heading.new(3, 'heading three')]
242
-
243
- assert_equal expected, @RMP.parse(str).parts
244
- end
245
-
246
- def test_parse_heading_bullet
247
- str = '= * heading one'
248
-
249
- expected = [
250
- @RM::Heading.new(1, '* heading one')]
251
-
252
- assert_equal expected, @RMP.parse(str).parts
253
- end
254
-
255
- def test_parse_heading_empty
256
- str = <<-STR
257
- ===
258
- * bullet
259
- STR
260
-
261
- expected = [
262
- @RM::Heading.new(3, ''),
263
- @RM::BlankLine.new,
264
- @RM::List.new(:BULLET, *[
265
- @RM::ListItem.new(nil,
266
- @RM::Paragraph.new('bullet'))]),
267
- ]
268
-
269
- assert_equal expected, @RMP.parse(str).parts
270
- end
271
-
272
- def test_parse_heading_heading
273
- str = '= ='
274
-
275
- expected = [
276
- @RM::Heading.new(1, '=')]
277
-
278
- assert_equal expected, @RMP.parse(str).parts
279
- end
280
-
281
- def test_parse_heading_lalpha
282
- str = '= b. heading one'
283
-
284
- expected = [
285
- @RM::Heading.new(1, 'b. heading one')]
286
-
287
- assert_equal expected, @RMP.parse(str).parts
288
- end
289
-
290
- def test_parse_heading_label
291
- str = '= [heading one]'
292
-
293
- expected = [
294
- @RM::Heading.new(1, '[heading one]')]
295
-
296
- assert_equal expected, @RMP.parse(str).parts
297
- end
298
-
299
- def test_parse_heading_note
300
- str = '= heading one::'
301
-
302
- expected = [
303
- @RM::Heading.new(1, 'heading one::')]
304
-
305
- assert_equal expected, @RMP.parse(str).parts
306
- end
307
-
308
- def test_parse_heading_number
309
- str = '= 5. heading one'
310
-
311
- expected = [
312
- @RM::Heading.new(1, '5. heading one')]
313
-
314
- assert_equal expected, @RMP.parse(str).parts
315
- end
316
-
317
- def test_parse_heading_ualpha
318
- str = '= B. heading one'
319
-
320
- expected = [
321
- @RM::Heading.new(1, 'B. heading one')]
322
-
323
- assert_equal expected, @RMP.parse(str).parts
324
- end
325
-
326
- def test_parse_label
327
- str = <<-STR
328
- [one] item one
329
- [two] item two
330
- STR
331
-
332
- expected = [
333
- list(:LABEL,
334
- item(%w[one],
335
- para('item one')),
336
- item(%w[two],
337
- para('item two')))]
338
-
339
- assert_equal expected, @RMP.parse(str).parts
340
- end
341
-
342
- def test_parse_label_bullet
343
- str = <<-STR
344
- [cat] l1
345
- * l1.1
346
- [dog] l2
347
- STR
348
-
349
- expected = [
350
- list(:LABEL,
351
- item(%w[cat],
352
- para('l1'),
353
- list(:BULLET,
354
- item(nil,
355
- para('l1.1')))),
356
- item(%w[dog],
357
- para('l2')))]
358
-
359
- assert_equal expected, @RMP.parse(str).parts
360
- end
361
-
362
- def test_parse_label_multi_label
363
- str = <<-STR
364
- [one]
365
- [two] some description
366
- STR
367
-
368
- expected = [
369
- list(:LABEL,
370
- item(%w[one two],
371
- para('some description')))]
372
-
373
- assert_equal expected, @RMP.parse(str).parts
374
- end
375
-
376
- def test_parse_label_multi_line
377
- str = <<-STR
378
- [cat] l1
379
- continuation
380
- [dog] l2
381
- STR
382
-
383
- expected = [
384
- list(:LABEL,
385
- item(%w[cat],
386
- para('l1 ', 'continuation')),
387
- item(%w[dog],
388
- para('l2')))]
389
-
390
- assert_equal expected, @RMP.parse(str).parts
391
- end
392
-
393
- def test_parse_label_newline
394
- str = <<-STR
395
- [one]
396
- item one
397
- [two]
398
- item two
399
- STR
400
-
401
- expected = [
402
- list(:LABEL,
403
- item(%w[one],
404
- para('item one')),
405
- item(%w[two],
406
- para('item two')))]
407
-
408
- assert_equal expected, @RMP.parse(str).parts
409
- end
410
-
411
- def test_parse_lalpha
412
- str = <<-STR
413
- a. l1
414
- b. l2
415
- STR
416
-
417
- expected = [
418
- @RM::List.new(:LALPHA, *[
419
- @RM::ListItem.new(nil,
420
- @RM::Paragraph.new('l1')),
421
- @RM::ListItem.new(nil,
422
- @RM::Paragraph.new('l2'))])]
423
-
424
- assert_equal expected, @RMP.parse(str).parts
425
- end
426
-
427
- def test_parse_lalpha_ualpha
428
- str = <<-STR
429
- a. l1
430
- b. l2
431
- A. l3
432
- A. l4
433
- STR
434
-
435
- expected = [
436
- @RM::List.new(:LALPHA, *[
437
- @RM::ListItem.new(nil,
438
- @RM::Paragraph.new('l1')),
439
- @RM::ListItem.new(nil,
440
- @RM::Paragraph.new('l2'))]),
441
- @RM::List.new(:UALPHA, *[
442
- @RM::ListItem.new(nil,
443
- @RM::Paragraph.new('l3')),
444
- @RM::ListItem.new(nil,
445
- @RM::Paragraph.new('l4'))])]
446
-
447
- assert_equal expected, @RMP.parse(str).parts
448
- end
449
-
450
- def test_parse_lalpha_utf_8
451
- str = <<-STR
452
- a. 新しい機能
453
- STR
454
-
455
- expected = [
456
- @RM::List.new(:LALPHA, *[
457
- @RM::ListItem.new(nil,
458
- @RM::Paragraph.new('新しい機能'))])]
459
-
460
- assert_equal expected, @RMP.parse(str).parts
461
- end
462
-
463
- def test_parse_line_break
464
- str = "now is\nthe time \nfor all"
465
-
466
- expected = [
467
- para('now is ', 'the time'),
468
- blank_line,
469
- para('for all')]
470
-
471
- assert_equal expected, @RMP.parse(str).parts
472
- end
473
-
474
- def test_parse_list_list_1
475
- str = <<-STR
476
- 10. para 1
477
-
478
- [label 1]
479
- para 1.1
480
-
481
- code
482
-
483
- para 1.2
484
- STR
485
-
486
- expected = [
487
- list(:NUMBER,
488
- item(nil,
489
- para('para 1'),
490
- blank_line,
491
- list(:LABEL,
492
- item(%w[label\ 1],
493
- para('para 1.1'),
494
- blank_line,
495
- verb("code\n"),
496
- para('para 1.2')))))]
497
-
498
- assert_equal expected, @RMP.parse(str).parts
499
- end
500
-
501
- def test_parse_list_list_2
502
- str = <<-STR
503
- 6. para
504
-
505
- label 1:: text 1
506
- label 2:: text 2
507
- STR
508
-
509
- expected = [
510
- list(:NUMBER,
511
- item(nil,
512
- para('para'),
513
- blank_line,
514
- list(:NOTE,
515
- item(%w[label\ 1],
516
- para('text 1')),
517
- item(%w[label\ 2],
518
- para('text 2')))))]
519
-
520
- assert_equal expected, @RMP.parse(str).parts
521
- end
522
-
523
- def test_parse_list_verbatim
524
- str = <<-STR
525
- * one
526
- verb1
527
- verb2
528
- * two
529
- STR
530
-
531
- expected = [
532
- @RM::List.new(:BULLET, *[
533
- @RM::ListItem.new(nil,
534
- @RM::Paragraph.new('one'),
535
- @RM::Verbatim.new("verb1\n", "verb2\n")),
536
- @RM::ListItem.new(nil,
537
- @RM::Paragraph.new('two'))])]
538
-
539
- assert_equal expected, @RMP.parse(str).parts
540
- end
541
-
542
- def test_parse_lists
543
- str = <<-STR
544
- now is
545
- * l1
546
- 1. n1
547
- 2. n2
548
- * l2
549
- the time
550
- STR
551
-
552
- expected = [
553
- @RM::Paragraph.new('now is'),
554
- @RM::List.new(:BULLET, *[
555
- @RM::ListItem.new(nil,
556
- @RM::Paragraph.new('l1'))]),
557
- @RM::List.new(:NUMBER, *[
558
- @RM::ListItem.new(nil,
559
- @RM::Paragraph.new('n1')),
560
- @RM::ListItem.new(nil,
561
- @RM::Paragraph.new('n2'))]),
562
- @RM::List.new(:BULLET, *[
563
- @RM::ListItem.new(nil,
564
- @RM::Paragraph.new('l2'))]),
565
- @RM::Paragraph.new('the time')]
566
-
567
- assert_equal expected, @RMP.parse(str).parts
568
- end
569
-
570
- def test_parse_note
571
- str = <<-STR
572
- one:: item one
573
- two:: item two
574
- STR
575
-
576
- expected = [
577
- list(:NOTE,
578
- item(%w[one],
579
- para('item one')),
580
- item(%w[two],
581
- para('item two')))]
582
-
583
- assert_equal expected, @RMP.parse(str).parts
584
- end
585
-
586
- def test_parse_note_empty
587
- str = <<-STR
588
- one::
589
- two::
590
- STR
591
-
592
- expected = [
593
- list(:NOTE,
594
- item(%w[one two],
595
- blank_line))]
596
-
597
- assert_equal expected, @RMP.parse(str).parts
598
- end
599
-
600
- def test_parse_note_note
601
- str = <<-STR
602
- one:: two::
603
- STR
604
-
605
- expected = [
606
- list(:NOTE,
607
- item(%w[one],
608
- list(:NOTE,
609
- item(%w[two],
610
- blank_line))))]
611
-
612
- assert_equal expected, @RMP.parse(str).parts
613
- end
614
-
615
- def test_parse_number_bullet
616
- str = <<-STR
617
- 1. l1
618
- * l1.1
619
- 2. l2
620
- STR
621
-
622
- expected = [
623
- list(:NUMBER,
624
- item(nil,
625
- para('l1'),
626
- list(:BULLET,
627
- item(nil,
628
- para('l1.1')))),
629
- item(nil,
630
- para('l2')))]
631
-
632
- assert_equal expected, @RMP.parse(str).parts
633
- end
634
-
635
- def test_parse_paragraph
636
- str = <<-STR
637
- now is the time
638
-
639
- for all good men
640
- STR
641
-
642
- expected = [
643
- @RM::Paragraph.new('now is the time'),
644
- @RM::BlankLine.new,
645
- @RM::Paragraph.new('for all good men')]
646
- assert_equal expected, @RMP.parse(str).parts
647
- end
648
-
649
- def test_parse_paragraph_multiline
650
- str = "now is the time\nfor all good men"
651
-
652
- expected = @RM::Paragraph.new 'now is the time ', 'for all good men'
653
- assert_equal [expected], @RMP.parse(str).parts
654
- end
655
-
656
- def test_parse_paragraph_verbatim
657
- str = <<-STR
658
- now is the time
659
- code _line_ here
660
- for all good men
661
- STR
662
-
663
- expected = [
664
- @RM::Paragraph.new('now is the time'),
665
- @RM::Verbatim.new("code _line_ here\n"),
666
- @RM::Paragraph.new('for all good men'),
667
- ]
668
- assert_equal expected, @RMP.parse(str).parts
669
- end
670
-
671
- def test_parse_rule
672
- str = <<-STR
673
- now is the time
674
-
675
- ---
676
-
677
- for all good men
678
- STR
679
-
680
- expected = [
681
- @RM::Paragraph.new('now is the time'),
682
- @RM::BlankLine.new,
683
- @RM::Rule.new(1),
684
- @RM::BlankLine.new,
685
- @RM::Paragraph.new('for all good men')]
686
-
687
- assert_equal expected, @RMP.parse(str).parts
688
- end
689
-
690
- def test_parse_ualpha
691
- str = <<-STR
692
- A. l1
693
- B. l2
694
- STR
695
-
696
- expected = [
697
- @RM::List.new(:UALPHA, *[
698
- @RM::ListItem.new(nil,
699
- @RM::Paragraph.new('l1')),
700
- @RM::ListItem.new(nil,
701
- @RM::Paragraph.new('l2'))])]
702
-
703
- assert_equal expected, @RMP.parse(str).parts
704
- end
705
-
706
- def test_parse_trailing_cr
707
- expected = [ @RM::Paragraph.new('Text') ]
708
- # FIXME hangs the parser:
709
- assert_equal expected, @RMP.parse("Text\r").parts
710
- end
711
-
712
- def test_parse_verbatim
713
- str = <<-STR
714
- now is
715
- code
716
- the time
717
- STR
718
-
719
- expected = [
720
- @RM::Paragraph.new('now is'),
721
- @RM::Verbatim.new("code\n"),
722
- @RM::Paragraph.new('the time'),
723
- ]
724
-
725
- assert_equal expected, @RMP.parse(str).parts
726
- end
727
-
728
- def test_parse_verbatim_bullet
729
- str = <<-STR
730
- * blah
731
- STR
732
-
733
- expected = [
734
- @RM::Verbatim.new("* blah\n")]
735
-
736
- assert_equal expected, @RMP.parse(str).parts
737
- end
738
-
739
- def test_parse_verbatim_dash
740
- str = <<-STR
741
- - blah
742
- STR
743
-
744
- expected = [
745
- @RM::Verbatim.new("- blah\n")]
746
-
747
- assert_equal expected, @RMP.parse(str).parts
748
- end
749
-
750
- def test_parse_verbatim_fold
751
- str = <<-STR
752
- now is
753
- code
754
-
755
-
756
- code1
757
-
758
- the time
759
- STR
760
-
761
- expected = [
762
- @RM::Paragraph.new('now is'),
763
- @RM::Verbatim.new("code\n", "\n", "code1\n"),
764
- @RM::Paragraph.new('the time'),
765
- ]
766
-
767
- assert_equal expected, @RMP.parse(str).parts
768
- end
769
-
770
- def test_parse_verbatim_heading
771
- str = <<-STR
772
- text
773
- === heading three
774
- STR
775
-
776
- expected = [
777
- @RM::Paragraph.new('text'),
778
- @RM::Verbatim.new("=== heading three\n")]
779
-
780
- assert_equal expected, @RMP.parse(str).parts
781
- end
782
-
783
- def test_parse_verbatim_heading2
784
- str = "text\n code\n=== heading three"
785
-
786
- expected = [
787
- @RM::Paragraph.new('text'),
788
- @RM::Verbatim.new("code\n"),
789
- @RM::Heading.new(3, 'heading three')]
790
-
791
- assert_equal expected, @RMP.parse(str).parts
792
- end
793
-
794
- def test_parse_verbatim_label
795
- str = <<-STR
796
- [blah] blah
797
- STR
798
-
799
- expected = [
800
- @RM::Verbatim.new("[blah] blah\n")]
801
-
802
- assert_equal expected, @RMP.parse(str).parts
803
- end
804
-
805
- def test_parse_verbatim_lalpha
806
- str = <<-STR
807
- b. blah
808
- STR
809
-
810
- expected = [
811
- @RM::Verbatim.new("b. blah\n")]
812
-
813
- assert_equal expected, @RMP.parse(str).parts
814
- end
815
-
816
- def test_parse_verbatim_markup_example
817
- str = <<-STR
818
- text
819
- code
820
- === heading three
821
- STR
822
-
823
- expected = [
824
- @RM::Paragraph.new('text'),
825
- @RM::Verbatim.new("code\n", "=== heading three\n")]
826
-
827
- assert_equal expected, @RMP.parse(str).parts
828
- end
829
-
830
- def test_parse_verbatim_merge
831
- str = <<-STR
832
- now is
833
- code
834
-
835
- code1
836
- the time
837
- STR
838
-
839
- expected = [
840
- @RM::Paragraph.new('now is'),
841
- @RM::Verbatim.new("code\n", "\n", "code1\n"),
842
- @RM::Paragraph.new('the time'),
843
- ]
844
-
845
- assert_equal expected, @RMP.parse(str).parts
846
- end
847
-
848
- def test_parse_verbatim_merge2
849
- str = <<-STR
850
- now is
851
- code
852
-
853
- code1
854
-
855
- code2
856
- the time
857
- STR
858
-
859
- expected = [
860
- @RM::Paragraph.new('now is'),
861
- @RM::Verbatim.new("code\n", "\n", "code1\n", "\n", "code2\n"),
862
- @RM::Paragraph.new('the time'),
863
- ]
864
-
865
- assert_equal expected, @RMP.parse(str).parts
866
- end
867
-
868
- def test_parse_verbatim_multiline
869
- str = <<-STR
870
- now is
871
- code
872
- code1
873
- the time
874
- STR
875
-
876
- expected = [
877
- @RM::Paragraph.new('now is'),
878
- @RM::Verbatim.new("code\n", "code1\n"),
879
- @RM::Paragraph.new('the time'),
880
- ]
881
-
882
- assert_equal expected, @RMP.parse(str).parts
883
- end
884
-
885
- def test_parse_verbatim_multilevel
886
- str = <<-STR
887
- now is the time
888
- code
889
- more code
890
- for all good men
891
- STR
892
-
893
- expected = [
894
- @RM::Paragraph.new('now is the time'),
895
- @RM::Verbatim.new(" code\n",
896
- "more code\n"),
897
- @RM::Paragraph.new('for all good men'),
898
- ]
899
-
900
- assert_equal expected, @RMP.parse(str).parts
901
- end
902
-
903
- def test_parse_verbatim_note
904
- str = <<-STR
905
- blah:: blah
906
- STR
907
-
908
- expected = [
909
- @RM::Verbatim.new("blah:: blah\n")]
910
-
911
- assert_equal expected, @RMP.parse(str).parts
912
- end
913
-
914
- def test_parse_verbatim_number
915
- str = <<-STR
916
- 2. blah
917
- STR
918
-
919
- expected = [
920
- @RM::Verbatim.new("2. blah\n")]
921
-
922
- assert_equal expected, @RMP.parse(str).parts
923
- end
924
-
925
- def test_parse_verbatim_rule
926
- str = <<-STR
927
- text
928
-
929
- --- lib/blah.rb.orig
930
- +++ lib/blah.rb
931
- STR
932
-
933
- expected = [
934
- @RM::Paragraph.new('text'),
935
- @RM::BlankLine.new,
936
- @RM::Verbatim.new("--- lib/blah.rb.orig\n",
937
- "+++ lib/blah.rb\n")]
938
-
939
- assert_equal expected, @RMP.parse(str).parts
940
- end
941
-
942
- def test_parse_verbatim_rule2
943
- str = <<-STR.chomp
944
- text
945
-
946
- ---
947
- STR
948
-
949
- expected = [
950
- @RM::Paragraph.new('text'),
951
- @RM::BlankLine.new,
952
- @RM::Verbatim.new("---")]
953
-
954
- assert_equal expected, @RMP.parse(str).parts
955
- end
956
-
957
- def test_parse_verbatim_trim
958
- str = <<-STR
959
- now is
960
- code
961
-
962
- code1
963
-
964
- the time
965
- STR
966
-
967
- expected = [
968
- @RM::Paragraph.new('now is'),
969
- @RM::Verbatim.new("code\n",
970
- "\n",
971
- "code1\n"),
972
- @RM::Paragraph.new('the time'),
973
- ]
974
-
975
- assert_equal expected, @RMP.parse(str).parts
976
- end
977
-
978
- def test_parse_verbatim_ualpha
979
- str = <<-STR
980
- B. blah
981
- STR
982
-
983
- expected = [
984
- @RM::Verbatim.new("B. blah\n")]
985
-
986
- assert_equal expected, @RMP.parse(str).parts
987
- end
988
-
989
- def test_parse_whitespace
990
- expected = [
991
- @RM::Paragraph.new('hello'),
992
- ]
993
-
994
- assert_equal expected, @RMP.parse('hello').parts
995
-
996
- expected = [
997
- @RM::Verbatim.new('hello '),
998
- ]
999
-
1000
- assert_equal expected, @RMP.parse(' hello ').parts
1001
-
1002
- expected = [
1003
- @RM::Verbatim.new('hello '),
1004
- ]
1005
-
1006
- assert_equal expected, @RMP.parse(' hello ').parts
1007
-
1008
- expected = [
1009
- @RM::Paragraph.new('1'),
1010
- @RM::Verbatim.new("2\n", ' 3'),
1011
- ]
1012
-
1013
- assert_equal expected, @RMP.parse("1\n 2\n 3").parts
1014
-
1015
- expected = [
1016
- @RM::Verbatim.new("1\n",
1017
- " 2\n",
1018
- " 3"),
1019
- ]
1020
-
1021
- assert_equal expected, @RMP.parse(" 1\n 2\n 3").parts
1022
-
1023
- expected = [
1024
- @RM::Paragraph.new('1'),
1025
- @RM::Verbatim.new("2\n",
1026
- " 3\n"),
1027
- @RM::Paragraph.new('1'),
1028
- @RM::Verbatim.new('2'),
1029
- ]
1030
-
1031
- assert_equal expected, @RMP.parse("1\n 2\n 3\n1\n 2").parts
1032
-
1033
- expected = [
1034
- @RM::Verbatim.new("1\n",
1035
- " 2\n",
1036
- " 3\n",
1037
- "1\n",
1038
- ' 2'),
1039
- ]
1040
-
1041
- assert_equal expected, @RMP.parse(" 1\n 2\n 3\n 1\n 2").parts
1042
-
1043
- expected = [
1044
- @RM::Verbatim.new("1\n",
1045
- " 2\n",
1046
- "\n",
1047
- ' 3'),
1048
- ]
1049
-
1050
- assert_equal expected, @RMP.parse(" 1\n 2\n\n 3").parts
1051
- end
1052
-
1053
- def test_peek_token
1054
- parser = util_parser
1055
-
1056
- assert_equal [:HEADER, 1, 0, 0], parser.peek_token
1057
-
1058
- assert_equal 8, parser.tokens.length
1059
- end
1060
-
1061
- def test_skip
1062
- parser = util_parser
1063
-
1064
- assert_equal [:HEADER, 1, 0, 0], parser.skip(:HEADER)
1065
-
1066
- assert_equal [:TEXT, 'Heading', 2, 0], parser.get
1067
-
1068
- assert_equal [:NEWLINE, "\n", 9, 0], parser.peek_token
1069
-
1070
- assert_raises RDoc::Markup::Parser::ParseError do
1071
- parser.skip :NONE
1072
- end
1073
-
1074
- assert_equal [:NEWLINE, "\n", 9, 0], parser.peek_token
1075
-
1076
- assert_equal nil, parser.skip(:NONE, false)
1077
-
1078
- assert_equal [:NEWLINE, "\n", 9, 0], parser.peek_token
1079
- end
1080
-
1081
- def test_tokenize_bullet
1082
- str = <<-STR
1083
- * l1
1084
- STR
1085
-
1086
- expected = [
1087
- [:BULLET, '*', 0, 0],
1088
- [:TEXT, 'l1', 2, 0],
1089
- [:NEWLINE, "\n", 4, 0],
1090
- ]
1091
-
1092
- assert_equal expected, @RMP.tokenize(str)
1093
- end
1094
-
1095
- def test_tokenize_bullet_indent
1096
- str = <<-STR
1097
- * l1
1098
- * l1.1
1099
- STR
1100
-
1101
- expected = [
1102
- [:BULLET, '*', 0, 0],
1103
- [:TEXT, 'l1', 2, 0],
1104
- [:NEWLINE, "\n", 4, 0],
1105
- [:BULLET, '*', 2, 1],
1106
- [:TEXT, 'l1.1', 4, 1],
1107
- [:NEWLINE, "\n", 8, 1],
1108
- ]
1109
-
1110
- assert_equal expected, @RMP.tokenize(str)
1111
- end
1112
-
1113
- def test_tokenize_heading
1114
- str = <<-STR
1115
- = Heading
1116
- == Heading 2
1117
- STR
1118
-
1119
- expected = [
1120
- [:HEADER, 1, 0, 0],
1121
- [:TEXT, 'Heading', 2, 0],
1122
- [:NEWLINE, "\n", 9, 0],
1123
- [:HEADER, 2, 0, 1],
1124
- [:TEXT, 'Heading 2', 3, 1],
1125
- [:NEWLINE, "\n", 12, 1],
1126
- ]
1127
-
1128
- assert_equal expected, @RMP.tokenize(str)
1129
- end
1130
-
1131
- def test_tokenize_heading_empty
1132
- str = <<-STR
1133
- ===
1134
- * bullet
1135
- STR
1136
-
1137
- expected = [
1138
- [:HEADER, 3, 0, 0],
1139
- [:NEWLINE, "\n", 3, 0],
1140
- [:BULLET, "*", 0, 1],
1141
- [:TEXT, "bullet", 2, 1],
1142
- [:NEWLINE, "\n", 8, 1],
1143
- ]
1144
-
1145
- assert_equal expected, @RMP.tokenize(str)
1146
- end
1147
-
1148
- def test_tokenize_heading_heading
1149
- str = <<-STR
1150
- = =
1151
- STR
1152
-
1153
- expected = [
1154
- [:HEADER, 1, 0, 0],
1155
- [:TEXT, '=', 2, 0],
1156
- [:NEWLINE, "\n", 3, 0],
1157
- ]
1158
-
1159
- assert_equal expected, @RMP.tokenize(str)
1160
- end
1161
-
1162
- def test_tokenize_heading_no_space
1163
- str = <<-STR
1164
- =Heading
1165
- ==Heading 2
1166
- STR
1167
-
1168
- expected = [
1169
- [:HEADER, 1, 0, 0],
1170
- [:TEXT, 'Heading', 1, 0],
1171
- [:NEWLINE, "\n", 8, 0],
1172
- [:HEADER, 2, 0, 1],
1173
- [:TEXT, 'Heading 2', 2, 1],
1174
- [:NEWLINE, "\n", 11, 1],
1175
- ]
1176
-
1177
- assert_equal expected, @RMP.tokenize(str)
1178
- end
1179
-
1180
- def test_tokenize_label
1181
- str = <<-STR
1182
- [cat] l1
1183
- [dog] l1.1
1184
- STR
1185
-
1186
- expected = [
1187
- [:LABEL, 'cat', 0, 0],
1188
- [:TEXT, 'l1', 6, 0],
1189
- [:NEWLINE, "\n", 8, 0],
1190
- [:LABEL, 'dog', 0, 1],
1191
- [:TEXT, 'l1.1', 6, 1],
1192
- [:NEWLINE, "\n", 10, 1],
1193
- ]
1194
-
1195
- assert_equal expected, @RMP.tokenize(str)
1196
- end
1197
-
1198
- def test_tokenize_label_note
1199
- str = <<-STR
1200
- [label]
1201
- note::
1202
- STR
1203
-
1204
- expected = [
1205
- [:LABEL, 'label', 0, 0],
1206
- [:NEWLINE, "\n", 7, 0],
1207
- [:NOTE, 'note', 2, 1],
1208
- [:NEWLINE, "\n", 8, 1],
1209
- ]
1210
-
1211
- assert_equal expected, @RMP.tokenize(str)
1212
- end
1213
-
1214
- def test_tokenize_label_newline
1215
- str = <<-STR
1216
- [cat]
1217
- l1
1218
- STR
1219
-
1220
- expected = [
1221
- [:LABEL, 'cat', 0, 0],
1222
- [:NEWLINE, "\n", 5, 0],
1223
- [:TEXT, 'l1', 2, 1],
1224
- [:NEWLINE, "\n", 4, 1],
1225
- ]
1226
-
1227
- assert_equal expected, @RMP.tokenize(str)
1228
- end
1229
-
1230
- def test_tokenize_label_newline_windows
1231
- str = <<-STR
1232
- [cat]\r
1233
- l1\r
1234
- STR
1235
-
1236
- expected = [
1237
- [:LABEL, 'cat', 0, 0],
1238
- [:NEWLINE, "\n", 6, 0],
1239
- [:TEXT, 'l1', 2, 1],
1240
- [:NEWLINE, "\n", 5, 1],
1241
- ]
1242
-
1243
- assert_equal expected, @RMP.tokenize(str)
1244
- end
1245
-
1246
- def test_tokenize_lalpha
1247
- str = <<-STR
1248
- a. l1
1249
- b. l1.1
1250
- STR
1251
-
1252
- expected = [
1253
- [:LALPHA, 'a', 0, 0],
1254
- [:TEXT, 'l1', 3, 0],
1255
- [:NEWLINE, "\n", 5, 0],
1256
- [:LALPHA, 'b', 0, 1],
1257
- [:TEXT, 'l1.1', 3, 1],
1258
- [:NEWLINE, "\n", 7, 1],
1259
- ]
1260
-
1261
- assert_equal expected, @RMP.tokenize(str)
1262
- end
1263
-
1264
- def test_tokenize_line_break
1265
- str = "now is\nthe time \nfor all\n"
1266
-
1267
- expected = [
1268
- [:TEXT, 'now is', 0, 0],
1269
- [:NEWLINE, "\n", 6, 0],
1270
- [:TEXT, 'the time', 0, 1],
1271
- [:BREAK, " ", 8, 1],
1272
- [:NEWLINE, "\n", 10, 1],
1273
- [:TEXT, 'for all', 0, 2],
1274
- [:NEWLINE, "\n", 7, 2],
1275
- ]
1276
-
1277
- assert_equal expected, @RMP.tokenize(str)
1278
- end
1279
-
1280
- def test_tokenize_line_break_long
1281
- str = "now is\nthe time \nfor all\n"
1282
-
1283
- expected = [
1284
- [:TEXT, 'now is', 0, 0],
1285
- [:NEWLINE, "\n", 6, 0],
1286
- [:TEXT, 'the time ', 0, 1],
1287
- [:BREAK, ' ', 9, 1],
1288
- [:NEWLINE, "\n", 11, 1],
1289
- [:TEXT, 'for all', 0, 2],
1290
- [:NEWLINE, "\n", 7, 2],
1291
- ]
1292
-
1293
- assert_equal expected, @RMP.tokenize(str)
1294
- end
1295
-
1296
- def test_tokenize_line_break_no_short
1297
- str = "now is\nthe time \nfor all\n"
1298
-
1299
- expected = [
1300
- [:TEXT, 'now is', 0, 0],
1301
- [:NEWLINE, "\n", 6, 0],
1302
- [:TEXT, 'the time ', 0, 1],
1303
- [:NEWLINE, "\n", 9, 1],
1304
- [:TEXT, 'for all', 0, 2],
1305
- [:NEWLINE, "\n", 7, 2],
1306
- ]
1307
-
1308
- assert_equal expected, @RMP.tokenize(str)
1309
- end
1310
-
1311
- def test_tokenize_note
1312
- str = <<-STR
1313
- cat:: l1
1314
- dog:: l1.1
1315
- STR
1316
-
1317
- expected = [
1318
- [:NOTE, 'cat', 0, 0],
1319
- [:TEXT, 'l1', 6, 0],
1320
- [:NEWLINE, "\n", 8, 0],
1321
- [:NOTE, 'dog', 0, 1],
1322
- [:TEXT, 'l1.1', 6, 1],
1323
- [:NEWLINE, "\n", 10, 1],
1324
- ]
1325
-
1326
- assert_equal expected, @RMP.tokenize(str)
1327
- end
1328
-
1329
- def test_tokenize_note_empty
1330
- str = <<-STR
1331
- cat::
1332
- dog::
1333
- STR
1334
-
1335
- expected = [
1336
- [:NOTE, 'cat', 0, 0],
1337
- [:NEWLINE, "\n", 5, 0],
1338
- [:NOTE, 'dog', 0, 1],
1339
- [:NEWLINE, "\n", 5, 1],
1340
- ]
1341
-
1342
- assert_equal expected, @RMP.tokenize(str)
1343
- end
1344
-
1345
- def test_tokenize_note_newline
1346
- str = <<-STR
1347
- cat::
1348
- l1
1349
- STR
1350
-
1351
- expected = [
1352
- [:NOTE, 'cat', 0, 0],
1353
- [:NEWLINE, "\n", 5, 0],
1354
- [:TEXT, 'l1', 2, 1],
1355
- [:NEWLINE, "\n", 4, 1],
1356
- ]
1357
-
1358
- assert_equal expected, @RMP.tokenize(str)
1359
- end
1360
-
1361
- def test_tokenize_note_utf_8
1362
- skip 'Encoding not implemented' unless @have_encoding
1363
-
1364
- str = <<-STR
1365
- cät:: l1a
1366
- l1b
1367
- døg:: l2a
1368
- l2b
1369
- STR
1370
-
1371
- expected = [
1372
- [:NOTE, 'cät', 0, 0],
1373
- [:TEXT, 'l1a', 6, 0],
1374
- [:NEWLINE, "\n", 9, 0],
1375
- [:TEXT, 'l1b', 6, 1],
1376
- [:NEWLINE, "\n", 9, 1],
1377
- [:NOTE, 'døg', 0, 2],
1378
- [:TEXT, 'l2a', 6, 2],
1379
- [:NEWLINE, "\n", 9, 2],
1380
- [:TEXT, 'l2b', 6, 3],
1381
- [:NEWLINE, "\n", 9, 3],
1382
- ]
1383
-
1384
- assert_equal expected, @RMP.tokenize(str)
1385
- end
1386
-
1387
- def test_tokenize_note_newline_windows
1388
- str = <<-STR
1389
- cat::\r
1390
- l1\r
1391
- STR
1392
-
1393
- expected = [
1394
- [:NOTE, 'cat', 0, 0],
1395
- [:NEWLINE, "\n", 6, 0],
1396
- [:TEXT, 'l1', 2, 1],
1397
- [:NEWLINE, "\n", 5, 1],
1398
- ]
1399
-
1400
- assert_equal expected, @RMP.tokenize(str)
1401
- end
1402
-
1403
- def test_tokenize_note_not
1404
- str = <<-STR
1405
- Cat::Dog
1406
- STR
1407
-
1408
- expected = [
1409
- [:TEXT, 'Cat::Dog', 0, 0],
1410
- [:NEWLINE, "\n", 8, 0],
1411
- ]
1412
-
1413
- assert_equal expected, @RMP.tokenize(str)
1414
- end
1415
-
1416
- def test_tokenize_number
1417
- str = <<-STR
1418
- 1. l1
1419
- 2. l1.1
1420
- STR
1421
-
1422
- expected = [
1423
- [:NUMBER, '1', 0, 0],
1424
- [:TEXT, 'l1', 3, 0],
1425
- [:NEWLINE, "\n", 5, 0],
1426
- [:NUMBER, '2', 0, 1],
1427
- [:TEXT, 'l1.1', 3, 1],
1428
- [:NEWLINE, "\n", 7, 1],
1429
- ]
1430
-
1431
- assert_equal expected, @RMP.tokenize(str)
1432
- end
1433
-
1434
- def test_tokenize_number_period
1435
- str = <<-STR
1436
- 1. blah blah blah
1437
- l.
1438
- 2. blah blah blah blah
1439
- d.
1440
- STR
1441
-
1442
- expected = [
1443
- [:NUMBER, "1", 0, 0],
1444
- [:TEXT, "blah blah blah", 3, 0],
1445
- [:NEWLINE, "\n", 17, 0],
1446
-
1447
- [:TEXT, "l.", 3, 1],
1448
- [:NEWLINE, "\n", 5, 1],
1449
-
1450
- [:NUMBER, "2", 0, 2],
1451
- [:TEXT, "blah blah blah blah", 3, 2],
1452
- [:NEWLINE, "\n", 22, 2],
1453
-
1454
- [:TEXT, "d.", 3, 3],
1455
- [:NEWLINE, "\n", 5, 3]
1456
- ]
1457
-
1458
- assert_equal expected, @RMP.tokenize(str)
1459
- end
1460
-
1461
- def test_tokenize_number_period_continue
1462
- str = <<-STR
1463
- 1. blah blah blah
1464
- l. more stuff
1465
- 2. blah blah blah blah
1466
- d. other stuff
1467
- STR
1468
-
1469
- expected = [
1470
- [:NUMBER, "1", 0, 0],
1471
- [:TEXT, "blah blah blah", 3, 0],
1472
- [:NEWLINE, "\n", 17, 0],
1473
-
1474
- [:LALPHA, "l", 3, 1],
1475
- [:TEXT, "more stuff", 7, 1],
1476
- [:NEWLINE, "\n", 17, 1],
1477
-
1478
- [:NUMBER, "2", 0, 2],
1479
- [:TEXT, "blah blah blah blah", 3, 2],
1480
- [:NEWLINE, "\n", 22, 2],
1481
-
1482
- [:LALPHA, "d", 3, 3],
1483
- [:TEXT, "other stuff", 6, 3],
1484
- [:NEWLINE, "\n", 17, 3]
1485
- ]
1486
-
1487
- assert_equal expected, @RMP.tokenize(str)
1488
- end
1489
-
1490
- def test_tokenize_paragraphs
1491
- str = <<-STR
1492
- now is
1493
- the time
1494
-
1495
- for all
1496
- STR
1497
-
1498
- expected = [
1499
- [:TEXT, 'now is', 0, 0],
1500
- [:NEWLINE, "\n", 6, 0],
1501
- [:TEXT, 'the time', 0, 1],
1502
- [:NEWLINE, "\n", 8, 1],
1503
- [:NEWLINE, "\n", 0, 2],
1504
- [:TEXT, 'for all', 0, 3],
1505
- [:NEWLINE, "\n", 7, 3],
1506
- ]
1507
-
1508
- assert_equal expected, @RMP.tokenize(str)
1509
- end
1510
-
1511
- def test_tokenize_rule
1512
- str = <<-STR
1513
- ---
1514
-
1515
- --- blah ---
1516
- STR
1517
-
1518
- expected = [
1519
- [:RULE, 1, 0, 0],
1520
- [:NEWLINE, "\n", 3, 0],
1521
- [:NEWLINE, "\n", 0, 1],
1522
- [:TEXT, "--- blah ---", 0, 2],
1523
- [:NEWLINE, "\n", 12, 2],
1524
- ]
1525
-
1526
- assert_equal expected, @RMP.tokenize(str)
1527
- end
1528
-
1529
- def test_tokenize_rule_windows
1530
- str = <<-STR
1531
- ---\r
1532
-
1533
- --- blah ---\r
1534
- STR
1535
-
1536
- expected = [
1537
- [:RULE, 1, 0, 0],
1538
- [:NEWLINE, "\n", 4, 0],
1539
- [:NEWLINE, "\n", 0, 1],
1540
- [:TEXT, "--- blah ---", 0, 2],
1541
- [:NEWLINE, "\n", 13, 2],
1542
- ]
1543
-
1544
- assert_equal expected, @RMP.tokenize(str)
1545
- end
1546
-
1547
- def test_tokenize_ualpha
1548
- str = <<-STR
1549
- A. l1
1550
- B. l1.1
1551
- STR
1552
-
1553
- expected = [
1554
- [:UALPHA, 'A', 0, 0],
1555
- [:TEXT, 'l1', 3, 0],
1556
- [:NEWLINE, "\n", 5, 0],
1557
- [:UALPHA, 'B', 0, 1],
1558
- [:TEXT, 'l1.1', 3, 1],
1559
- [:NEWLINE, "\n", 7, 1],
1560
- ]
1561
-
1562
- assert_equal expected, @RMP.tokenize(str)
1563
- end
1564
-
1565
- def test_tokenize_verbatim_heading
1566
- str = <<-STR
1567
- Example heading:
1568
-
1569
- === heading three
1570
- STR
1571
-
1572
- expected = [
1573
- [:TEXT, 'Example heading:', 0, 0],
1574
- [:NEWLINE, "\n", 16, 0],
1575
- [:NEWLINE, "\n", 0, 1],
1576
- [:HEADER, 3, 3, 2],
1577
- [:TEXT, 'heading three', 7, 2],
1578
- [:NEWLINE, "\n", 20, 2],
1579
- ]
1580
-
1581
- assert_equal expected, @RMP.tokenize(str)
1582
- end
1583
-
1584
- def test_tokenize_verbatim_rule
1585
- str = <<-STR
1586
- Verbatim section here that is double-underlined
1587
- ===============================================
1588
- STR
1589
-
1590
- expected = [
1591
- [:TEXT, 'Verbatim section here that is double-underlined', 2, 0],
1592
- [:NEWLINE, "\n", 49, 0],
1593
- [:HEADER, 47, 2, 1],
1594
- [:NEWLINE, "\n", 49, 1],
1595
- ]
1596
-
1597
- assert_equal expected, @RMP.tokenize(str)
1598
- end
1599
-
1600
- def test_tokenize_verbatim_rule_fancy
1601
- str = <<-STR
1602
- A
1603
- b
1604
- ===============================================
1605
- c
1606
- STR
1607
-
1608
- expected = [
1609
- [:TEXT, 'A', 2, 0],
1610
- [:NEWLINE, "\n", 3, 0],
1611
- [:TEXT, 'b', 4, 1],
1612
- [:NEWLINE, "\n", 5, 1],
1613
- [:HEADER, 47, 2, 2],
1614
- [:NEWLINE, "\n", 49, 2],
1615
- [:TEXT, 'c', 4, 3],
1616
- [:NEWLINE, "\n", 5, 3],
1617
- ]
1618
-
1619
- assert_equal expected, @RMP.tokenize(str)
1620
- end
1621
-
1622
- def test_token_pos
1623
- parser = @RMP.new
1624
- s = parser.setup_scanner 'cät'
1625
-
1626
- s.scan(/\S+/)
1627
-
1628
- if @have_encoding or @have_byteslice then
1629
- assert_equal [3, 0], parser.token_pos(s.pos)
1630
- else
1631
- assert_equal [4, 0], parser.token_pos(s.pos)
1632
- end
1633
- end
1634
-
1635
- # HACK move to Verbatim test case
1636
- def test_verbatim_normalize
1637
- v = @RM::Verbatim.new "foo\n", "\n", "\n", "bar\n"
1638
-
1639
- v.normalize
1640
-
1641
- assert_equal ["foo\n", "\n", "bar\n"], v.parts
1642
-
1643
- v = @RM::Verbatim.new "foo\n", "\n"
1644
-
1645
- v.normalize
1646
-
1647
- assert_equal ["foo\n"], v.parts
1648
- end
1649
-
1650
- def test_unget
1651
- parser = util_parser
1652
-
1653
- parser.get
1654
-
1655
- parser.unget
1656
-
1657
- assert_equal [:HEADER, 1, 0, 0], parser.peek_token
1658
-
1659
- assert_raises @RMP::Error do
1660
- parser.unget
1661
- end
1662
-
1663
- assert_equal 8, parser.tokens.length
1664
- end
1665
-
1666
- def util_parser
1667
- str = <<-STR
1668
- = Heading
1669
-
1670
- Some text here
1671
- some more text over here
1672
- STR
1673
-
1674
- @parser = @RMP.new
1675
- @parser.tokenize str
1676
- @parser
1677
- end
1678
-
1679
- end
1680
-