annotate vendor/gems/coderay-1.0.0/test/functional/for_redcloth.rb @ 1477:f2ad2199b49a bibplugin_integration

Close obsolete branch bibplugin_integration
author Chris Cannam
date Fri, 30 Nov 2012 14:41:31 +0000
parents cbb26bc654de
children
rev   line source
Chris@909 1 require 'test/unit'
Chris@909 2 require File.expand_path('../../lib/assert_warning', __FILE__)
Chris@909 3
Chris@909 4 $:.unshift File.expand_path('../../../lib', __FILE__)
Chris@909 5 require 'coderay'
Chris@909 6
Chris@909 7 begin
Chris@909 8 require 'rubygems' unless defined? Gem
Chris@909 9 gem 'RedCloth', '>= 4.0.3' rescue nil
Chris@909 10 require 'redcloth'
Chris@909 11 rescue LoadError
Chris@909 12 warn 'RedCloth not found - skipping for_redcloth tests.'
Chris@909 13 undef RedCloth if defined? RedCloth
Chris@909 14 end
Chris@909 15
Chris@909 16 class BasicTest < Test::Unit::TestCase
Chris@909 17
Chris@909 18 def test_for_redcloth
Chris@909 19 require 'coderay/for_redcloth'
Chris@909 20 assert_equal "<p><span lang=\"ruby\" class=\"CodeRay\">puts <span style=\"background-color:hsla(0,100%,50%,0.05)\"><span style=\"color:#710\">&quot;</span><span style=\"color:#D20\">Hello, World!</span><span style=\"color:#710\">&quot;</span></span></span></p>",
Chris@909 21 RedCloth.new('@[ruby]puts "Hello, World!"@').to_html
Chris@909 22 assert_equal <<-BLOCKCODE.chomp,
Chris@909 23 <div lang="ruby" class="CodeRay">
Chris@909 24 <div class="code"><pre>puts <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">&quot;</span><span style="color:#D20">Hello, World!</span><span style="color:#710">&quot;</span></span></pre></div>
Chris@909 25 </div>
Chris@909 26 BLOCKCODE
Chris@909 27 RedCloth.new('bc[ruby]. puts "Hello, World!"').to_html
Chris@909 28 end
Chris@909 29
Chris@909 30 def test_for_redcloth_no_lang
Chris@909 31 require 'coderay/for_redcloth'
Chris@909 32 assert_equal "<p><code>puts \"Hello, World!\"</code></p>",
Chris@909 33 RedCloth.new('@puts "Hello, World!"@').to_html
Chris@909 34 assert_equal <<-BLOCKCODE.chomp,
Chris@909 35 <pre><code>puts \"Hello, World!\"</code></pre>
Chris@909 36 BLOCKCODE
Chris@909 37 RedCloth.new('bc. puts "Hello, World!"').to_html
Chris@909 38 end
Chris@909 39
Chris@909 40 def test_for_redcloth_style
Chris@909 41 require 'coderay/for_redcloth'
Chris@909 42 assert_equal <<-BLOCKCODE.chomp,
Chris@909 43 <pre style=\"color: red;\"><code style=\"color: red;\">puts \"Hello, World!\"</code></pre>
Chris@909 44 BLOCKCODE
Chris@909 45 RedCloth.new('bc{color: red}. puts "Hello, World!"').to_html
Chris@909 46 end
Chris@909 47
Chris@909 48 def test_for_redcloth_escapes
Chris@909 49 require 'coderay/for_redcloth'
Chris@909 50 assert_equal '<p><span lang="ruby" class="CodeRay">&gt;</span></p>',
Chris@909 51 RedCloth.new('@[ruby]>@').to_html
Chris@909 52 assert_equal <<-BLOCKCODE.chomp,
Chris@909 53 <div lang="ruby" class="CodeRay">
Chris@909 54 <div class="code"><pre>&amp;</pre></div>
Chris@909 55 </div>
Chris@909 56 BLOCKCODE
Chris@909 57 RedCloth.new('bc[ruby]. &').to_html
Chris@909 58 end
Chris@909 59
Chris@909 60 def test_for_redcloth_escapes2
Chris@909 61 require 'coderay/for_redcloth'
Chris@909 62 assert_equal "<p><span lang=\"c\" class=\"CodeRay\"><span style=\"color:#579\">#include</span> <span style=\"color:#B44;font-weight:bold\">&lt;test.h&gt;</span></span></p>",
Chris@909 63 RedCloth.new('@[c]#include <test.h>@').to_html
Chris@909 64 end
Chris@909 65
Chris@909 66 # See http://jgarber.lighthouseapp.com/projects/13054/tickets/124-code-markup-does-not-allow-brackets.
Chris@909 67 def test_for_redcloth_false_positive
Chris@909 68 require 'coderay/for_redcloth'
Chris@909 69 assert_warning 'CodeRay::Scanners could not load plugin :project; falling back to :text' do
Chris@909 70 assert_equal '<p><code>[project]_dff.skjd</code></p>',
Chris@909 71 RedCloth.new('@[project]_dff.skjd@').to_html
Chris@909 72 end
Chris@909 73 # false positive, but expected behavior / known issue
Chris@909 74 assert_equal "<p><span lang=\"ruby\" class=\"CodeRay\">_dff.skjd</span></p>",
Chris@909 75 RedCloth.new('@[ruby]_dff.skjd@').to_html
Chris@909 76 assert_warning 'CodeRay::Scanners could not load plugin :project; falling back to :text' do
Chris@909 77 assert_equal <<-BLOCKCODE.chomp,
Chris@909 78 <pre><code>[project]_dff.skjd</code></pre>
Chris@909 79 BLOCKCODE
Chris@909 80 RedCloth.new('bc. [project]_dff.skjd').to_html
Chris@909 81 end
Chris@909 82 end
Chris@909 83
Chris@909 84 end if defined? RedCloth