rdoc 2.4.3 → 2.5

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 (139) hide show
  1. data.tar.gz.sig +0 -0
  2. data/.autotest +3 -1
  3. data/History.txt +68 -0
  4. data/LICENSE.txt +57 -0
  5. data/Manifest.txt +37 -19
  6. data/README.txt +2 -12
  7. data/Rakefile +12 -12
  8. data/bin/rdoc +4 -4
  9. data/lib/rdoc.rb +32 -9
  10. data/lib/rdoc/alias.rb +2 -2
  11. data/lib/rdoc/any_method.rb +108 -16
  12. data/lib/rdoc/attr.rb +87 -1
  13. data/lib/rdoc/class_module.rb +131 -5
  14. data/lib/rdoc/code_object.rb +28 -5
  15. data/lib/rdoc/constant.rb +22 -0
  16. data/lib/rdoc/context.rb +80 -37
  17. data/lib/rdoc/gauntlet.rb +48 -0
  18. data/lib/rdoc/generator/darkfish.rb +25 -23
  19. data/lib/rdoc/generator/markup.rb +6 -29
  20. data/lib/rdoc/generator/ri.rb +39 -189
  21. data/lib/rdoc/generator/template/darkfish/classpage.rhtml +17 -1
  22. data/lib/rdoc/generator/template/darkfish/filepage.rhtml +10 -0
  23. data/lib/rdoc/generator/template/darkfish/images/brick.png +0 -0
  24. data/lib/rdoc/generator/template/darkfish/images/brick_link.png +0 -0
  25. data/lib/rdoc/generator/template/darkfish/images/bullet_black.png +0 -0
  26. data/lib/rdoc/generator/template/darkfish/images/bullet_toggle_minus.png +0 -0
  27. data/lib/rdoc/generator/template/darkfish/images/bullet_toggle_plus.png +0 -0
  28. data/lib/rdoc/generator/template/darkfish/images/date.png +0 -0
  29. data/lib/rdoc/generator/template/darkfish/images/find.png +0 -0
  30. data/lib/rdoc/generator/template/darkfish/images/package.png +0 -0
  31. data/lib/rdoc/generator/template/darkfish/images/page_green.png +0 -0
  32. data/lib/rdoc/generator/template/darkfish/images/page_white_text.png +0 -0
  33. data/lib/rdoc/generator/template/darkfish/images/page_white_width.png +0 -0
  34. data/lib/rdoc/generator/template/darkfish/images/plugin.png +0 -0
  35. data/lib/rdoc/generator/template/darkfish/images/ruby.png +0 -0
  36. data/lib/rdoc/generator/template/darkfish/images/tag_green.png +0 -0
  37. data/lib/rdoc/generator/template/darkfish/images/wrench.png +0 -0
  38. data/lib/rdoc/generator/template/darkfish/images/wrench_orange.png +0 -0
  39. data/lib/rdoc/generator/template/darkfish/images/zoom.png +0 -0
  40. data/lib/rdoc/generator/template/darkfish/index.rhtml +2 -2
  41. data/lib/rdoc/generator/template/darkfish/rdoc.css +38 -33
  42. data/lib/rdoc/include.rb +22 -0
  43. data/lib/rdoc/markup.rb +10 -262
  44. data/lib/rdoc/markup/attribute_manager.rb +57 -50
  45. data/lib/rdoc/markup/blank_line.rb +19 -0
  46. data/lib/rdoc/markup/document.rb +72 -0
  47. data/lib/rdoc/markup/formatter.rb +118 -0
  48. data/lib/rdoc/markup/formatter_test_case.rb +341 -0
  49. data/lib/rdoc/markup/heading.rb +17 -0
  50. data/lib/rdoc/markup/inline.rb +6 -5
  51. data/lib/rdoc/markup/list.rb +78 -0
  52. data/lib/rdoc/markup/list_item.rb +83 -0
  53. data/lib/rdoc/markup/paragraph.rb +66 -0
  54. data/lib/rdoc/markup/parser.rb +528 -0
  55. data/lib/rdoc/markup/rule.rb +17 -0
  56. data/lib/rdoc/markup/to_ansi.rb +72 -0
  57. data/lib/rdoc/markup/to_bs.rb +74 -0
  58. data/lib/rdoc/markup/to_html.rb +106 -172
  59. data/lib/rdoc/markup/to_html_crossref.rb +10 -4
  60. data/lib/rdoc/markup/to_rdoc.rb +243 -0
  61. data/lib/rdoc/markup/to_test.rb +27 -16
  62. data/lib/rdoc/markup/verbatim.rb +42 -0
  63. data/lib/rdoc/normal_class.rb +38 -1
  64. data/lib/rdoc/normal_module.rb +38 -8
  65. data/lib/rdoc/options.rb +39 -151
  66. data/lib/rdoc/parser.rb +36 -18
  67. data/lib/rdoc/parser/c.rb +102 -109
  68. data/lib/rdoc/parser/ruby.rb +359 -1662
  69. data/lib/rdoc/parser/ruby_tools.rb +157 -0
  70. data/lib/rdoc/parser/simple.rb +0 -2
  71. data/lib/rdoc/rdoc.rb +142 -82
  72. data/lib/rdoc/ri.rb +10 -0
  73. data/lib/rdoc/ri/driver.rb +674 -444
  74. data/lib/rdoc/ri/formatter.rb +2 -651
  75. data/lib/rdoc/ri/paths.rb +70 -45
  76. data/lib/rdoc/ri/store.rb +248 -0
  77. data/lib/rdoc/ruby_lex.rb +1284 -0
  78. data/lib/rdoc/ruby_token.rb +416 -0
  79. data/lib/rdoc/single_class.rb +5 -0
  80. data/lib/rdoc/stats.rb +152 -83
  81. data/lib/rdoc/task.rb +27 -49
  82. data/lib/rdoc/text.rb +130 -0
  83. data/lib/rdoc/tokenstream.rb +28 -9
  84. data/lib/rdoc/top_level.rb +49 -43
  85. data/test/hidden.zip.txt +1 -0
  86. data/test/test_attribute_manager.rb +9 -16
  87. data/test/test_rdoc_any_method.rb +23 -0
  88. data/test/test_rdoc_attr.rb +40 -0
  89. data/test/test_rdoc_class_module.rb +100 -0
  90. data/test/test_rdoc_code_object.rb +18 -2
  91. data/test/test_rdoc_context.rb +41 -0
  92. data/test/test_rdoc_generator_ri.rb +56 -0
  93. data/test/test_rdoc_markup.rb +21 -610
  94. data/test/test_rdoc_markup_attribute_manager.rb +14 -17
  95. data/test/test_rdoc_markup_document.rb +51 -0
  96. data/test/test_rdoc_markup_paragraph.rb +27 -0
  97. data/test/test_rdoc_markup_parser.rb +1327 -0
  98. data/test/test_rdoc_markup_to_ansi.rb +426 -0
  99. data/test/test_rdoc_markup_to_bs.rb +443 -0
  100. data/test/test_rdoc_markup_to_html.rb +183 -18
  101. data/test/test_rdoc_markup_to_html_crossref.rb +1 -3
  102. data/test/test_rdoc_markup_to_rdoc.rb +426 -0
  103. data/test/test_rdoc_normal_class.rb +17 -0
  104. data/test/test_rdoc_normal_module.rb +6 -6
  105. data/test/test_rdoc_options.rb +41 -0
  106. data/test/test_rdoc_parser.rb +66 -13
  107. data/test/test_rdoc_parser_c.rb +93 -38
  108. data/test/test_rdoc_parser_perl.rb +2 -3
  109. data/test/test_rdoc_parser_ruby.rb +291 -28
  110. data/test/test_rdoc_parser_simple.rb +48 -0
  111. data/test/test_rdoc_rdoc.rb +66 -0
  112. data/test/test_rdoc_ri_driver.rb +752 -38
  113. data/test/test_rdoc_ri_paths.rb +39 -0
  114. data/test/test_rdoc_ri_store.rb +309 -0
  115. data/test/test_rdoc_text.rb +157 -0
  116. data/test/test_rdoc_top_level.rb +35 -9
  117. data/test/xref_data.rb +9 -1
  118. data/test/xref_test_case.rb +8 -3
  119. metadata +110 -38
  120. metadata.gz.sig +0 -0
  121. data/lib/rdoc/cache.rb +0 -41
  122. data/lib/rdoc/diagram.rb +0 -340
  123. data/lib/rdoc/dot.rb +0 -249
  124. data/lib/rdoc/markup/fragments.rb +0 -377
  125. data/lib/rdoc/markup/lines.rb +0 -156
  126. data/lib/rdoc/markup/to_flow.rb +0 -211
  127. data/lib/rdoc/markup/to_latex.rb +0 -328
  128. data/lib/rdoc/markup/to_texinfo.rb +0 -73
  129. data/lib/rdoc/ri/cache.rb +0 -187
  130. data/lib/rdoc/ri/descriptions.rb +0 -156
  131. data/lib/rdoc/ri/display.rb +0 -340
  132. data/lib/rdoc/ri/reader.rb +0 -106
  133. data/lib/rdoc/ri/util.rb +0 -79
  134. data/lib/rdoc/ri/writer.rb +0 -68
  135. data/test/test_rdoc_ri_attribute_formatter.rb +0 -44
  136. data/test/test_rdoc_ri_default_display.rb +0 -302
  137. data/test/test_rdoc_ri_formatter.rb +0 -320
  138. data/test/test_rdoc_ri_html_formatter.rb +0 -141
  139. data/test/test_rdoc_ri_overstrike_formatter.rb +0 -71
