metasploit-framework /lib/gemcache/ruby/1.9.1/gems/tilt-1.3.3/test/tilt_markdown_test.rb

Language Ruby Lines 162
MD5 Hash df491fffb2f7d6d65ce7ae0bc8bb5a15 Estimated Cost $2,916 (why?)
Repository https://bitbucket.org/technopunk2099/metasploit-framework.git View Raw File View Project SPDX
  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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# coding: UTF-8
require 'tilt'

begin
require 'nokogiri'

module MarkdownTests
  def self.included(mod)
    class << mod
      def template(t = nil)
        t.nil? ? @template : @template = t
      end
    end
  end

  def render(text, options = {})
    self.class.template.new(options) { text }.render
  end

  def normalize(html)
    Nokogiri::HTML.fragment(html).to_s
  end

  def nrender(text, options = {})
    html = render(text, options)
    html.encode!("UTF-8") if html.respond_to?(:encode)
    normalize(html)
  end
  
  def test_escape_html
    html = nrender "Hello <b>World</b>"
    assert_equal "<p>Hello <b>World</b></p>", html
  end

  def test_escape_html_false
    html = nrender "Hello <b>World</b>", :escape_html => false
    assert_equal "<p>Hello <b>World</b></p>", html
  end

  def test_escape_html_true
    if self.class.template == Tilt::RedcarpetTemplate
      flunk "redcarpet doesn't support :escape_html yet"
    end
    html = nrender "Hello <b>World</b>", :escape_html => true
    assert_equal "<p>Hello &lt;b&gt;World&lt;/b&gt;</p>", html
  end

  def test_smart_quotes
    html = nrender 'Hello "World"'
    assert_equal '<p>Hello "World"</p>', html
  end

  def test_smart_quotes_false
    html = nrender 'Hello "World"', :smartypants => false
    assert_equal '<p>Hello "World"</p>', html
  end

  def test_smart_quotes_true
    html = nrender 'Hello "World"', :smartypants => true
    assert_equal '<p>Hello “World”</p>', html
  end

  def test_smarty_pants
    html = nrender "Hello ``World'' -- This is --- a test ..."
    assert_equal "<p>Hello ``World'' -- This is --- a test ...</p>", html
  end

  def test_smarty_pants_false
    html = nrender "Hello ``World'' -- This is --- a test ...", :smartypants => false
    assert_equal "<p>Hello ``World'' -- This is --- a test ...</p>", html
  end

  def test_smarty_pants_true
    html = nrender "Hello ``World'' -- This is --- a test ...", :smartypants => true
    assert_equal "<p>Hello “World” — This is —– a test …</p>", html
  end
end

begin
  require 'rdiscount'

  class MarkdownRDiscountTest < Test::Unit::TestCase
    include MarkdownTests
    template Tilt::RDiscountTemplate
  end
rescue LoadError => boom
  # It should already be warned in the main tests
end

begin
  require 'redcarpet'

  class MarkdownRedcarpetTest < Test::Unit::TestCase
    include MarkdownTests
    template Tilt::RedcarpetTemplate
    # Doesn't support escaping
    undef test_escape_html_true

    def test_smarty_pants_true
      html = nrender "Hello ``World'' -- This is --- a test ...", :smartypants => true
      assert_equal "<p>Hello “World” – This is — a test …</p>", html
    end
  end
rescue LoadError => boom
  # It should already be warned in the main tests
end

begin
  require 'bluecloth'

  class MarkdownBlueClothTest < Test::Unit::TestCase
    include MarkdownTests
    template Tilt::BlueClothTemplate
  end
rescue LoadError => boom
  # It should already be warned in the main tests
end

begin
  require 'kramdown'

  class MarkdownKramdownTest < Test::Unit::TestCase
    include MarkdownTests
    template Tilt::KramdownTemplate
    # Doesn't support escaping
    undef test_escape_html_true
    # Smarty Pants is *always* on, but doesn't support it fully
    undef test_smarty_pants
    undef test_smarty_pants_false
    undef test_smarty_pants_true
  end
rescue LoadError => boom
  # It should already be warned in the main tests
end

  
begin
  require 'maruku'

  class MarkdownMarukuTest < Test::Unit::TestCase
    include MarkdownTests
    template Tilt::MarukuTemplate
    # Doesn't support escaping
    undef test_escape_html_true
    # Doesn't support Smarty Pants, and even fails on ``Foobar''
    undef test_smarty_pants
    undef test_smarty_pants_false
    undef test_smarty_pants_true
    # Smart Quotes is always on
    undef test_smart_quotes
    undef test_smart_quotes_false
  end
rescue LoadError => boom
  # It should already be warned in the main tests
end

rescue LoadError
  warn "Markdown tests need Nokogiri\n"
end
Back to Top