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