File: markdown_spec.rb

package info (click to toggle)
yard 0.9.38-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,736 kB
  • sloc: ruby: 31,680; javascript: 7,658; makefile: 21
file content (99 lines) | stat: -rw-r--r-- 2,634 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# frozen_string_literal: true

require File.dirname(__FILE__) + '/integration_spec_helper'

RSpec.describe 'Markdown processors integration' do
  include_context 'shared helpers for markup processor integration specs'

  shared_examples 'shared examples for markdown processors' do
    let(:document) do
    <<-MARKDOWN
## Example code listings

Indented block of Ruby code:

    x = 1

Fenced block of Ruby code:

```
x = 2
```

Fenced and annotated block of Ruby code:

```ruby
x = 3
```

Fenced and annotated block of non-Ruby code:

```plain
x = 4
```

### Example line break

commonmark line break with\\
a backslash
MARKDOWN
    end

    it 'renders level 2 header' do
      expect(rendered_document).to match(header_regexp(2, 'Example code listings'))
    end

    it 'renders indented block of code, and applies Ruby syntax highlight' do
      expect(rendered_document).to match(highlighted_ruby_regexp('x', '=', '1'))
    end

    it 'renders fenced block of code, and applies Ruby syntax highlight' do
      expect(rendered_document).to match(highlighted_ruby_regexp('x', '=', '2'))
    end

    it 'renders fenced and annotated block of Ruby code, and applies syntax highlight' do
      expect(rendered_document).to match(highlighted_ruby_regexp('x', '=', '3'))
    end

    it 'renders fenced and annotated block of non-Ruby code, and does not apply syntax highlight' do
      expect(rendered_document).to match('x = 4')
    end

    it "autolinks URLs" do
      expect(html_renderer.htmlify('http://example.com', :markdown).chomp.gsub('&#47;', '/')).to eq(
        '<p><a href="http://example.com">http://example.com</a></p>'
      )
    end
  end

  describe 'Redcarpet' do
    let(:markup) { :markdown }
    let(:markup_provider) { :redcarpet }

    include_examples 'shared examples for markdown processors'


    it 'generates anchor tags for level 2 header' do
      expect(rendered_document).to include('<h2 id="example-code-listings">Example code listings</h2>')
    end

    it 'does not create line break via backslash' do
      expect(rendered_document).to include("commonmark line break with\\\na backslash")
    end
  end

  describe 'CommonMarker', if:  RUBY_VERSION >= '2.3' do
    let(:markup) { :markdown }
    let(:markup_provider) { :commonmarker }

    include_examples 'shared examples for markdown processors'

    it 'generates level 2 header without id' do
      expect(rendered_document).to include('<h2>Example code listings</h2>')
    end

    it 'creates line break via backslash' do
      expect(rendered_document).to include("commonmark line break with<br />\na backslash")
    end
  end
end