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