File: test_redcarpet.rb

package info (click to toggle)
jekyll 3.1.6%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 3,820 kB
  • ctags: 997
  • sloc: ruby: 10,045; sh: 145; xml: 59; makefile: 28
file content (88 lines) | stat: -rw-r--r-- 2,699 bytes parent folder | download
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
require 'helper'

class TestRedcarpet < JekyllUnitTest
  context "redcarpet" do
    setup do
      if jruby?
        then skip(
          "JRuby does not perform well with CExt, test disabled."
        )
      end

      @config = {
        'markdown' => 'redcarpet',
        'redcarpet' => {
          'extensions' => [
            'smart', 'strikethrough', 'filter_html'
          ]
        }
      }

      @markdown = Converters::Markdown.new @config
    end

    should "pass redcarpet options" do
      assert_equal "<h1>Some Header</h1>", @markdown.convert('# Some Header #').strip
    end

    should "pass redcarpet SmartyPants options" do
      assert_equal "<p>&ldquo;smart&rdquo;</p>", @markdown.convert('"smart"').strip
    end

    should "pass redcarpet extensions" do
      assert_equal "<p><del>deleted</del></p>", @markdown.convert('~~deleted~~').strip
    end

    should "pass redcarpet render options" do
      assert_equal "<p><strong>bad code not here</strong>: i am bad</p>", @markdown.convert('**bad code not here**: <script>i am bad</script>').strip
    end

    context "with pygments enabled" do
      setup do
        @markdown = Converters::Markdown.new @config.merge({ 'highlighter' => 'pygments' })
      end

      should "render fenced code blocks with syntax highlighting" do
        assert_equal "<div class=\"highlight\"><pre><code class=\"language-ruby\" data-lang=\"ruby\"><span class=\"nb\">puts</span> <span class=\"s2\">&quot;Hello world&quot;</span>\n</code></pre></div>", @markdown.convert(
          <<-EOS
```ruby
puts "Hello world"
```
          EOS
        ).strip.gsub(/<span><\/span>/,"")
      end
    end

    context "with rouge enabled" do
      setup do
        @markdown = Converters::Markdown.new @config.merge({ 'highlighter' => 'rouge' })
      end

      should "render fenced code blocks with syntax highlighting" do
        assert_equal "<div class=\"highlight\"><pre><code class=\"language-ruby\" data-lang=\"ruby\"><span class=\"nb\">puts</span> <span class=\"s2\">\"Hello world\"</span>\n</code></pre></div>", @markdown.convert(
          <<-EOS
```ruby
puts "Hello world"
```
          EOS
        ).strip
      end
    end

    context "without any highlighter" do
      setup do
        @markdown = Converters::Markdown.new @config.merge({ 'highlighter' => nil })
      end

      should "render fenced code blocks without syntax highlighting" do
        assert_equal "<figure class=\"highlight\"><pre><code class=\"language-ruby\" data-lang=\"ruby\">puts &quot;Hello world&quot;\n</code></pre></figure>", @markdown.convert(
          <<-EOS
```ruby
puts "Hello world"
```
          EOS
        ).strip
      end
    end
  end
end