@@ -1,14 +1,13 @@
1
1
  require "rubygems"
2
- require "minitest/unit"
2
+ require "minitest/autorun"
3
+ require 'rdoc'
4
+ require 'rdoc/markup'
3
5
  require "rdoc/markup/inline"
4
6
  require "rdoc/markup/to_html_crossref"
5
7
 
6
8
  class TestRDocMarkupAttributeManager < MiniTest::Unit::TestCase
7
9
 
8
10
  def setup
9
- @orig_special = RDoc::Markup::AttributeManager::SPECIAL
10
- RDoc::Markup::AttributeManager::SPECIAL.replace Hash.new
11
-
12
11
  @am = RDoc::Markup::AttributeManager.new
13
12
 
14
13
  @bold_on = @am.changed_attribute_by_name([], [:BOLD])
@@ -32,10 +31,6 @@ class TestRDocMarkupAttributeManager < MiniTest::Unit::TestCase
32
31
  @wombat_off = @am.changed_attribute_by_name([:WOMBAT], [])
33
32
  end
34
33
 
35
- def teardown
36
- RDoc::Markup::AttributeManager::SPECIAL.replace @orig_special
37
- end
38
-
39
34
  def crossref(text)
40
35
  crossref_bitmap = RDoc::Markup::Attribute.bitmap_for(:_SPECIAL_) |
41
36
  RDoc::Markup::Attribute.bitmap_for(:CROSSREF)
@@ -55,9 +50,9 @@ class TestRDocMarkupAttributeManager < MiniTest::Unit::TestCase
55
50
  def test_add_word_pair
56
51
  @am.add_word_pair '%', '&', 'percent and'
57
52
 
58
- assert RDoc::Markup::AttributeManager::WORD_PAIR_MAP.include?(/(%)(\S+)(&)/)
59
- assert RDoc::Markup::AttributeManager::PROTECTABLE.include?('%')
60
- assert !RDoc::Markup::AttributeManager::PROTECTABLE.include?('&')
53
+ assert @am.word_pair_map.include?(/(%)(\S+)(&)/)
54
+ assert @am.protectable.include?('%')
55
+ assert !@am.protectable.include?('&')
61
56
  end
62
57
 
63
58
  def test_add_word_pair_angle
@@ -71,8 +66,8 @@ class TestRDocMarkupAttributeManager < MiniTest::Unit::TestCase
71
66
  def test_add_word_pair_matching
72
67
  @am.add_word_pair '^', '^', 'caret'
73
68
 
74
- assert RDoc::Markup::AttributeManager::MATCHING_WORD_PAIRS.include?('^')
75
- assert RDoc::Markup::AttributeManager::PROTECTABLE.include?('^')
69
+ assert @am.matching_word_pairs.include?('^')
70
+ assert @am.protectable.include?('^')
76
71
  end
77
72
 
78
73
  def test_basic
@@ -200,14 +195,17 @@ class TestRDocMarkupAttributeManager < MiniTest::Unit::TestCase
200
195
  end
201
196
 
202
197
  def test_protect
203
- assert_equal(['cat \\ dog'], @am.flow('cat \\ dog'))
198
+ assert_equal(['cat \\ dog'],
199
+ @am.flow('cat \\ dog'))
204
200
 
205
- assert_equal(["cat <tt>dog</Tt>"], @am.flow("cat \\<tt>dog</Tt>"))
201
+ assert_equal(["cat <tt>dog</Tt>"],
202
+ @am.flow("cat \\<tt>dog</Tt>"))
206
203
 
207
204
  assert_equal(["cat ", @em_on, "and", @em_off, " <B>dog</b>"],
208
205
  @am.flow("cat <i>and</i> \\<B>dog</b>"))
209
206
 
210
- assert_equal(["*word* or <b>text</b>"], @am.flow("\\*word* or \\<b>text</b>"))
207
+ assert_equal(["*word* or <b>text</b>"],
208
+ @am.flow("\\*word* or \\<b>text</b>"))
211
209
 
212
210
  assert_equal(["_cat_", @em_on, "dog", @em_off],
213
211
  @am.flow("\\_cat_<i>dog</i>"))
@@ -240,4 +238,3 @@ class TestRDocMarkupAttributeManager < MiniTest::Unit::TestCase
240
238
 
241
239
  end
242
240
 
