PageRenderTime 53ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/bundle/ruby/1.9.1/gems/tilt-1.3.3/test/tilt_markdown_test.rb

https://bitbucket.org/mulligan/extractext
Ruby | 161 lines | 132 code | 19 blank | 10 comment | 3 complexity | df491fffb2f7d6d65ce7ae0bc8bb5a15 MD5 | raw file
Possible License(s): Apache-2.0, MIT, GPL-3.0, GPL-2.0, BSD-3-Clause, MPL-2.0-no-copyleft-exception, BSD-2-Clause, JSON
  1. # coding: UTF-8
  2. require 'tilt'
  3. begin
  4. require 'nokogiri'
  5. module MarkdownTests
  6. def self.included(mod)
  7. class << mod
  8. def template(t = nil)
  9. t.nil? ? @template : @template = t
  10. end
  11. end
  12. end
  13. def render(text, options = {})
  14. self.class.template.new(options) { text }.render
  15. end
  16. def normalize(html)
  17. Nokogiri::HTML.fragment(html).to_s
  18. end
  19. def nrender(text, options = {})
  20. html = render(text, options)
  21. html.encode!("UTF-8") if html.respond_to?(:encode)
  22. normalize(html)
  23. end
  24. def test_escape_html
  25. html = nrender "Hello <b>World</b>"
  26. assert_equal "<p>Hello <b>World</b></p>", html
  27. end
  28. def test_escape_html_false
  29. html = nrender "Hello <b>World</b>", :escape_html => false
  30. assert_equal "<p>Hello <b>World</b></p>", html
  31. end
  32. def test_escape_html_true
  33. if self.class.template == Tilt::RedcarpetTemplate
  34. flunk "redcarpet doesn't support :escape_html yet"
  35. end
  36. html = nrender "Hello <b>World</b>", :escape_html => true
  37. assert_equal "<p>Hello &lt;b&gt;World&lt;/b&gt;</p>", html
  38. end
  39. def test_smart_quotes
  40. html = nrender 'Hello "World"'
  41. assert_equal '<p>Hello "World"</p>', html
  42. end
  43. def test_smart_quotes_false
  44. html = nrender 'Hello "World"', :smartypants => false
  45. assert_equal '<p>Hello "World"</p>', html
  46. end
  47. def test_smart_quotes_true
  48. html = nrender 'Hello "World"', :smartypants => true
  49. assert_equal '<p>Hello “World”</p>', html
  50. end
  51. def test_smarty_pants
  52. html = nrender "Hello ``World'' -- This is --- a test ..."
  53. assert_equal "<p>Hello ``World'' -- This is --- a test ...</p>", html
  54. end
  55. def test_smarty_pants_false
  56. html = nrender "Hello ``World'' -- This is --- a test ...", :smartypants => false
  57. assert_equal "<p>Hello ``World'' -- This is --- a test ...</p>", html
  58. end
  59. def test_smarty_pants_true
  60. html = nrender "Hello ``World'' -- This is --- a test ...", :smartypants => true
  61. assert_equal "<p>Hello “World” — This is —– a test …</p>", html
  62. end
  63. end
  64. begin
  65. require 'rdiscount'
  66. class MarkdownRDiscountTest < Test::Unit::TestCase
  67. include MarkdownTests
  68. template Tilt::RDiscountTemplate
  69. end
  70. rescue LoadError => boom
  71. # It should already be warned in the main tests
  72. end
  73. begin
  74. require 'redcarpet'
  75. class MarkdownRedcarpetTest < Test::Unit::TestCase
  76. include MarkdownTests
  77. template Tilt::RedcarpetTemplate
  78. # Doesn't support escaping
  79. undef test_escape_html_true
  80. def test_smarty_pants_true
  81. html = nrender "Hello ``World'' -- This is --- a test ...", :smartypants => true
  82. assert_equal "<p>Hello “World” – This is — a test …</p>", html
  83. end
  84. end
  85. rescue LoadError => boom
  86. # It should already be warned in the main tests
  87. end
  88. begin
  89. require 'bluecloth'
  90. class MarkdownBlueClothTest < Test::Unit::TestCase
  91. include MarkdownTests
  92. template Tilt::BlueClothTemplate
  93. end
  94. rescue LoadError => boom
  95. # It should already be warned in the main tests
  96. end
  97. begin
  98. require 'kramdown'
  99. class MarkdownKramdownTest < Test::Unit::TestCase
  100. include MarkdownTests
  101. template Tilt::KramdownTemplate
  102. # Doesn't support escaping
  103. undef test_escape_html_true
  104. # Smarty Pants is *always* on, but doesn't support it fully
  105. undef test_smarty_pants
  106. undef test_smarty_pants_false
  107. undef test_smarty_pants_true
  108. end
  109. rescue LoadError => boom
  110. # It should already be warned in the main tests
  111. end
  112. begin
  113. require 'maruku'
  114. class MarkdownMarukuTest < Test::Unit::TestCase
  115. include MarkdownTests
  116. template Tilt::MarukuTemplate
  117. # Doesn't support escaping
  118. undef test_escape_html_true
  119. # Doesn't support Smarty Pants, and even fails on ``Foobar''
  120. undef test_smarty_pants
  121. undef test_smarty_pants_false
  122. undef test_smarty_pants_true
  123. # Smart Quotes is always on
  124. undef test_smart_quotes
  125. undef test_smart_quotes_false
  126. end
  127. rescue LoadError => boom
  128. # It should already be warned in the main tests
  129. end
  130. rescue LoadError
  131. warn "Markdown tests need Nokogiri\n"
  132. end