1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
require "test/unit"
require "coderay"
class BasicTest < Test::Unit::TestCase
def test_version
assert_nothing_raised do
CodeRay::VERSION
end
end
RUBY_TEST_CODE = 'puts "Hello, World!"'
def test_simple_scan
assert_nothing_raised do
CodeRay.scan(RUBY_TEST_CODE, :ruby)
end
end
def test_simple_highlight
assert_nothing_raised do
CodeRay.scan(RUBY_TEST_CODE, :ruby).html
end
end
def test_duo
assert_equal(RUBY_TEST_CODE,
CodeRay::Duo[:plain, :plain].highlight(RUBY_TEST_CODE))
assert_equal(RUBY_TEST_CODE,
CodeRay::Duo[:plain => :plain].highlight(RUBY_TEST_CODE))
end
def test_duo_stream
assert_equal(RUBY_TEST_CODE,
CodeRay::Duo[:plain, :plain].highlight(RUBY_TEST_CODE, :stream => true))
end
begin
require 'rubygems'
gem 'RedCloth', '>= 4.0.3' rescue nil
require 'redcloth'
def test_for_redcloth
require 'rubygems'
require 'coderay/for_redcloth'
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>",
RedCloth.new('@[ruby]puts "Hello, World!"@').to_html
assert_equal <<-BLOCKCODE.chomp,
<div lang="ruby" class="CodeRay">
<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>
</div>
</pre>
BLOCKCODE
RedCloth.new('bc[ruby]. puts "Hello, World!"').to_html
end
def test_for_redcloth_escapes
require 'rubygems'
require 'coderay/for_redcloth'
assert_equal '<p><span lang="ruby" class="CodeRay">></span></p>',
RedCloth.new('@[ruby]>@').to_html
assert_equal <<-BLOCKCODE.chomp,
<div lang="ruby" class="CodeRay">
<div class="code"><pre>&</pre></div>
</div>
</pre>
BLOCKCODE
RedCloth.new('bc[ruby]. &').to_html
end
rescue LoadError
$stderr.puts 'RedCloth not found.'
end
ENCODERS_LIST = %w(
count debug div html null page span statistic text tokens xml yaml
)
def _test_list_of_encoders
assert_equal(ENCODERS_LIST, CodeRay::Encoders.list.sort)
end
SCANNERS_LIST = %w(
c debug delphi html nitro_xhtml plaintext rhtml ruby xml
)
def _test_list_of_scanners
assert_equal(SCANNERS_LIST, CodeRay::Scanners.list.sort)
end
end
|