annotate .svn/pristine/40/40da41a99bbaf8c8dd342e000dfd662f0b546a22.svn-base @ 1519:afce8026aaeb redmine-2.4-integration

Merge from branch "live"
author Chris Cannam
date Tue, 09 Sep 2014 09:34:53 +0100
parents e248c7af89ec
children
rev   line source
Chris@1494 1 # Redmine - project management software
Chris@1494 2 # Copyright (C) 2006-2014 Jean-Philippe Lang
Chris@1494 3 #
Chris@1494 4 # This program is free software; you can redistribute it and/or
Chris@1494 5 # modify it under the terms of the GNU General Public License
Chris@1494 6 # as published by the Free Software Foundation; either version 2
Chris@1494 7 # of the License, or (at your option) any later version.
Chris@1494 8 #
Chris@1494 9 # This program is distributed in the hope that it will be useful,
Chris@1494 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1494 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1494 12 # GNU General Public License for more details.
Chris@1494 13 #
Chris@1494 14 # You should have received a copy of the GNU General Public License
Chris@1494 15 # along with this program; if not, write to the Free Software
Chris@1494 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1494 17
Chris@1494 18 require File.expand_path('../../../../../test_helper', __FILE__)
Chris@1494 19 require 'digest/md5'
Chris@1494 20
Chris@1494 21 class Redmine::WikiFormatting::TextileFormatterTest < ActionView::TestCase
Chris@1494 22
Chris@1494 23 def setup
Chris@1494 24 @formatter = Redmine::WikiFormatting::Textile::Formatter
Chris@1494 25 end
Chris@1494 26
Chris@1494 27 MODIFIERS = {
Chris@1494 28 "*" => 'strong', # bold
Chris@1494 29 "_" => 'em', # italic
Chris@1494 30 "+" => 'ins', # underline
Chris@1494 31 "-" => 'del', # deleted
Chris@1494 32 "^" => 'sup', # superscript
Chris@1494 33 "~" => 'sub' # subscript
Chris@1494 34 }
Chris@1494 35
Chris@1494 36 def test_modifiers
Chris@1494 37 assert_html_output(
Chris@1494 38 '*bold*' => '<strong>bold</strong>',
Chris@1494 39 'before *bold*' => 'before <strong>bold</strong>',
Chris@1494 40 '*bold* after' => '<strong>bold</strong> after',
Chris@1494 41 '*two words*' => '<strong>two words</strong>',
Chris@1494 42 '*two*words*' => '<strong>two*words</strong>',
Chris@1494 43 '*two * words*' => '<strong>two * words</strong>',
Chris@1494 44 '*two* *words*' => '<strong>two</strong> <strong>words</strong>',
Chris@1494 45 '*(two)* *(words)*' => '<strong>(two)</strong> <strong>(words)</strong>',
Chris@1494 46 # with class
Chris@1494 47 '*(foo)two words*' => '<strong class="foo">two words</strong>'
Chris@1494 48 )
Chris@1494 49 end
Chris@1494 50
Chris@1494 51 def test_modifiers_combination
Chris@1494 52 MODIFIERS.each do |m1, tag1|
Chris@1494 53 MODIFIERS.each do |m2, tag2|
Chris@1494 54 next if m1 == m2
Chris@1494 55 text = "#{m2}#{m1}Phrase modifiers#{m1}#{m2}"
Chris@1494 56 html = "<#{tag2}><#{tag1}>Phrase modifiers</#{tag1}></#{tag2}>"
Chris@1494 57 assert_html_output text => html
Chris@1494 58 end
Chris@1494 59 end
Chris@1494 60 end
Chris@1494 61
Chris@1494 62 def test_styles
Chris@1494 63 # single style
Chris@1494 64 assert_html_output({
Chris@1494 65 'p{color:red}. text' => '<p style="color:red;">text</p>',
Chris@1494 66 'p{color:red;}. text' => '<p style="color:red;">text</p>',
Chris@1494 67 'p{color: red}. text' => '<p style="color: red;">text</p>',
Chris@1494 68 'p{color:#f00}. text' => '<p style="color:#f00;">text</p>',
Chris@1494 69 'p{color:#ff0000}. text' => '<p style="color:#ff0000;">text</p>',
Chris@1494 70 'p{border:10px}. text' => '<p style="border:10px;">text</p>',
Chris@1494 71 'p{border:10}. text' => '<p style="border:10;">text</p>',
Chris@1494 72 'p{border:10%}. text' => '<p style="border:10%;">text</p>',
Chris@1494 73 'p{border:10em}. text' => '<p style="border:10em;">text</p>',
Chris@1494 74 'p{border:1.5em}. text' => '<p style="border:1.5em;">text</p>',
Chris@1494 75 'p{border-left:1px}. text' => '<p style="border-left:1px;">text</p>',
Chris@1494 76 'p{border-right:1px}. text' => '<p style="border-right:1px;">text</p>',
Chris@1494 77 'p{border-top:1px}. text' => '<p style="border-top:1px;">text</p>',
Chris@1494 78 'p{border-bottom:1px}. text' => '<p style="border-bottom:1px;">text</p>',
Chris@1494 79 }, false)
Chris@1494 80
Chris@1494 81 # multiple styles
Chris@1494 82 assert_html_output({
Chris@1494 83 'p{color:red; border-top:1px}. text' => '<p style="color:red;border-top:1px;">text</p>',
Chris@1494 84 'p{color:red ; border-top:1px}. text' => '<p style="color:red;border-top:1px;">text</p>',
Chris@1494 85 'p{color:red;border-top:1px}. text' => '<p style="color:red;border-top:1px;">text</p>',
Chris@1494 86 }, false)
Chris@1494 87
Chris@1494 88 # styles with multiple values
Chris@1494 89 assert_html_output({
Chris@1494 90 'p{border:1px solid red;}. text' => '<p style="border:1px solid red;">text</p>',
Chris@1494 91 'p{border-top-left-radius: 10px 5px;}. text' => '<p style="border-top-left-radius: 10px 5px;">text</p>',
Chris@1494 92 }, false)
Chris@1494 93 end
Chris@1494 94
Chris@1494 95 def test_invalid_styles_should_be_filtered
Chris@1494 96 assert_html_output({
Chris@1494 97 'p{invalid}. text' => '<p>text</p>',
Chris@1494 98 'p{invalid:red}. text' => '<p>text</p>',
Chris@1494 99 'p{color:(red)}. text' => '<p>text</p>',
Chris@1494 100 'p{color:red;invalid:blue}. text' => '<p style="color:red;">text</p>',
Chris@1494 101 'p{invalid:blue;color:red}. text' => '<p style="color:red;">text</p>',
Chris@1494 102 'p{color:"}. text' => '<p>p{color:"}. text</p>',
Chris@1494 103 }, false)
Chris@1494 104 end
Chris@1494 105
Chris@1494 106 def test_inline_code
Chris@1494 107 assert_html_output(
Chris@1494 108 'this is @some code@' => 'this is <code>some code</code>',
Chris@1494 109 '@<Location /redmine>@' => '<code>&lt;Location /redmine&gt;</code>'
Chris@1494 110 )
Chris@1494 111 end
Chris@1494 112
Chris@1494 113 def test_nested_lists
Chris@1494 114 raw = <<-RAW
Chris@1494 115 # Item 1
Chris@1494 116 # Item 2
Chris@1494 117 ** Item 2a
Chris@1494 118 ** Item 2b
Chris@1494 119 # Item 3
Chris@1494 120 ** Item 3a
Chris@1494 121 RAW
Chris@1494 122
Chris@1494 123 expected = <<-EXPECTED
Chris@1494 124 <ol>
Chris@1494 125 <li>Item 1</li>
Chris@1494 126 <li>Item 2
Chris@1494 127 <ul>
Chris@1494 128 <li>Item 2a</li>
Chris@1494 129 <li>Item 2b</li>
Chris@1494 130 </ul>
Chris@1494 131 </li>
Chris@1494 132 <li>Item 3
Chris@1494 133 <ul>
Chris@1494 134 <li>Item 3a</li>
Chris@1494 135 </ul>
Chris@1494 136 </li>
Chris@1494 137 </ol>
Chris@1494 138 EXPECTED
Chris@1494 139
Chris@1494 140 assert_equal expected.gsub(%r{\s+}, ''), to_html(raw).gsub(%r{\s+}, '')
Chris@1494 141 end
Chris@1494 142
Chris@1494 143 def test_escaping
Chris@1494 144 assert_html_output(
Chris@1494 145 'this is a <script>' => 'this is a &lt;script&gt;'
Chris@1494 146 )
Chris@1494 147 end
Chris@1494 148
Chris@1494 149 def test_use_of_backslashes_followed_by_numbers_in_headers
Chris@1494 150 assert_html_output({
Chris@1494 151 'h1. 2009\02\09' => '<h1>2009\02\09</h1>'
Chris@1494 152 }, false)
Chris@1494 153 end
Chris@1494 154
Chris@1494 155 def test_double_dashes_should_not_strikethrough
Chris@1494 156 assert_html_output(
Chris@1494 157 'double -- dashes -- test' => 'double -- dashes -- test',
Chris@1494 158 'double -- *dashes* -- test' => 'double -- <strong>dashes</strong> -- test'
Chris@1494 159 )
Chris@1494 160 end
Chris@1494 161
Chris@1494 162 def test_abbreviations
Chris@1494 163 assert_html_output(
Chris@1494 164 'this is an abbreviation: GPL(General Public License)' => 'this is an abbreviation: <abbr title="General Public License">GPL</abbr>',
Chris@1494 165 '2 letters JP(Jean-Philippe) abbreviation' => '2 letters <abbr title="Jean-Philippe">JP</abbr> abbreviation',
Chris@1494 166 'GPL(This is a double-quoted "title")' => '<abbr title="This is a double-quoted &quot;title&quot;">GPL</abbr>'
Chris@1494 167 )
Chris@1494 168 end
Chris@1494 169
Chris@1494 170 def test_blockquote
Chris@1494 171 # orig raw text
Chris@1494 172 raw = <<-RAW
Chris@1494 173 John said:
Chris@1494 174 > Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero.
Chris@1494 175 > Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor.
Chris@1494 176 > * Donec odio lorem,
Chris@1494 177 > * sagittis ac,
Chris@1494 178 > * malesuada in,
Chris@1494 179 > * adipiscing eu, dolor.
Chris@1494 180 >
Chris@1494 181 > >Nulla varius pulvinar diam. Proin id arcu id lorem scelerisque condimentum. Proin vehicula turpis vitae lacus.
Chris@1494 182 > Proin a tellus. Nam vel neque.
Chris@1494 183
Chris@1494 184 He's right.
Chris@1494 185 RAW
Chris@1494 186
Chris@1494 187 # expected html
Chris@1494 188 expected = <<-EXPECTED
Chris@1494 189 <p>John said:</p>
Chris@1494 190 <blockquote>
Chris@1494 191 Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero.<br />
Chris@1494 192 Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor.
Chris@1494 193 <ul>
Chris@1494 194 <li>Donec odio lorem,</li>
Chris@1494 195 <li>sagittis ac,</li>
Chris@1494 196 <li>malesuada in,</li>
Chris@1494 197 <li>adipiscing eu, dolor.</li>
Chris@1494 198 </ul>
Chris@1494 199 <blockquote>
Chris@1494 200 <p>Nulla varius pulvinar diam. Proin id arcu id lorem scelerisque condimentum. Proin vehicula turpis vitae lacus.</p>
Chris@1494 201 </blockquote>
Chris@1494 202 <p>Proin a tellus. Nam vel neque.</p>
Chris@1494 203 </blockquote>
Chris@1494 204 <p>He's right.</p>
Chris@1494 205 EXPECTED
Chris@1494 206
Chris@1494 207 assert_equal expected.gsub(%r{\s+}, ''), to_html(raw).gsub(%r{\s+}, '')
Chris@1494 208 end
Chris@1494 209
Chris@1494 210 def test_table
Chris@1494 211 raw = <<-RAW
Chris@1494 212 This is a table with empty cells:
Chris@1494 213
Chris@1494 214 |cell11|cell12||
Chris@1494 215 |cell21||cell23|
Chris@1494 216 |cell31|cell32|cell33|
Chris@1494 217 RAW
Chris@1494 218
Chris@1494 219 expected = <<-EXPECTED
Chris@1494 220 <p>This is a table with empty cells:</p>
Chris@1494 221
Chris@1494 222 <table>
Chris@1494 223 <tr><td>cell11</td><td>cell12</td><td></td></tr>
Chris@1494 224 <tr><td>cell21</td><td></td><td>cell23</td></tr>
Chris@1494 225 <tr><td>cell31</td><td>cell32</td><td>cell33</td></tr>
Chris@1494 226 </table>
Chris@1494 227 EXPECTED
Chris@1494 228
Chris@1494 229 assert_equal expected.gsub(%r{\s+}, ''), to_html(raw).gsub(%r{\s+}, '')
Chris@1494 230 end
Chris@1494 231
Chris@1494 232 def test_table_with_line_breaks
Chris@1494 233 raw = <<-RAW
Chris@1494 234 This is a table with line breaks:
Chris@1494 235
Chris@1494 236 |cell11
Chris@1494 237 continued|cell12||
Chris@1494 238 |-cell21-||cell23
Chris@1494 239 cell23 line2
Chris@1494 240 cell23 *line3*|
Chris@1494 241 |cell31|cell32
Chris@1494 242 cell32 line2|cell33|
Chris@1494 243
Chris@1494 244 RAW
Chris@1494 245
Chris@1494 246 expected = <<-EXPECTED
Chris@1494 247 <p>This is a table with line breaks:</p>
Chris@1494 248
Chris@1494 249 <table>
Chris@1494 250 <tr>
Chris@1494 251 <td>cell11<br />continued</td>
Chris@1494 252 <td>cell12</td>
Chris@1494 253 <td></td>
Chris@1494 254 </tr>
Chris@1494 255 <tr>
Chris@1494 256 <td><del>cell21</del></td>
Chris@1494 257 <td></td>
Chris@1494 258 <td>cell23<br/>cell23 line2<br/>cell23 <strong>line3</strong></td>
Chris@1494 259 </tr>
Chris@1494 260 <tr>
Chris@1494 261 <td>cell31</td>
Chris@1494 262 <td>cell32<br/>cell32 line2</td>
Chris@1494 263 <td>cell33</td>
Chris@1494 264 </tr>
Chris@1494 265 </table>
Chris@1494 266 EXPECTED
Chris@1494 267
Chris@1494 268 assert_equal expected.gsub(%r{\s+}, ''), to_html(raw).gsub(%r{\s+}, '')
Chris@1494 269 end
Chris@1494 270
Chris@1494 271 def test_tables_with_lists
Chris@1494 272 raw = <<-RAW
Chris@1494 273 This is a table with lists:
Chris@1494 274
Chris@1494 275 |cell11|cell12|
Chris@1494 276 |cell21|ordered list
Chris@1494 277 # item
Chris@1494 278 # item 2|
Chris@1494 279 |cell31|unordered list
Chris@1494 280 * item
Chris@1494 281 * item 2|
Chris@1494 282
Chris@1494 283 RAW
Chris@1494 284
Chris@1494 285 expected = <<-EXPECTED
Chris@1494 286 <p>This is a table with lists:</p>
Chris@1494 287
Chris@1494 288 <table>
Chris@1494 289 <tr>
Chris@1494 290 <td>cell11</td>
Chris@1494 291 <td>cell12</td>
Chris@1494 292 </tr>
Chris@1494 293 <tr>
Chris@1494 294 <td>cell21</td>
Chris@1494 295 <td>ordered list<br /># item<br /># item 2</td>
Chris@1494 296 </tr>
Chris@1494 297 <tr>
Chris@1494 298 <td>cell31</td>
Chris@1494 299 <td>unordered list<br />* item<br />* item 2</td>
Chris@1494 300 </tr>
Chris@1494 301 </table>
Chris@1494 302 EXPECTED
Chris@1494 303
Chris@1494 304 assert_equal expected.gsub(%r{\s+}, ''), to_html(raw).gsub(%r{\s+}, '')
Chris@1494 305 end
Chris@1494 306
Chris@1494 307 def test_textile_should_not_mangle_brackets
Chris@1494 308 assert_equal '<p>[msg1][msg2]</p>', to_html('[msg1][msg2]')
Chris@1494 309 end
Chris@1494 310
Chris@1494 311 def test_textile_should_escape_image_urls
Chris@1494 312 # this is onclick="alert('XSS');" in encoded form
Chris@1494 313 raw = '!/images/comment.png"onclick=&#x61;&#x6c;&#x65;&#x72;&#x74;&#x28;&#x27;&#x58;&#x53;&#x53;&#x27;&#x29;;&#x22;!'
Chris@1494 314 expected = '<p><img src="/images/comment.png&quot;onclick=&amp;#x61;&amp;#x6c;&amp;#x65;&amp;#x72;&amp;#x74;&amp;#x28;&amp;#x27;&amp;#x58;&amp;#x53;&amp;#x53;&amp;#x27;&amp;#x29;;&amp;#x22;" alt="" /></p>'
Chris@1494 315 assert_equal expected.gsub(%r{\s+}, ''), to_html(raw).gsub(%r{\s+}, '')
Chris@1494 316 end
Chris@1494 317
Chris@1494 318
Chris@1494 319 STR_WITHOUT_PRE = [
Chris@1494 320 # 0
Chris@1494 321 "h1. Title
Chris@1494 322
Chris@1494 323 Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero.",
Chris@1494 324 # 1
Chris@1494 325 "h2. Heading 2
Chris@1494 326
Chris@1494 327 Maecenas sed elit sit amet mi accumsan vestibulum non nec velit. Proin porta tincidunt lorem, consequat rhoncus dolor fermentum in.
Chris@1494 328
Chris@1494 329 Cras ipsum felis, ultrices at porttitor vel, faucibus eu nunc.",
Chris@1494 330 # 2
Chris@1494 331 "h2. Heading 2
Chris@1494 332
Chris@1494 333 Morbi facilisis accumsan orci non pharetra.
Chris@1494 334
Chris@1494 335 h3. Heading 3
Chris@1494 336
Chris@1494 337 Nulla nunc nisi, egestas in ornare vel, posuere ac libero.",
Chris@1494 338 # 3
Chris@1494 339 "h3. Heading 3
Chris@1494 340
Chris@1494 341 Praesent eget turpis nibh, a lacinia nulla.",
Chris@1494 342 # 4
Chris@1494 343 "h2. Heading 2
Chris@1494 344
Chris@1494 345 Ut rhoncus elementum adipiscing."]
Chris@1494 346
Chris@1494 347 TEXT_WITHOUT_PRE = STR_WITHOUT_PRE.join("\n\n").freeze
Chris@1494 348
Chris@1494 349 def test_get_section_should_return_the_requested_section_and_its_hash
Chris@1494 350 assert_section_with_hash STR_WITHOUT_PRE[1], TEXT_WITHOUT_PRE, 2
Chris@1494 351 assert_section_with_hash STR_WITHOUT_PRE[2..3].join("\n\n"), TEXT_WITHOUT_PRE, 3
Chris@1494 352 assert_section_with_hash STR_WITHOUT_PRE[3], TEXT_WITHOUT_PRE, 5
Chris@1494 353 assert_section_with_hash STR_WITHOUT_PRE[4], TEXT_WITHOUT_PRE, 6
Chris@1494 354
Chris@1494 355 assert_section_with_hash '', TEXT_WITHOUT_PRE, 0
Chris@1494 356 assert_section_with_hash '', TEXT_WITHOUT_PRE, 10
Chris@1494 357 end
Chris@1494 358
Chris@1494 359 def test_update_section_should_update_the_requested_section
Chris@1494 360 replacement = "New text"
Chris@1494 361
Chris@1494 362 assert_equal [STR_WITHOUT_PRE[0], replacement, STR_WITHOUT_PRE[2..4]].flatten.join("\n\n"), @formatter.new(TEXT_WITHOUT_PRE).update_section(2, replacement)
Chris@1494 363 assert_equal [STR_WITHOUT_PRE[0..1], replacement, STR_WITHOUT_PRE[4]].flatten.join("\n\n"), @formatter.new(TEXT_WITHOUT_PRE).update_section(3, replacement)
Chris@1494 364 assert_equal [STR_WITHOUT_PRE[0..2], replacement, STR_WITHOUT_PRE[4]].flatten.join("\n\n"), @formatter.new(TEXT_WITHOUT_PRE).update_section(5, replacement)
Chris@1494 365 assert_equal [STR_WITHOUT_PRE[0..3], replacement].flatten.join("\n\n"), @formatter.new(TEXT_WITHOUT_PRE).update_section(6, replacement)
Chris@1494 366
Chris@1494 367 assert_equal TEXT_WITHOUT_PRE, @formatter.new(TEXT_WITHOUT_PRE).update_section(0, replacement)
Chris@1494 368 assert_equal TEXT_WITHOUT_PRE, @formatter.new(TEXT_WITHOUT_PRE).update_section(10, replacement)
Chris@1494 369 end
Chris@1494 370
Chris@1494 371 def test_update_section_with_hash_should_update_the_requested_section
Chris@1494 372 replacement = "New text"
Chris@1494 373
Chris@1494 374 assert_equal [STR_WITHOUT_PRE[0], replacement, STR_WITHOUT_PRE[2..4]].flatten.join("\n\n"),
Chris@1494 375 @formatter.new(TEXT_WITHOUT_PRE).update_section(2, replacement, Digest::MD5.hexdigest(STR_WITHOUT_PRE[1]))
Chris@1494 376 end
Chris@1494 377
Chris@1494 378 def test_update_section_with_wrong_hash_should_raise_an_error
Chris@1494 379 assert_raise Redmine::WikiFormatting::StaleSectionError do
Chris@1494 380 @formatter.new(TEXT_WITHOUT_PRE).update_section(2, "New text", Digest::MD5.hexdigest("Old text"))
Chris@1494 381 end
Chris@1494 382 end
Chris@1494 383
Chris@1494 384 STR_WITH_PRE = [
Chris@1494 385 # 0
Chris@1494 386 "h1. Title
Chris@1494 387
Chris@1494 388 Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero.",
Chris@1494 389 # 1
Chris@1494 390 "h2. Heading 2
Chris@1494 391
Chris@1494 392 <pre><code class=\"ruby\">
Chris@1494 393 def foo
Chris@1494 394 end
Chris@1494 395 </code></pre>
Chris@1494 396
Chris@1494 397 <pre><code><pre><code class=\"ruby\">
Chris@1494 398 Place your code here.
Chris@1494 399 </code></pre>
Chris@1494 400 </code></pre>
Chris@1494 401
Chris@1494 402 Morbi facilisis accumsan orci non pharetra.
Chris@1494 403
Chris@1494 404 <pre>
Chris@1494 405 Pre Content:
Chris@1494 406
Chris@1494 407 h2. Inside pre
Chris@1494 408
Chris@1494 409 <tag> inside pre block
Chris@1494 410
Chris@1494 411 Morbi facilisis accumsan orci non pharetra.
Chris@1494 412 </pre>",
Chris@1494 413 # 2
Chris@1494 414 "h3. Heading 3
Chris@1494 415
Chris@1494 416 Nulla nunc nisi, egestas in ornare vel, posuere ac libero."]
Chris@1494 417
Chris@1494 418 def test_get_section_should_ignore_pre_content
Chris@1494 419 text = STR_WITH_PRE.join("\n\n")
Chris@1494 420
Chris@1494 421 assert_section_with_hash STR_WITH_PRE[1..2].join("\n\n"), text, 2
Chris@1494 422 assert_section_with_hash STR_WITH_PRE[2], text, 3
Chris@1494 423 end
Chris@1494 424
Chris@1494 425 def test_update_section_should_not_escape_pre_content_outside_section
Chris@1494 426 text = STR_WITH_PRE.join("\n\n")
Chris@1494 427 replacement = "New text"
Chris@1494 428
Chris@1494 429 assert_equal [STR_WITH_PRE[0..1], "New text"].flatten.join("\n\n"),
Chris@1494 430 @formatter.new(text).update_section(3, replacement)
Chris@1494 431 end
Chris@1494 432
Chris@1494 433 def test_get_section_should_support_lines_with_spaces_before_heading
Chris@1494 434 # the lines after Content 2 and Heading 4 contain a space
Chris@1494 435 text = <<-STR
Chris@1494 436 h1. Heading 1
Chris@1494 437
Chris@1494 438 Content 1
Chris@1494 439
Chris@1494 440 h1. Heading 2
Chris@1494 441
Chris@1494 442 Content 2
Chris@1494 443
Chris@1494 444 h1. Heading 3
Chris@1494 445
Chris@1494 446 Content 3
Chris@1494 447
Chris@1494 448 h1. Heading 4
Chris@1494 449
Chris@1494 450 Content 4
Chris@1494 451 STR
Chris@1494 452
Chris@1494 453 [1, 2, 3, 4].each do |index|
Chris@1494 454 assert_match /\Ah1. Heading #{index}.+Content #{index}/m, @formatter.new(text).get_section(index).first
Chris@1494 455 end
Chris@1494 456 end
Chris@1494 457
Chris@1494 458 def test_get_section_should_support_headings_starting_with_a_tab
Chris@1494 459 text = <<-STR
Chris@1494 460 h1.\tHeading 1
Chris@1494 461
Chris@1494 462 Content 1
Chris@1494 463
Chris@1494 464 h1. Heading 2
Chris@1494 465
Chris@1494 466 Content 2
Chris@1494 467 STR
Chris@1494 468
Chris@1494 469 assert_match /\Ah1.\tHeading 1\s+Content 1\z/, @formatter.new(text).get_section(1).first
Chris@1494 470 end
Chris@1494 471
Chris@1494 472 private
Chris@1494 473
Chris@1494 474 def assert_html_output(to_test, expect_paragraph = true)
Chris@1494 475 to_test.each do |text, expected|
Chris@1494 476 assert_equal(( expect_paragraph ? "<p>#{expected}</p>" : expected ), @formatter.new(text).to_html, "Formatting the following text failed:\n===\n#{text}\n===\n")
Chris@1494 477 end
Chris@1494 478 end
Chris@1494 479
Chris@1494 480 def to_html(text)
Chris@1494 481 @formatter.new(text).to_html
Chris@1494 482 end
Chris@1494 483
Chris@1494 484 def assert_section_with_hash(expected, text, index)
Chris@1494 485 result = @formatter.new(text).get_section(index)
Chris@1494 486
Chris@1494 487 assert_kind_of Array, result
Chris@1494 488 assert_equal 2, result.size
Chris@1494 489 assert_equal expected, result.first, "section content did not match"
Chris@1494 490 assert_equal Digest::MD5.hexdigest(expected), result.last, "section hash did not match"
Chris@1494 491 end
Chris@1494 492 end