0004-CommonMark-formatter_test.rb.patch

Tests for #35036 - shared implementation with current Markdown formatter - Martin Cizek, 2021-04-05 16:31

Download (2.09 KB)

View differences:

test/unit/lib/redmine/wiki_formatting/common_mark/formatter_test.rb
208 208
      @formatter.new(text).update_section(3, replacement)
209 209
  end
210 210

  
211
  STR_SETEXT_LIKE = [
212
    # 0
213
    <<~STR.chomp,
214
      # Title
215
    STR
216
    # 1
217
    <<~STR.chomp,
218
      ## Heading 2
219

  
220
      Thematic breaks - not be confused with setext headings.
221

  
222
      ---
223

  
224
      Preceding CRLF is the default for web-submitted data.
225
      \r
226
      ---\r
227
      \r
228

  
229
      A space-only line does not mean much.
230
      \s
231
      ---
232

  
233
      End of thematic breaks.
234
    STR
235
    # 2
236
    <<~STR.chomp,
237
      ## Heading 2
238
      Nulla nunc nisi, egestas in ornare vel, posuere ac libero.
239
    STR
240
  ]
241

  
242
  STR_RARE_SETEXT_LIKE = [
243
    # 0
244
    <<~STR.chomp,
245
      # Title
246
    STR
247
    # 1
248
    <<~STR.chomp,
249
      ## Heading 2
250

  
251
      - item
252
      one
253
      -
254
      not a heading
255
    STR
256
    # 2
257
    <<~STR.chomp,
258
      ## Heading 2
259
      Nulla nunc nisi, egestas in ornare vel, posuere ac libero.
260
    STR
261
  ]
262

  
263
  def test_get_section_should_ignore_setext_like_text
264
    text = STR_SETEXT_LIKE.join("\n\n")
265
    assert_section_with_hash STR_SETEXT_LIKE[1], text, 2
266
    assert_section_with_hash STR_SETEXT_LIKE[2], text, 3
267
  end
268

  
269
  def test_get_section_should_ignore_rare_setext_like_text
270
    begin
271
      text = STR_RARE_SETEXT_LIKE.join("\n\n")
272
      assert_section_with_hash STR_RARE_SETEXT_LIKE[1], text, 2
273
      assert_section_with_hash STR_RARE_SETEXT_LIKE[2], text, 3
274
    rescue Minitest::Assertion => e
275
      skip "Section extraction is currently limited, see #35037. Known error: #{e.message}"
276
    end
277
    refute "This test should be adjusted when fixing the known error."
278
  end
279

  
211 280
  def test_should_emphasize_text
212 281
    text = 'This _text_ should be emphasized'
213 282
    assert_equal '<p>This <em>text</em> should be emphasized</p>', format(text)