Skip to content

Commit c999deb

Browse files
committed
fix tests
1 parent 351822b commit c999deb

File tree

4 files changed

+29
-12
lines changed

4 files changed

+29
-12
lines changed

test/functional/basic.rb

+7-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77

88
class BasicTest < Test::Unit::TestCase
99

10+
def normalize_html html
11+
html.gsub('&#39;', "'").gsub('&quot;', '"')
12+
end
13+
1014
def test_version
1115
assert_nothing_raised do
1216
assert_match(/\A\d\.\d\.\d?\z/, CodeRay::VERSION)
@@ -50,7 +54,7 @@ def test_simple_scan
5054
'<span class="content">Hello, World!</span><span class="delimiter">"</span></span>'
5155
def test_simple_highlight
5256
assert_nothing_raised do
53-
assert_equal RUBY_TEST_HTML, CodeRay.scan(RUBY_TEST_CODE, :ruby).html
57+
assert_equal RUBY_TEST_HTML, normalize_html(CodeRay.scan(RUBY_TEST_CODE, :ruby).html)
5458
end
5559
end
5660

@@ -75,7 +79,8 @@ def test_highlight
7579
end
7680

7781
def test_highlight_file
78-
assert_match "require <span class=\"string\"><span class=\"delimiter\">'</span><span class=\"content\">test/unit</span><span class=\"delimiter\">'</span></span>\n", CodeRay.highlight_file(__FILE__)
82+
assert_match "require <span class=\"string\"><span class=\"delimiter\">'</span><span class=\"content\">test/unit</span><span class=\"delimiter\">'</span></span>\n",
83+
normalize_html(CodeRay.highlight_file(__FILE__))
7984
end
8085

8186
def test_duo

test/functional/examples.rb

+9-5
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@
55

66
class ExamplesTest < Test::Unit::TestCase
77

8+
def normalize_html html
9+
html.gsub('&#39;', "'").gsub('&quot;', '"')
10+
end
11+
812
def test_examples
913
# output as HTML div (using inline CSS styles)
1014
div = CodeRay.scan('puts "Hello, world!"', :ruby).div
11-
assert_equal <<-DIV, div
15+
assert_equal <<-DIV, normalize_html(div)
1216
<div class="CodeRay">
1317
<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>
1418
</div>
@@ -20,7 +24,7 @@ def test_examples
2024
puts 'Hello, world!'
2125
end
2226
CODE
23-
assert_equal <<-DIV, div
27+
assert_equal <<-DIV, normalize_html(div)
2428
<table class="CodeRay"><tr>
2529
<td class="line-numbers"><pre><a href="#n1" name="n1">1</a>
2630
<a href="#n2" name="n2">2</a>
@@ -34,7 +38,7 @@ def test_examples
3438

3539
# output as standalone HTML page (using CSS classes)
3640
page = CodeRay.scan('puts "Hello, world!"', :ruby).page
37-
assert_match <<-PAGE, page
41+
assert_match <<-PAGE, normalize_html(page)
3842
<body>
3943
4044
<table class="CodeRay"><tr>
@@ -90,7 +94,7 @@ def test_examples
9094

9195
# produce a HTML div, but with CSS classes
9296
div = tokens.div(:css => :class)
93-
assert_equal <<-DIV, div
97+
assert_equal <<-DIV, normalize_html(div)
9498
<div class="CodeRay">
9599
<div class="code"><pre>{ <span class="key"><span class="delimiter">"</span><span class="content">just</span><span class="delimiter">"</span></span>: <span class="string"><span class="delimiter">"</span><span class="content">an</span><span class="delimiter">"</span></span>, <span class="key"><span class="delimiter">"</span><span class="content">example</span><span class="delimiter">"</span></span>: <span class="integer">42</span> }</pre></div>
96100
</div>
@@ -119,7 +123,7 @@ def test_examples
119123
# re-using scanner and encoder
120124
ruby_highlighter = CodeRay::Duo[:ruby, :div]
121125
div = ruby_highlighter.encode('puts "Hello, world!"')
122-
assert_equal <<-DIV, div
126+
assert_equal <<-DIV, normalize_html(div)
123127
<div class="CodeRay">
124128
<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>
125129
</div>

test/functional/for_redcloth.rb

+6-2
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,20 @@
1414

1515
class BasicTest < Test::Unit::TestCase
1616

17+
def normalize_html html
18+
html.gsub('&#39;', "'").gsub('&quot;', '"')
19+
end
20+
1721
def test_for_redcloth
1822
require 'coderay/for_redcloth'
1923
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>",
20-
RedCloth.new('@[ruby]puts "Hello, World!"@').to_html
24+
normalize_html(RedCloth.new('@[ruby]puts "Hello, World!"@').to_html)
2125
assert_equal <<-BLOCKCODE.chomp,
2226
<div lang="ruby" class="CodeRay">
2327
<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>
2428
</div>
2529
BLOCKCODE
26-
RedCloth.new('bc[ruby]. puts "Hello, World!"').to_html
30+
normalize_html(RedCloth.new('bc[ruby]. puts "Hello, World!"').to_html)
2731
end
2832

2933
def test_for_redcloth_no_lang

test/unit/html.rb

+7-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33

44
class HtmlTest < Test::Unit::TestCase
55

6+
def normalize_html html
7+
html.gsub('&#39;', "'").gsub('&quot;', '"')
8+
end
9+
610
def test_break_lines_option
711
snippets = {}
812

@@ -95,9 +99,9 @@ def test_break_lines_option
9599
for lang, code in snippets
96100
tokens = CodeRay.scan code[:in], lang
97101

98-
assert_equal code[:expected_with_option_off], tokens.html
99-
assert_equal code[:expected_with_option_off], tokens.html(:break_lines => false)
100-
assert_equal code[:expected_with_option_on], tokens.html(:break_lines => true)
102+
assert_equal code[:expected_with_option_off], normalize_html(tokens.html)
103+
assert_equal code[:expected_with_option_off], normalize_html(tokens.html(:break_lines => false))
104+
assert_equal code[:expected_with_option_on], normalize_html(tokens.html(:break_lines => true))
101105
end
102106
end
103107
end

0 commit comments

Comments
 (0)