1require 'rdoc/test_case' 2 3class TestRDocMarkupToBs < RDoc::Markup::TextFormatterTestCase 4 5 add_visitor_tests 6 add_text_tests 7 8 def setup 9 super 10 11 @to = RDoc::Markup::ToBs.new 12 end 13 14 def accept_blank_line 15 assert_equal "\n", @to.res.join 16 end 17 18 def accept_block_quote 19 assert_equal "> quote\n", @to.res.join 20 end 21 22 def accept_document 23 assert_equal "hello\n", @to.res.join 24 end 25 26 def accept_heading 27 skip "No String#chars, upgrade your ruby" unless ''.respond_to? :chars 28 assert_equal "===== H\bHe\bel\bll\blo\bo\n", @to.res.join 29 end 30 31 def accept_list_end_bullet 32 assert_empty @to.list_index 33 assert_empty @to.list_type 34 assert_empty @to.list_width 35 end 36 37 def accept_list_end_label 38 assert_empty @to.list_index 39 assert_empty @to.list_type 40 assert_empty @to.list_width 41 end 42 43 def accept_list_end_lalpha 44 assert_empty @to.list_index 45 assert_empty @to.list_type 46 assert_empty @to.list_width 47 end 48 49 def accept_list_end_note 50 assert_empty @to.list_index 51 assert_empty @to.list_type 52 assert_empty @to.list_width 53 end 54 55 def accept_list_end_number 56 assert_empty @to.list_index 57 assert_empty @to.list_type 58 assert_empty @to.list_width 59 end 60 61 def accept_list_end_ualpha 62 assert_empty @to.list_index 63 assert_empty @to.list_type 64 assert_empty @to.list_width 65 end 66 67 def accept_list_item_end_bullet 68 assert_equal 0, @to.indent, 'indent' 69 end 70 71 def accept_list_item_end_label 72 assert_equal "cat:\n", @to.res.join 73 assert_equal 0, @to.indent, 'indent' 74 end 75 76 def accept_list_item_end_lalpha 77 assert_equal 0, @to.indent, 'indent' 78 assert_equal 'b', @to.list_index.last 79 end 80 81 def accept_list_item_end_note 82 assert_equal "cat:\n", @to.res.join 83 assert_equal 0, @to.indent, 'indent' 84 end 85 86 def accept_list_item_end_number 87 assert_equal 0, @to.indent, 'indent' 88 assert_equal 2, @to.list_index.last 89 end 90 91 def accept_list_item_end_ualpha 92 assert_equal 0, @to.indent, 'indent' 93 assert_equal 'B', @to.list_index.last 94 end 95 96 def accept_list_item_start_bullet 97 assert_equal [''], @to.res 98 assert_equal '* ', @to.prefix 99 end 100 101 def accept_list_item_start_label 102 assert_equal [''], @to.res 103 assert_equal "cat:\n ", @to.prefix 104 105 assert_equal 2, @to.indent 106 end 107 108 def accept_list_item_start_lalpha 109 assert_equal [''], @to.res 110 assert_equal 'a. ', @to.prefix 111 112 assert_equal 'a', @to.list_index.last 113 assert_equal 3, @to.indent 114 end 115 116 def accept_list_item_start_note 117 assert_equal [''], @to.res 118 assert_equal "cat:\n ", @to.prefix 119 120 assert_equal 2, @to.indent 121 end 122 123 def accept_list_item_start_number 124 assert_equal [''], @to.res 125 assert_equal '1. ', @to.prefix 126 127 assert_equal 1, @to.list_index.last 128 assert_equal 3, @to.indent 129 end 130 131 def accept_list_item_start_ualpha 132 assert_equal [''], @to.res 133 assert_equal 'A. ', @to.prefix 134 135 assert_equal 'A', @to.list_index.last 136 assert_equal 3, @to.indent 137 end 138 139 def accept_list_start_bullet 140 assert_equal "", @to.res.join 141 assert_equal [nil], @to.list_index 142 assert_equal [:BULLET], @to.list_type 143 assert_equal [1], @to.list_width 144 end 145 146 def accept_list_start_label 147 assert_equal "", @to.res.join 148 assert_equal [nil], @to.list_index 149 assert_equal [:LABEL], @to.list_type 150 assert_equal [2], @to.list_width 151 end 152 153 def accept_list_start_lalpha 154 assert_equal "", @to.res.join 155 assert_equal ['a'], @to.list_index 156 assert_equal [:LALPHA], @to.list_type 157 assert_equal [1], @to.list_width 158 end 159 160 def accept_list_start_note 161 assert_equal "", @to.res.join 162 assert_equal [nil], @to.list_index 163 assert_equal [:NOTE], @to.list_type 164 assert_equal [2], @to.list_width 165 end 166 167 def accept_list_start_number 168 assert_equal "", @to.res.join 169 assert_equal [1], @to.list_index 170 assert_equal [:NUMBER], @to.list_type 171 assert_equal [1], @to.list_width 172 end 173 174 def accept_list_start_ualpha 175 assert_equal "", @to.res.join 176 assert_equal ['A'], @to.list_index 177 assert_equal [:UALPHA], @to.list_type 178 assert_equal [1], @to.list_width 179 end 180 181 def accept_paragraph 182 assert_equal "hi\n", @to.res.join 183 end 184 185 def accept_raw 186 raw = <<-RAW.rstrip 187<table> 188<tr><th>Name<th>Count 189<tr><td>a<td>1 190<tr><td>b<td>2 191</table> 192 RAW 193 194 assert_equal raw, @to.res.join 195 end 196 197 def accept_rule 198 assert_equal "#{'-' * 78}\n", @to.res.join 199 end 200 201 def accept_verbatim 202 assert_equal " hi\n world\n\n", @to.res.join 203 end 204 205 def end_accepting 206 assert_equal "hi", @to.end_accepting 207 end 208 209 def start_accepting 210 assert_equal 0, @to.indent 211 assert_equal [''], @to.res 212 assert_empty @to.list_index 213 assert_empty @to.list_type 214 assert_empty @to.list_width 215 end 216 217 def accept_heading_1 218 skip "No String#chars, upgrade your ruby" unless ''.respond_to? :chars 219 assert_equal "= H\bHe\bel\bll\blo\bo\n", @to.end_accepting 220 end 221 222 def accept_heading_2 223 skip "No String#chars, upgrade your ruby" unless ''.respond_to? :chars 224 assert_equal "== H\bHe\bel\bll\blo\bo\n", @to.end_accepting 225 end 226 227 def accept_heading_3 228 skip "No String#chars, upgrade your ruby" unless ''.respond_to? :chars 229 assert_equal "=== H\bHe\bel\bll\blo\bo\n", @to.end_accepting 230 end 231 232 def accept_heading_4 233 skip "No String#chars, upgrade your ruby" unless ''.respond_to? :chars 234 assert_equal "==== H\bHe\bel\bll\blo\bo\n", @to.end_accepting 235 end 236 237 def accept_heading_indent 238 skip "No String#chars, upgrade your ruby" unless ''.respond_to? :chars 239 assert_equal " = H\bHe\bel\bll\blo\bo\n", @to.end_accepting 240 end 241 242 def accept_heading_b 243 skip "No String#chars, upgrade your ruby" unless ''.respond_to? :chars 244 assert_equal "= H\bHe\bel\bll\blo\bo\n", @to.end_accepting 245 end 246 247 def accept_heading_suppressed_crossref 248 skip "No String#chars, upgrade your ruby" unless ''.respond_to? :chars 249 assert_equal "= H\bHe\bel\bll\blo\bo\n", @to.end_accepting 250 end 251 252 def accept_list_item_start_note_2 253 assert_equal "teletype:\n teletype description\n\n", @to.res.join 254 end 255 256 def accept_list_item_start_note_multi_description 257 assert_equal "label:\n description one\n\n description two\n\n", 258 @to.res.join 259 end 260 261 def accept_list_item_start_note_multi_label 262 assert_equal "one\ntwo:\n two headers\n\n", @to.res.join 263 end 264 265 def accept_paragraph_b 266 skip "No String#chars, upgrade your ruby" unless ''.respond_to? :chars 267 assert_equal "reg b\bbo\bol\bld\bd \b w\bwo\bor\brd\bds\bs reg\n", 268 @to.end_accepting 269 end 270 271 def accept_paragraph_br 272 skip "No String#chars, upgrade your ruby" unless ''.respond_to? :chars 273 assert_equal "one\ntwo\n", @to.end_accepting 274 end 275 276 def accept_paragraph_break 277 skip "No String#chars, upgrade your ruby" unless ''.respond_to? :chars 278 assert_equal "hello\nworld\n", 279 @to.end_accepting 280 end 281 282 def accept_paragraph_i 283 skip "No String#chars, upgrade your ruby" unless ''.respond_to? :chars 284 assert_equal "reg _\bi_\bt_\ba_\bl_\bi_\bc_\b _\bw_\bo_\br_\bd_\bs reg\n", 285 @to.end_accepting 286 end 287 288 def accept_paragraph_indent 289 expected = <<-EXPECTED 290 words words words words words words words words words words words words 291 words words words words words words words words words words words words 292 words words words words words words 293 EXPECTED 294 295 assert_equal expected, @to.end_accepting 296 end 297 298 def accept_paragraph_plus 299 assert_equal "reg teletype reg\n", @to.end_accepting 300 end 301 302 def accept_paragraph_star 303 skip "No String#chars, upgrade your ruby" unless ''.respond_to? :chars 304 assert_equal "reg b\bbo\bol\bld\bd reg\n", @to.end_accepting 305 end 306 307 def accept_paragraph_underscore 308 skip "No String#chars, upgrade your ruby" unless ''.respond_to? :chars 309 assert_equal "reg _\bi_\bt_\ba_\bl_\bi_\bc reg\n", @to.end_accepting 310 end 311 312 def accept_paragraph_wrap 313 expected = <<-EXPECTED 314words words words words words words words words words words words words words 315words words words words words words words words words words words words words 316words words words words 317 EXPECTED 318 319 assert_equal expected, @to.end_accepting 320 end 321 322 def accept_rule_indent 323 assert_equal " #{'-' * 75}\n", @to.end_accepting 324 end 325 326 def accept_verbatim_indent 327 assert_equal " hi\n world\n\n", @to.end_accepting 328 end 329 330 def accept_verbatim_big_indent 331 assert_equal " hi\n world\n\n", @to.end_accepting 332 end 333 334 def list_nested 335 expected = <<-EXPECTED 336* l1 337 * l1.1 338* l2 339 EXPECTED 340 341 assert_equal expected, @to.end_accepting 342 end 343 344 def list_verbatim 345 expected = <<-EXPECTED # HACK overblown 346* list stuff 347 348 * list 349 with 350 351 second 352 353 1. indented 354 2. numbered 355 356 third 357 358 * second 359 360 EXPECTED 361 362 assert_equal expected, @to.end_accepting 363 end 364 365end 366 367