243
- MiniTest::Unit.autorun
@@ -0,0 +1,51 @@
1
+ require 'pp'
2
+ require 'rubygems'
3
+ require 'minitest/autorun'
4
+ require 'rdoc/markup'
5
+
6
+ class TestRDocMarkupDocument < MiniTest::Unit::TestCase
7
+
8
+ def setup
9
+ @RM = RDoc::Markup
10
+ @d = @RM::Document.new
11
+ end
12
+
13
+ def mu_pp obj
14
+ s = ''
15
+ s = PP.pp obj, s
16
+ s.force_encoding Encoding.default_external if defined? Encoding
17
+ s.chomp
18
+ end
19
+
20
+ def test_append
21
+ @d << @RM::Paragraph.new('hi')
22
+
23
+ expected = @RM::Document.new @RM::Paragraph.new('hi')
24
+
25
+ assert_equal expected, @d
26
+ end
27
+
28
+ def test_append_document
29
+ @d << @RM::Document.new
30
+
31
+ assert_empty @d
32
+
33
+ @d << @RM::Document.new(@RM::Paragraph.new('hi'))
34
+
35
+ expected = @RM::Document.new @RM::Paragraph.new('hi'), @RM::BlankLine.new
36
+
37
+ assert_equal expected, @d
38
+ end
39
+
40
+ def test_append_string
41
+ @d << ''
42
+
43
+ assert_empty @d
44
+
45
+ assert_raises ArgumentError do
46
+ @d << 'hi'
47
+ end
48
+ end
49
+
50
+ end
51
+
@@ -0,0 +1,27 @@
1
+ require 'pp'
2
+ require 'rubygems'
3
+ require 'minitest/autorun'
4
+ require 'rdoc/markup'
5
+
6
+ class TestRDocMarkupParagraph < MiniTest::Unit::TestCase
7
+
8
+ def setup
9
+ @RM = RDoc::Markup
10
+ @p = @RM::Paragraph.new
11
+ end
12
+
13
+ def mu_pp obj
14
+ s = ''
15
+ s = PP.pp obj, s
16
+ s.force_encoding Encoding.default_external if defined? Encoding
17
+ s.chomp
18
+ end
19
+
20
+ def test_push
21
+ @p.push 'hi', 'there'
22
+
23
+ assert_equal @RM::Paragraph.new('hi', 'there'), @p
24
+ end
25
+
26
+ end
27
+
@@ -0,0 +1,1327 @@
1
+ require 'pp'
2
+ require 'rubygems'
3
+ require 'minitest/autorun'
4
+ require 'rdoc/markup'
5
+ require 'rdoc/markup/to_test'
6
+
7
+ class TestRDocMarkupParser < MiniTest::Unit::TestCase
8
+
9
+ def setup
10
+ @RM = RDoc::Markup
11
+ @RMP = @RM::Parser
12
+ end
13
+
14
+ def mu_pp(obj)
15
+ s = ''
16
+ s = PP.pp obj, s
17
+ s = s.force_encoding(Encoding.default_external) if defined? Encoding
18
+ s.chomp
19
+ end
20
+
21
+ def test_build_heading
22
+ parser = @RMP.new
23
+
24
+ parser.tokens.replace [
25
+ [:TEXT, 'heading three', 4, 0],
26
+ [:NEWLINE, "\n", 17, 0],
27
+ ]
28
+
29
+ assert_equal @RM::Heading.new(3, 'heading three'), parser.build_heading(3)
30
+ end
31
+
32
+ def test_get
33
+ parser = util_parser
34
+
35
+ assert_equal [:HEADER, 1, 0, 0], parser.get
36
+
37
+ assert_equal 7, parser.tokens.length
38
+ end
39
+
40
+ def test_parse_bullet
41
+ str = <<-STR
42
+ * l1
43
+ * l2
44
+ STR
45
+
46
+ expected = [
47
+ @RM::List.new(:BULLET, *[
48
+ @RM::ListItem.new(nil,
49
+ @RM::Paragraph.new('l1')),
50
+ @RM::ListItem.new(nil,
51
+ @RM::Paragraph.new('l2'))])]
52
+
53
+ assert_equal expected, @RMP.parse(str).parts
54
+ end
55
+
56
+ def test_parse_bullet_verbatim_heading
57
+ str = <<-STR
58
+ * l1
59
+ v
60
+
61
+ = H
62
+ STR
63
+
64
+ expected = [
65
+ @RM::List.new(:BULLET, *[
66
+ @RM::ListItem.new(nil,
67
+ @RM::Paragraph.new('l1'),
68
+ @RM::Verbatim.new(' ', 'v', "\n"))]),
69
+ @RM::Heading.new(1, 'H')]
70
+
71
+ assert_equal expected, @RMP.parse(str).parts
72
+ end
73
+
74
+ def test_parse_bullet_heading
75
+ str = <<-STR
76
+ * = l1
77
+ STR
78
+
79
+ expected = [
80
+ @RM::List.new(:BULLET, *[
81
+ @RM::ListItem.new(nil,
82
+ @RM::Heading.new(1, 'l1'))])]
83
+
84
+ assert_equal expected, @RMP.parse(str).parts
85
+ end
86
+
87
+ def test_parse_bullet_indent
88
+ str = <<-STR
89
+ * l1
90
+ * l1.1
91
+ * l2
92
+ STR
93
+
94
+ expected = [
95
+ @RM::List.new(:BULLET, *[
96
+ @RM::ListItem.new(nil,
97
+ @RM::Paragraph.new('l1'),
98
+ @RM::List.new(:BULLET, *[
99
+ @RM::ListItem.new(nil,
100
+ @RM::Paragraph.new('l1.1'))])),
101
+ @RM::ListItem.new(nil,
102
+ @RM::Paragraph.new('l2'))])]
103
+
104
+ assert_equal expected, @RMP.parse(str).parts
105
+ end
106
+
107
+ def test_parse_bullet_paragraph
108
+ str = <<-STR
109
+ now is
110
+ * l1
111
+ * l2
112
+ the time
113
+ STR
114
+
115
+ expected = [
116
+ @RM::Paragraph.new('now is'),
117
+ @RM::List.new(:BULLET, *[
118
+ @RM::ListItem.new(nil,
119
+ @RM::Paragraph.new('l1')),
120
+ @RM::ListItem.new(nil,
121
+ @RM::Paragraph.new('l2')),
122
+ ]),
123
+ @RM::Paragraph.new('the time'),
124
+ ]
125
+
126
+ assert_equal expected, @RMP.parse(str).parts
127
+ end
128
+
129
+ def test_parse_bullet_multiline
130
+ str = <<-STR
131
+ * l1
132
+ l1+
133
+ * l2
134
+ STR
135
+
136
+ expected = [
137
+ @RM::List.new(:BULLET, *[
138
+ @RM::ListItem.new(nil,
139
+ @RM::Paragraph.new('l1', 'l1+')),
140
+ @RM::ListItem.new(nil,
141
+ @RM::Paragraph.new('l2')),
142
+ ]),
143
+ ]
144
+
145
+ assert_equal expected, @RMP.parse(str).parts
146
+ end
147
+
148
+ def test_parse_bullet_multiparagraph
149
+ str = <<-STR
150
+ * l1
151
+
152
+ l1+
153
+ STR
154
+
155
+ expected = [
156
+ @RM::List.new(:BULLET, *[
157
+ @RM::ListItem.new(nil,
158
+ @RM::Paragraph.new('l1'),
159
+ @RM::BlankLine.new,
160
+ @RM::Paragraph.new('l1+')),
161
+ ]),
162
+ ]
163
+
164
+ assert_equal expected, @RMP.parse(str).parts
165
+ end
166
+
167
+ def test_parse_bullet_indent_verbatim
168
+ str = <<-STR
169
+ * l1
170
+ * l1.1
171
+ text
172
+ code
173
+ code
174
+
175
+ text
176
+ * l2
177
+ STR
178
+
179
+ expected = [
180
+ @RM::List.new(:BULLET, *[
181
+ @RM::ListItem.new(nil,
182
+ @RM::Paragraph.new('l1'),
183
+ @RM::List.new(:BULLET, *[
184
+ @RM::ListItem.new(nil,
185
+ @RM::Paragraph.new('l1.1', 'text'),
186
+ @RM::Verbatim.new(' ', 'code', "\n",
187
+ ' ', 'code', "\n"),
188
+ @RM::Paragraph.new('text'))])),
189
+ @RM::ListItem.new(nil,
190
+ @RM::Paragraph.new('l2'))])]
191
+
192
+ assert_equal expected, @RMP.parse(str).parts
193
+ end
194
+
195
+ def test_parse_dash
196
+ str = <<-STR
197
+ - one
198
+ - two
199
+ STR
200
+
201
+ expected = [
202
+ @RM::List.new(:BULLET, *[
203
+ @RM::ListItem.new(nil,
204
+ @RM::Paragraph.new('one')),
205
+ @RM::ListItem.new(nil,
206
+ @RM::Paragraph.new('two'))])]
207
+
208
+ assert_equal expected, @RMP.parse(str).parts
209
+ end
210
+
211
+ def test_parse_heading
212
+ str = '= heading one'
213
+
214
+ expected = [
215
+ @RM::Heading.new(1, 'heading one')]
216
+
217
+ assert_equal expected, @RMP.parse(str).parts
218
+ end
219
+
220
+ def test_parse_heading_three
221
+ str = '=== heading three'
222
+
223
+ expected = [
224
+ @RM::Heading.new(3, 'heading three')]
225
+
226
+ assert_equal expected, @RMP.parse(str).parts
227
+ end
228
+
229
+ def test_parse_heading_bullet
230
+ str = '= * heading one'
231
+
232
+ expected = [
233
+ @RM::Heading.new(1, '* heading one')]
234
+
235
+ assert_equal expected, @RMP.parse(str).parts
236
+ end
237
+
238
+ def test_parse_heading_heading
239
+ str = '= ='
240
+
241
+ expected = [
242
+ @RM::Heading.new(1, '=')]
243
+
244
+ assert_equal expected, @RMP.parse(str).parts
245
+ end
246
+
247
+ def test_parse_heading_lalpha
248
+ str = '= b. heading one'
249
+
250
+ expected = [
251
+ @RM::Heading.new(1, 'b. heading one')]
252
+
253
+ assert_equal expected, @RMP.parse(str).parts
254
+ end
255
+
256
+ def test_parse_heading_label
257
+ str = '= [heading one]'
258
+
259
+ expected = [
260
+ @RM::Heading.new(1, '[heading one]')]
261
+
262
+ assert_equal expected, @RMP.parse(str).parts
263
+ end
264
+
265
+ def test_parse_heading_note
266
+ str = '= heading one::'
267
+
268
+ expected = [
269
+ @RM::Heading.new(1, 'heading one::')]
270
+
271
+ assert_equal expected, @RMP.parse(str).parts
272
+ end
273
+
274
+ def test_parse_heading_number
275
+ str = '= 5. heading one'
276
+
277
+ expected = [
278
+ @RM::Heading.new(1, '5. heading one')]
279
+
280
+ assert_equal expected, @RMP.parse(str).parts
281
+ end
282
+
283
+ def test_parse_heading_ualpha
284
+ str = '= B. heading one'
285
+
286
+ expected = [
287
+ @RM::Heading.new(1, 'B. heading one')]
288
+
289
+ assert_equal expected, @RMP.parse(str).parts
290
+ end
291
+
292
+ def test_parse_label
293
+ str = <<-STR
294
+ [one] item one
295
+ [two] item two
296
+ STR
297
+
298
+ expected = [
299
+ @RM::List.new(:LABEL, *[
300
+ @RM::ListItem.new('one',
301
+ @RM::Paragraph.new('item one')),
302
+ @RM::ListItem.new('two',
303
+ @RM::Paragraph.new('item two'))])]
304
+
305
+ assert_equal expected, @RMP.parse(str).parts
306
+ end
307
+
308
+ def test_parse_label_bullet
309
+ str = <<-STR
310
+ [cat] l1
311
+ * l1.1
312
+ [dog] l2
313
+ STR
314
+
315
+ expected = [
316
+ @RM::List.new(:LABEL, *[
317
+ @RM::ListItem.new('cat',
318
+ @RM::Paragraph.new('l1'),
319
+ @RM::List.new(:BULLET, *[
320
+ @RM::ListItem.new(nil,
321
+ @RM::Paragraph.new('l1.1'))])),
322
+ @RM::ListItem.new('dog',
323
+ @RM::Paragraph.new('l2'))])]
324
+
325
+ assert_equal expected, @RMP.parse(str).parts
326
+ end
327
+
328
+ def test_parse_label_multiline
329
+ str = <<-STR
330
+ [cat] l1
331
+ continuation
332
+ [dog] l2
333
+ STR
334
+
335
+ expected = [
336
+ @RM::List.new(:LABEL, *[
337
+ @RM::ListItem.new('cat',
338
+ @RM::Paragraph.new('l1', 'continuation')),
339
+ @RM::ListItem.new('dog',
340
+ @RM::Paragraph.new('l2'))])]
341
+
342
+ assert_equal expected, @RMP.parse(str).parts
343
+ end
344
+
345
+ def test_parse_label_newline
346
+ str = <<-STR
347
+ [one]
348
+ item one
349
+ [two]
350
+ item two
351
+ STR
352
+
353
+ expected = [
354
+ @RM::List.new(:LABEL, *[
355
+ @RM::ListItem.new('one',
356
+ @RM::Paragraph.new('item one')),
357
+ @RM::ListItem.new('two',
358
+ @RM::Paragraph.new('item two')),
359
+ ])]
360
+
361
+ assert_equal expected, @RMP.parse(str).parts
362
+ end
363
+
364
+ def test_parse_lalpha
365
+ str = <<-STR
366
+ a. l1
367
+ b. l2
368
+ STR
369
+
370
+ expected = [
371
+ @RM::List.new(:LALPHA, *[
372
+ @RM::ListItem.new(nil,
373
+ @RM::Paragraph.new('l1')),
374
+ @RM::ListItem.new(nil,
375
+ @RM::Paragraph.new('l2'))])]
376
+
377
+ assert_equal expected, @RMP.parse(str).parts
378
+ end
379
+
380
+ def test_parse_lalpha_ualpha
381
+ str = <<-STR
382
+ a. l1
383
+ b. l2
384
+ A. l3
385
+ A. l4
386
+ STR
387
+
388
+ expected = [
389
+ @RM::List.new(:LALPHA, *[
390
+ @RM::ListItem.new(nil,
391
+ @RM::Paragraph.new('l1')),
392
+ @RM::ListItem.new(nil,
393
+ @RM::Paragraph.new('l2'))]),
394
+ @RM::List.new(:UALPHA, *[
395
+ @RM::ListItem.new(nil,
396
+ @RM::Paragraph.new('l3')),
397
+ @RM::ListItem.new(nil,
398
+ @RM::Paragraph.new('l4'))])]
399
+
400
+ assert_equal expected, @RMP.parse(str).parts
401
+ end
402
+
403
+ def test_parse_list_verbatim
404
+ str = <<-STR
405
+ * one
406
+ verb1
407
+ verb2
408
+ * two
409
+ STR
410
+
411
+ expected = [
412
+ @RM::List.new(:BULLET, *[
413
+ @RM::ListItem.new(nil,
414
+ @RM::Paragraph.new('one'),
415
+ @RM::Verbatim.new(' ', 'verb1', "\n",
416
+ ' ', 'verb2', "\n")),
417
+ @RM::ListItem.new(nil,
418
+ @RM::Paragraph.new('two'))])]
419
+
420
+ assert_equal expected, @RMP.parse(str).parts
421
+ end
422
+
423
+ def test_parse_lists
424
+ str = <<-STR
425
+ now is
426
+ * l1
427
+ 1. n1
428
+ 2. n2
429
+ * l2
430
+ the time
431
+ STR
432
+
433
+ expected = [
434
+ @RM::Paragraph.new('now is'),
435
+ @RM::List.new(:BULLET, *[
436
+ @RM::ListItem.new(nil,
437
+ @RM::Paragraph.new('l1'))]),
438
+ @RM::List.new(:NUMBER, *[
439
+ @RM::ListItem.new(nil,
440
+ @RM::Paragraph.new('n1')),
441
+ @RM::ListItem.new(nil,
442
+ @RM::Paragraph.new('n2'))]),
443
+ @RM::List.new(:BULLET, *[
444
+ @RM::ListItem.new(nil,
445
+ @RM::Paragraph.new('l2'))]),
446
+ @RM::Paragraph.new('the time')]
447
+
448
+ assert_equal expected, @RMP.parse(str).parts
449
+ end
450
+
451
+ def test_parse_note
452
+ str = <<-STR
453
+ one:: item one
454
+ two:: item two
455
+ STR
456
+
457
+ expected = [
458
+ @RM::List.new(:NOTE, *[
459
+ @RM::ListItem.new('one',
460
+ @RM::Paragraph.new('item one')),
461
+ @RM::ListItem.new('two',
462
+ @RM::Paragraph.new('item two'))])]
463
+
464
+ assert_equal expected, @RMP.parse(str).parts
465
+ end
466
+
467
+ def test_parse_note_empty
468
+ str = <<-STR
469
+ one::
470
+ two::
471
+ STR
472
+
473
+ expected = [
474
+ @RM::List.new(:NOTE, *[
475
+ @RM::ListItem.new('one',
476
+ @RM::BlankLine.new),
477
+ @RM::ListItem.new('two',
478
+ @RM::BlankLine.new)])]
479
+
480
+ assert_equal expected, @RMP.parse(str).parts
481
+ end
482
+
483
+ def test_parse_note_note
484
+ str = <<-STR
485
+ one:: two::
486
+ STR
487
+
488
+ expected = [
489
+ @RM::List.new(:NOTE, *[
490
+ @RM::ListItem.new('one',
491
+ @RM::List.new(:NOTE, *[
492
+ @RM::ListItem.new('two',
493
+ @RM::BlankLine.new)]))])]
494
+
495
+ assert_equal expected, @RMP.parse(str).parts
496
+ end
497
+
498
+ def test_parse_number_bullet
499
+ str = <<-STR
500
+ 1. l1
501
+ * l1.1
502
+ 2. l2
503
+ STR
504
+
505
+ expected = [
506
+ @RM::List.new(:NUMBER, *[
507
+ @RM::ListItem.new(nil,
508
+ @RM::Paragraph.new('l1'),
509
+ @RM::List.new(:BULLET, *[
510
+ @RM::ListItem.new(nil,
511
+ @RM::Paragraph.new('l1.1'))])),
512
+ @RM::ListItem.new(nil,
513
+ @RM::Paragraph.new('l2'))])]
514
+
515
+ assert_equal expected, @RMP.parse(str).parts
516
+ end
517
+
518
+ def test_parse_paragraph
519
+ str = <<-STR
520
+ now is the time
521
+
522
+ for all good men
523
+ STR
524
+
525
+ expected = [
526
+ @RM::Paragraph.new('now is the time'),
527
+ @RM::BlankLine.new,
528
+ @RM::Paragraph.new('for all good men')]
529
+ assert_equal expected, @RMP.parse(str).parts
530
+ end
531
+
532
+ def test_parse_paragraph_multiline
533
+ str = "now is the time\nfor all good men"
534
+
535
+ expected = @RM::Paragraph.new 'now is the time for all good men'
536
+ assert_equal [expected], @RMP.parse(str).parts
537
+ end
538
+
539
+ def test_parse_paragraph_verbatim
540
+ str = <<-STR
541
+ now is the time
542
+ code _line_ here
543
+ for all good men
544
+ STR
545
+
546
+ expected = [
547
+ @RM::Paragraph.new('now is the time'),
548
+ @RM::Verbatim.new(' ', 'code _line_ here', "\n"),
549
+ @RM::Paragraph.new('for all good men'),
550
+ ]
551
+ assert_equal expected, @RMP.parse(str).parts
552
+ end
553
+
554
+ def test_parse_ualpha
555
+ str = <<-STR
556
+ A. l1
557
+ B. l2
558
+ STR
559
+
560
+ expected = [
561
+ @RM::List.new(:UALPHA, *[
562
+ @RM::ListItem.new(nil,
563
+ @RM::Paragraph.new('l1')),
564
+ @RM::ListItem.new(nil,
565
+ @RM::Paragraph.new('l2'))])]
566
+
567
+ assert_equal expected, @RMP.parse(str).parts
568
+ end
569
+
570
+ def test_parse_verbatim
571
+ str = <<-STR
572
+ now is
573
+ code
574
+ the time
575
+ STR
576
+
577
+ expected = [
578
+ @RM::Paragraph.new('now is'),
579
+ @RM::Verbatim.new(' ', 'code', "\n"),
580
+ @RM::Paragraph.new('the time'),
581
+ ]
582
+
583
+ assert_equal expected, @RMP.parse(str).parts
584
+ end
585
+
586
+ def test_parse_verbatim_bullet
587
+ str = <<-STR
588
+ * blah
589
+ STR
590
+
591
+ expected = [
592
+ @RM::Verbatim.new(' ', '*', ' ', 'blah', "\n")]
593
+
594
+ assert_equal expected, @RMP.parse(str).parts
595
+ end
596
+
597
+ def test_parse_verbatim_fold
598
+ str = <<-STR
599
+ now is
600
+ code
601
+
602
+
603
+ code1
604
+
605
+ the time
606
+ STR
607
+
608
+ expected = [
609
+ @RM::Paragraph.new('now is'),
610
+ @RM::Verbatim.new(' ', 'code', "\n",
611
+ "\n",
612
+ ' ', 'code1', "\n"),
613
+ @RM::Paragraph.new('the time'),
614
+ ]
615
+
616
+ assert_equal expected, @RMP.parse(str).parts
617
+ end
618
+
619
+ def test_parse_verbatim_heading
620
+ str = <<-STR
621
+ text
622
+ === heading three
623
+ STR
624
+
625
+ expected = [
626
+ @RM::Paragraph.new('text'),
627
+ @RM::Verbatim.new(' ', '===', ' ', 'heading three', "\n")]
628
+
629
+ assert_equal expected, @RMP.parse(str).parts
630
+ end
631
+
632
+ def test_parse_verbatim_heading2
633
+ str = "text\n code\n=== heading three"
634
+
635
+ expected = [
636
+ @RM::Paragraph.new('text'),
637
+ @RM::Verbatim.new(' ', 'code', "\n"),
638
+ @RM::Heading.new(3, 'heading three')]
639
+
640
+ assert_equal expected, @RMP.parse(str).parts
641
+ end
642
+
643
+ def test_parse_verbatim_label
644
+ str = <<-STR
645
+ [blah] blah
646
+ STR
647
+
648
+ expected = [
649
+ @RM::Verbatim.new(' ', '[blah]', ' ', 'blah', "\n")]
650
+
651
+ assert_equal expected, @RMP.parse(str).parts
652
+ end
653
+
654
+ def test_parse_verbatim_lalpha
655
+ str = <<-STR
656
+ b. blah
657
+ STR
658
+
659
+ expected = [
660
+ @RM::Verbatim.new(' ', 'b.', ' ', 'blah', "\n")]
661
+
662
+ assert_equal expected, @RMP.parse(str).parts
663
+ end
664
+
665
+ def test_parse_verbatim_markup_example
666
+ str = <<-STR
667
+ text
668
+ code
669
+ === heading three
670
+ STR
671
+
672
+ expected = [
673
+ @RM::Paragraph.new('text'),
674
+ @RM::Verbatim.new(' ', 'code', "\n",
675
+ ' ', '===', ' ', 'heading three', "\n")]
676
+
677
+ assert_equal expected, @RMP.parse(str).parts
678
+ end
679
+
680
+ def test_parse_verbatim_merge
681
+ str = <<-STR
682
+ now is
683
+ code
684
+
685
+ code1
686
+ the time
687
+ STR
688
+
689
+ expected = [
690
+ @RM::Paragraph.new('now is'),
691
+ @RM::Verbatim.new(' ', 'code', "\n",
692
+ "\n",
693
+ ' ', 'code1', "\n"),
694
+ @RM::Paragraph.new('the time'),
695
+ ]
696
+
697
+ assert_equal expected, @RMP.parse(str).parts
698
+ end
699
+
700
+ def test_parse_verbatim_merge2
701
+ str = <<-STR
702
+ now is
703
+ code
704
+
705
+ code1
706
+
707
+ code2
708
+ the time
709
+ STR
710
+
711
+ expected = [
712
+ @RM::Paragraph.new('now is'),
713
+ @RM::Verbatim.new(' ', 'code', "\n",
714
+ "\n",
715
+ ' ', 'code1', "\n",
716
+ "\n",
717
+ ' ', 'code2', "\n"),
718
+ @RM::Paragraph.new('the time'),
719
+ ]
720
+
721
+ assert_equal expected, @RMP.parse(str).parts
722
+ end
723
+
724
+ def test_parse_verbatim_multiline
725
+ str = <<-STR
726
+ now is
727
+ code
728
+ code1
729
+ the time
730
+ STR
731
+
732
+ expected = [
733
+ @RM::Paragraph.new('now is'),
734
+ @RM::Verbatim.new(' ', 'code', "\n",
735
+ ' ', 'code1', "\n"),
736
+ @RM::Paragraph.new('the time'),
737
+ ]
738
+
739
+ assert_equal expected, @RMP.parse(str).parts
740
+ end
741
+
742
+ def test_parse_verbatim_multilevel
743
+ str = <<-STR
744
+ now is the time
745
+ code
746
+ more code
747
+ for all good men
748
+ STR
749
+
750
+ expected = [
751
+ @RM::Paragraph.new('now is the time'),
752
+ @RM::Verbatim.new(' ', 'code', "\n",
753
+ ' ', 'more code', "\n"),
754
+ @RM::Paragraph.new('for all good men'),
755
+ ]
756
+
757
+ assert_equal expected, @RMP.parse(str).parts
758
+ end
759
+
760
+ def test_parse_verbatim_note
761
+ str = <<-STR
762
+ blah:: blah
763
+ STR
764
+
765
+ expected = [
766
+ @RM::Verbatim.new(' ', 'blah::', ' ', 'blah', "\n")]
767
+
768
+ assert_equal expected, @RMP.parse(str).parts
769
+ end
770
+
771
+ def test_parse_verbatim_number
772
+ str = <<-STR
773
+ 2. blah
774
+ STR
775
+
776
+ expected = [
777
+ @RM::Verbatim.new(' ', '2.', ' ', 'blah', "\n")]
778
+
779
+ assert_equal expected, @RMP.parse(str).parts
780
+ end
781
+
782
+ def test_parse_verbatim_rule
783
+ str = <<-STR
784
+ text
785
+
786
+ --- lib/blah.rb.orig
787
+ +++ lib/blah.rb
788
+ STR
789
+
790
+ expected = [
791
+ @RM::Paragraph.new('text'),
792
+ @RM::BlankLine.new,
793
+ @RM::Verbatim.new(' ', '---', ' ', 'lib/blah.rb.orig', "\n",
794
+ ' ', '+++', ' ', 'lib/blah.rb', "\n")]
795
+
796
+ assert_equal expected, @RMP.parse(str).parts
797
+ end
798
+
799
+ def test_parse_verbatim_rule2
800
+ str = <<-STR.chomp
801
+ text
802
+
803
+ ---
804
+ STR
805
+
806
+ expected = [
807
+ @RM::Paragraph.new('text'),
808
+ @RM::BlankLine.new,
809
+ @RM::Verbatim.new(' ', '---', '')]
810
+
811
+ assert_equal expected, @RMP.parse(str).parts
812
+ end
813
+
814
+ def test_parse_verbatim_trim
815
+ str = <<-STR
816
+ now is
817
+ code
818
+
819
+ code1
820
+
821
+ the time
822
+ STR
823
+
824
+ expected = [
825
+ @RM::Paragraph.new('now is'),
826
+ @RM::Verbatim.new(' ', 'code', "\n",
827
+ "\n",
828
+ ' ', 'code1', "\n"),
829
+ @RM::Paragraph.new('the time'),
830
+ ]
831
+
832
+ assert_equal expected, @RMP.parse(str).parts
833
+ end
834
+
835
+ def test_parse_verbatim_ualpha
836
+ str = <<-STR
837
+ B. blah
838
+ STR
839
+
840
+ expected = [
841
+ @RM::Verbatim.new(' ', 'B.', ' ', 'blah', "\n")]
842
+
843
+ assert_equal expected, @RMP.parse(str).parts
844
+ end
845
+
846
+ def test_parse_whitespace
847
+ expected = [
848
+ @RM::Paragraph.new('hello'),
849
+ ]
850
+
851
+ assert_equal expected, @RMP.parse('hello').parts
852
+
853
+ expected = [
854
+ @RM::Verbatim.new(' ', 'hello '),
855
+ ]
856
+
857
+ assert_equal expected, @RMP.parse(' hello ').parts
858
+
859
+ expected = [
860
+ @RM::Verbatim.new(' ', 'hello '),
861
+ ]
862
+
863
+ assert_equal expected, @RMP.parse(" hello ").parts
864
+
865
+ expected = [
866
+ @RM::Paragraph.new('1'),
867
+ @RM::Verbatim.new(' ', '2', "\n",
868
+ ' ', '3'),
869
+ ]
870
+
871
+ assert_equal expected, @RMP.parse("1\n 2\n 3").parts
872
+
873
+ expected = [
874
+ @RM::Verbatim.new(' ', '1', "\n",
875
+ ' ', '2', "\n",
876
+ ' ', '3'),
877
+ ]
878
+
879
+ assert_equal expected, @RMP.parse(" 1\n 2\n 3").parts
880
+
881
+ expected = [
882
+ @RM::Paragraph.new('1'),
883
+ @RM::Verbatim.new(' ', '2', "\n",
884
+ ' ', '3', "\n"),
885
+ @RM::Paragraph.new('1'),
886
+ @RM::Verbatim.new(' ', '2'),
887
+ ]
888
+
889
+ assert_equal expected, @RMP.parse("1\n 2\n 3\n1\n 2").parts
890
+
891
+ expected = [
892
+ @RM::Verbatim.new(' ', '1', "\n",
893
+ ' ', '2', "\n",
894
+ ' ', '3', "\n",
895
+ ' ', '1', "\n",
896
+ ' ', '2'),
897
+ ]
898
+
899
+ assert_equal expected, @RMP.parse(" 1\n 2\n 3\n 1\n 2").parts
900
+
901
+ expected = [
902
+ @RM::Verbatim.new(' ', '1', "\n",
903
+ ' ', '2', "\n",
904
+ "\n",
905
+ ' ', '3'),
906
+ ]
907
+
908
+ assert_equal expected, @RMP.parse(" 1\n 2\n\n 3").parts
909
+ end
910
+
911
+ def test_peek_token
912
+ parser = util_parser
913
+
914
+ assert_equal [:HEADER, 1, 0, 0], parser.peek_token
915
+
916
+ assert_equal 8, parser.tokens.length
917
+ end
918
+
919
+ def test_skip
920
+ parser = util_parser
921
+
922
+ assert_equal [:HEADER, 1, 0, 0], parser.skip(:HEADER)
923
+
924
+ assert_equal [:TEXT, 'Heading', 2, 0], parser.get
925
+
926
+ assert_equal [:NEWLINE, "\n", 9, 0], parser.peek_token
927
+
928
+ assert_raises RDoc::Markup::Parser::ParseError do
929
+ parser.skip :NONE
930
+ end
931
+
932
+ assert_equal [:NEWLINE, "\n", 9, 0], parser.peek_token
933
+
934
+ assert_equal nil, parser.skip(:NONE, false)
935
+
936
+ assert_equal [:NEWLINE, "\n", 9, 0], parser.peek_token
937
+ end
938
+
939
+ def test_tokenize_bullet
940
+ str = <<-STR
941
+ * l1
942
+ STR
943
+
944
+ expected = [
945
+ [:BULLET, :BULLET, 0, 0],
946
+ [:SPACE, 2, 0, 0],
947
+ [:TEXT, 'l1', 2, 0],
948
+ [:NEWLINE, "\n", 4, 0],
949
+ ]
950
+
951
+ assert_equal expected, @RMP.tokenize(str)
952
+ end
953
+
954
+ def test_tokenize_bullet_indent
955
+ str = <<-STR
956
+ * l1
957
+ * l1.1
958
+ STR
959
+
960
+ expected = [
961
+ [:BULLET, :BULLET, 0, 0],
962
+ [:SPACE, 2, 0, 0],
963
+ [:TEXT, 'l1', 2, 0],
964
+ [:NEWLINE, "\n", 4, 0],
965
+ [:INDENT, 2, 0, 1],
966
+ [:BULLET, :BULLET, 2, 1],
967
+ [:SPACE, 2, 2, 1],
968
+ [:TEXT, 'l1.1', 4, 1],
969
+ [:NEWLINE, "\n", 8, 1],
970
+ ]
971
+
972
+ assert_equal expected, @RMP.tokenize(str)
973
+ end
974
+
975
+ def test_tokenize_heading
976
+ str = <<-STR
977
+ = Heading
978
+ == Heading 2
979
+ STR
980
+
981
+ expected = [
982
+ [:HEADER, 1, 0, 0],
983
+ [:TEXT, 'Heading', 2, 0],
984
+ [:NEWLINE, "\n", 9, 0],
985
+ [:HEADER, 2, 0, 1],
986
+ [:TEXT, 'Heading 2', 3, 1],
987
+ [:NEWLINE, "\n", 12, 1],
988
+ ]
989
+
990
+ assert_equal expected, @RMP.tokenize(str)
991
+ end
992
+
993
+ def test_tokenize_heading_heading
994
+ str = <<-STR
995
+ = =
996
+ STR
997
+
998
+ expected = [
999
+ [:HEADER, 1, 0, 0],
1000
+ [:TEXT, '=', 2, 0],
1001
+ [:NEWLINE, "\n", 3, 0],
1002
+ ]
1003
+
1004
+ assert_equal expected, @RMP.tokenize(str)
1005
+ end
1006
+
1007
+ def test_tokenize_label
1008
+ str = <<-STR
1009
+ [cat] l1
1010
+ [dog] l1.1
1011
+ STR
1012
+
1013
+ expected = [
1014
+ [:LABEL, 'cat', 0, 0],
1015
+ [:SPACE, 6, 0, 0],
1016
+ [:TEXT, 'l1', 6, 0],
1017
+ [:NEWLINE, "\n", 8, 0],
1018
+ [:LABEL, 'dog', 0, 1],
1019
+ [:SPACE, 6, 0, 1],
1020
+ [:TEXT, 'l1.1', 6, 1],
1021
+ [:NEWLINE, "\n", 10, 1],
1022
+ ]
1023
+
1024
+ assert_equal expected, @RMP.tokenize(str)
1025
+ end
1026
+
1027
+ def test_tokenize_label_note
1028
+ str = <<-STR
1029
+ [label]
1030
+ note::
1031
+ STR
1032
+
1033
+ expected = [
1034
+ [:LABEL, 'label', 0, 0],
1035
+ [:SPACE, 7, 0, 0],
1036
+ [:NEWLINE, "\n", 7, 0],
1037
+ [:INDENT, 2, 0, 1],
1038
+ [:NOTE, 'note', 2, 1],
1039
+ [:SPACE, 6, 2, 1],
1040
+ [:NEWLINE, "\n", 8, 1],
1041
+ ]
1042
+
1043
+ assert_equal expected, @RMP.tokenize(str)
1044
+ end
1045
+
1046
+ def test_tokenize_lalpha
1047
+ str = <<-STR
1048
+ a. l1
1049
+ b. l1.1
1050
+ STR
1051
+
1052
+ expected = [
1053
+ [:LALPHA, 'a', 0, 0],
1054
+ [:SPACE, 3, 0, 0],
1055
+ [:TEXT, 'l1', 3, 0],
1056
+ [:NEWLINE, "\n", 5, 0],
1057
+ [:LALPHA, 'b', 0, 1],
1058
+ [:SPACE, 3, 0, 1],
1059
+ [:TEXT, 'l1.1', 3, 1],
1060
+ [:NEWLINE, "\n", 7, 1],
1061
+ ]
1062
+
1063
+ assert_equal expected, @RMP.tokenize(str)
1064
+ end
1065
+
1066
+ def test_tokenize_note
1067
+ str = <<-STR
1068
+ cat:: l1
1069
+ dog:: l1.1
1070
+ STR
1071
+
1072
+ expected = [
1073
+ [:NOTE, 'cat', 0, 0],
1074
+ [:SPACE, 6, 0, 0],
1075
+ [:TEXT, 'l1', 6, 0],
1076
+ [:NEWLINE, "\n", 8, 0],
1077
+ [:NOTE, 'dog', 0, 1],
1078
+ [:SPACE, 6, 0, 1],
1079
+ [:TEXT, 'l1.1', 6, 1],
1080
+ [:NEWLINE, "\n", 10, 1],
1081
+ ]
1082
+
1083
+ assert_equal expected, @RMP.tokenize(str)
1084
+ end
1085
+
1086
+ def test_tokenize_note_empty
1087
+ str = <<-STR
1088
+ cat::
1089
+ dog::
1090
+ STR
1091
+
1092
+ expected = [
1093
+ [:NOTE, 'cat', 0, 0],
1094
+ [:SPACE, 5, 0, 0],
1095
+ [:NEWLINE, "\n", 5, 0],
1096
+ [:NOTE, 'dog', 0, 1],
1097
+ [:SPACE, 5, 0, 1],
1098
+ [:NEWLINE, "\n", 5, 1],
1099
+ ]
1100
+
1101
+ assert_equal expected, @RMP.tokenize(str)
1102
+ end
1103
+
1104
+ def test_tokenize_note_not
1105
+ str = <<-STR
1106
+ Cat::Dog
1107
+ STR
1108
+
1109
+ expected = [
1110
+ [:TEXT, 'Cat::Dog', 0, 0],
1111
+ [:NEWLINE, "\n", 8, 0],
1112
+ ]
1113
+
1114
+ assert_equal expected, @RMP.tokenize(str)
1115
+ end
1116
+
1117
+ def test_tokenize_number
1118
+ str = <<-STR
1119
+ 1. l1
1120
+ 2. l1.1
1121
+ STR
1122
+
1123
+ expected = [
1124
+ [:NUMBER, '1', 0, 0],
1125
+ [:SPACE, 3, 0, 0],
1126
+ [:TEXT, 'l1', 3, 0],
1127
+ [:NEWLINE, "\n", 5, 0],
1128
+ [:NUMBER, '2', 0, 1],
1129
+ [:SPACE, 3, 0, 1],
1130
+ [:TEXT, 'l1.1', 3, 1],
1131
+ [:NEWLINE, "\n", 7, 1],
1132
+ ]
1133
+
1134
+ assert_equal expected, @RMP.tokenize(str)
1135
+ end
1136
+
1137
+ def test_tokenize_number_period
1138
+ str = <<-STR
1139
+ 1. blah blah blah
1140
+ l.
1141
+ 2. blah blah blah blah
1142
+ d.
1143
+ STR
1144
+
1145
+ expected = [
1146
+ [:NUMBER, "1", 0, 0],
1147
+ [:SPACE, 3, 0, 0],
1148
+ [:TEXT, "blah blah blah", 3, 0],
1149
+ [:NEWLINE, "\n", 17, 0],
1150
+
1151
+ [:INDENT, 3, 0, 1],
1152
+ [:TEXT, "l.", 3, 1],
1153
+ [:NEWLINE, "\n", 5, 1],
1154
+
1155
+ [:NUMBER, "2", 0, 2],
1156
+ [:SPACE, 3, 0, 2],
1157
+ [:TEXT, "blah blah blah blah", 3, 2],
1158
+ [:NEWLINE, "\n", 22, 2],
1159
+
1160
+ [:INDENT, 3, 0, 3],
1161
+ [:TEXT, "d.", 3, 3],
1162
+ [:NEWLINE, "\n", 5, 3]
1163
+ ]
1164
+
1165
+ assert_equal expected, @RMP.tokenize(str)
1166
+ end
1167
+
1168
+ def test_tokenize_number_period_continue
1169
+ str = <<-STR
1170
+ 1. blah blah blah
1171
+ l. more stuff
1172
+ 2. blah blah blah blah
1173
+ d. other stuff
1174
+ STR
1175
+
1176
+ expected = [
1177
+ [:NUMBER, "1", 0, 0],
1178
+ [:SPACE, 3, 0, 0],
1179
+ [:TEXT, "blah blah blah", 3, 0],
1180
+ [:NEWLINE, "\n", 17, 0],
1181
+
1182
+ [:INDENT, 3, 0, 1],
1183
+ [:LALPHA, "l", 3, 1],
1184
+ [:SPACE, 4, 3, 1],
1185
+ [:TEXT, "more stuff", 7, 1],
1186
+ [:NEWLINE, "\n", 17, 1],
1187
+
1188
+ [:NUMBER, "2", 0, 2],
1189
+ [:SPACE, 3, 0, 2],
1190
+ [:TEXT, "blah blah blah blah", 3, 2],
1191
+ [:NEWLINE, "\n", 22, 2],
1192
+
1193
+ [:INDENT, 3, 0, 3],
1194
+ [:LALPHA, "d", 3, 3],
1195
+ [:SPACE, 3, 3, 3],
1196
+ [:TEXT, "other stuff", 6, 3],
1197
+ [:NEWLINE, "\n", 17, 3]
1198
+ ]
1199
+
1200
+ assert_equal expected, @RMP.tokenize(str)
1201
+ end
1202
+
1203
+ def test_tokenize_paragraphs
1204
+ str = <<-STR
1205
+ now is
1206
+ the time
1207
+
1208
+ for all
1209
+ STR
1210
+
1211
+ expected = [
1212
+ [:TEXT, 'now is', 0, 0],
1213
+ [:NEWLINE, "\n", 6, 0],
1214
+ [:TEXT, 'the time', 0, 1],
1215
+ [:NEWLINE, "\n", 8, 1],
1216
+ [:NEWLINE, "\n", 0, 2],
1217
+ [:TEXT, 'for all', 0, 3],
1218
+ [:NEWLINE, "\n", 7, 3],
1219
+ ]
1220
+
1221
+ assert_equal expected, @RMP.tokenize(str)
1222
+ end
1223
+
1224
+ def test_tokenize_rule
1225
+ str = <<-STR
1226
+ ---
1227
+
1228
+ --- blah ---
1229
+ STR
1230
+
1231
+ expected = [
1232
+ [:RULE, 1, 0, 0],
1233
+ [:NEWLINE, "\n", 4, 0],
1234
+ [:NEWLINE, "\n", 0, 1],
1235
+ [:TEXT, "--- blah ---", 0, 2],
1236
+ [:NEWLINE, "\n", 12, 2],
1237
+ ]
1238
+
1239
+ assert_equal expected, @RMP.tokenize(str)
1240
+ end
1241
+
1242
+ def test_tokenize_ualpha
1243
+ str = <<-STR
1244
+ A. l1
1245
+ B. l1.1
1246
+ STR
1247
+
1248
+ expected = [
1249
+ [:UALPHA, 'A', 0, 0],
1250
+ [:SPACE, 3, 0, 0],
1251
+ [:TEXT, 'l1', 3, 0],
1252
+ [:NEWLINE, "\n", 5, 0],
1253
+ [:UALPHA, 'B', 0, 1],
1254
+ [:SPACE, 3, 0, 1],
1255
+ [:TEXT, 'l1.1', 3, 1],
1256
+ [:NEWLINE, "\n", 7, 1],
1257
+ ]
1258
+
1259
+ assert_equal expected, @RMP.tokenize(str)
1260
+ end
1261
+
1262
+ def test_tokenize_verbatim_heading
1263
+ str = <<-STR
1264
+ Example heading:
1265
+
1266
+ === heading three
1267
+ STR
1268
+
1269
+ expected = [
1270
+ [:TEXT, 'Example heading:', 0, 0],
1271
+ [:NEWLINE, "\n", 16, 0],
1272
+ [:NEWLINE, "\n", 0, 1],
1273
+ [:INDENT, 3, 0, 2],
1274
+ [:HEADER, 3, 3, 2],
1275
+ [:TEXT, 'heading three', 7, 2],
1276
+ [:NEWLINE, "\n", 20, 2],
1277
+ ]
1278
+
1279
+ assert_equal expected, @RMP.tokenize(str)
1280
+ end
1281
+
1282
+ # HACK move to Verbatim test case
1283
+ def test_verbatim_normalize
1284
+ v = @RM::Verbatim.new ' ', 'foo', "\n", "\n", "\n", ' ', 'bar', "\n"
1285
+
1286
+ v.normalize
1287
+
1288
+ assert_equal [' ', 'foo', "\n", "\n", ' ', 'bar', "\n"], v.parts
1289
+
1290
+ v = @RM::Verbatim.new ' ', 'foo', "\n", "\n"
1291
+
1292
+ v.normalize
1293
+
1294
+ assert_equal [' ', 'foo', "\n"], v.parts
1295
+ end
1296
+
1297
+ def test_unget
1298
+ parser = util_parser
1299
+
1300
+ parser.get
1301
+
1302
+ parser.unget
1303
+
1304
+ assert_equal [:HEADER, 1, 0, 0], parser.peek_token
1305
+
1306
+ assert_raises @RMP::Error do
1307
+ parser.unget
1308
+ end
1309
+
1310
+ assert_equal 8, parser.tokens.length
1311
+ end
1312
+
1313
+ def util_parser
1314
+ str = <<-STR
1315
+ = Heading
1316
+
1317
+ Some text here
1318
+ some more text over here
1319
+ STR
1320
+
1321
+ @parser = @RMP.new
1322
+ @parser.tokenize str
1323
+ @parser
1324
+ end
1325
+
1326
+ end
1327
+