To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / .svn / pristine / d2 / d2ab451eb617526d561093c390e63e0839289e3b.svn-base @ 1297:0a574315af3e
History | View | Annotate | Download (3.3 KB)
| 1 |
require 'test/unit' |
|---|---|
| 2 |
require File.expand_path('../../lib/assert_warning', __FILE__)
|
| 3 |
|
| 4 |
$:.unshift File.expand_path('../../../lib', __FILE__)
|
| 5 |
require 'coderay' |
| 6 |
|
| 7 |
begin |
| 8 |
require 'rubygems' unless defined? Gem |
| 9 |
gem 'RedCloth', '>= 4.0.3' rescue nil |
| 10 |
require 'redcloth' |
| 11 |
rescue LoadError |
| 12 |
warn 'RedCloth not found - skipping for_redcloth tests.' |
| 13 |
undef RedCloth if defined? RedCloth |
| 14 |
end |
| 15 |
|
| 16 |
class BasicTest < Test::Unit::TestCase |
| 17 |
|
| 18 |
def test_for_redcloth |
| 19 |
require 'coderay/for_redcloth' |
| 20 |
assert_equal "<p><span lang=\"ruby\" class=\"CodeRay\">puts <span style=\"background-color:hsla(0,100%,50%,0.05)\"><span style=\"color:#710\">"</span><span style=\"color:#D20\">Hello, World!</span><span style=\"color:#710\">"</span></span></span></p>", |
| 21 |
RedCloth.new('@[ruby]puts "Hello, World!"@').to_html
|
| 22 |
assert_equal <<-BLOCKCODE.chomp, |
| 23 |
<div lang="ruby" class="CodeRay"> |
| 24 |
<div class="code"><pre>puts <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">Hello, World!</span><span style="color:#710">"</span></span></pre></div> |
| 25 |
</div> |
| 26 |
BLOCKCODE |
| 27 |
RedCloth.new('bc[ruby]. puts "Hello, World!"').to_html
|
| 28 |
end |
| 29 |
|
| 30 |
def test_for_redcloth_no_lang |
| 31 |
require 'coderay/for_redcloth' |
| 32 |
assert_equal "<p><code>puts \"Hello, World!\"</code></p>", |
| 33 |
RedCloth.new('@puts "Hello, World!"@').to_html
|
| 34 |
assert_equal <<-BLOCKCODE.chomp, |
| 35 |
<pre><code>puts \"Hello, World!\"</code></pre> |
| 36 |
BLOCKCODE |
| 37 |
RedCloth.new('bc. puts "Hello, World!"').to_html
|
| 38 |
end |
| 39 |
|
| 40 |
def test_for_redcloth_style |
| 41 |
require 'coderay/for_redcloth' |
| 42 |
assert_equal <<-BLOCKCODE.chomp, |
| 43 |
<pre style=\"color: red;\"><code style=\"color: red;\">puts \"Hello, World!\"</code></pre> |
| 44 |
BLOCKCODE |
| 45 |
RedCloth.new('bc{color: red}. puts "Hello, World!"').to_html
|
| 46 |
end |
| 47 |
|
| 48 |
def test_for_redcloth_escapes |
| 49 |
require 'coderay/for_redcloth' |
| 50 |
assert_equal '<p><span lang="ruby" class="CodeRay">></span></p>', |
| 51 |
RedCloth.new('@[ruby]>@').to_html
|
| 52 |
assert_equal <<-BLOCKCODE.chomp, |
| 53 |
<div lang="ruby" class="CodeRay"> |
| 54 |
<div class="code"><pre>&</pre></div> |
| 55 |
</div> |
| 56 |
BLOCKCODE |
| 57 |
RedCloth.new('bc[ruby]. &').to_html
|
| 58 |
end |
| 59 |
|
| 60 |
def test_for_redcloth_escapes2 |
| 61 |
require 'coderay/for_redcloth' |
| 62 |
assert_equal "<p><span lang=\"c\" class=\"CodeRay\"><span style=\"color:#579\">#include</span> <span style=\"color:#B44;font-weight:bold\"><test.h></span></span></p>", |
| 63 |
RedCloth.new('@[c]#include <test.h>@').to_html
|
| 64 |
end |
| 65 |
|
| 66 |
# See http://jgarber.lighthouseapp.com/projects/13054/tickets/124-code-markup-does-not-allow-brackets. |
| 67 |
def test_for_redcloth_false_positive |
| 68 |
require 'coderay/for_redcloth' |
| 69 |
assert_warning 'CodeRay::Scanners could not load plugin :project; falling back to :text' do |
| 70 |
assert_equal '<p><code>[project]_dff.skjd</code></p>', |
| 71 |
RedCloth.new('@[project]_dff.skjd@').to_html
|
| 72 |
end |
| 73 |
# false positive, but expected behavior / known issue |
| 74 |
assert_equal "<p><span lang=\"ruby\" class=\"CodeRay\">_dff.skjd</span></p>", |
| 75 |
RedCloth.new('@[ruby]_dff.skjd@').to_html
|
| 76 |
assert_warning 'CodeRay::Scanners could not load plugin :project; falling back to :text' do |
| 77 |
assert_equal <<-BLOCKCODE.chomp, |
| 78 |
<pre><code>[project]_dff.skjd</code></pre> |
| 79 |
BLOCKCODE |
| 80 |
RedCloth.new('bc. [project]_dff.skjd').to_html
|
| 81 |
end |
| 82 |
end |
| 83 |
|
| 84 |
end if defined? RedCloth |