summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/functional/basic.rb13
-rw-r--r--test/functional/examples.rb22
-rw-r--r--test/functional/for_redcloth.rb12
-rw-r--r--test/unit/html.rb14
4 files changed, 39 insertions, 22 deletions
diff --git a/test/functional/basic.rb b/test/functional/basic.rb
index 752d4ba..8554a78 100644
--- a/test/functional/basic.rb
+++ b/test/functional/basic.rb
@@ -7,6 +7,10 @@ require 'coderay'
class BasicTest < Test::Unit::TestCase
+ def normalize_html html
+ html.gsub('&#39;', "'").gsub('&quot;', '"')
+ end
+
def test_version
assert_nothing_raised do
assert_match(/\A\d\.\d\.\d?\z/, CodeRay::VERSION)
@@ -46,11 +50,11 @@ class BasicTest < Test::Unit::TestCase
end
end
- RUBY_TEST_HTML = 'puts <span class="string"><span class="delimiter">&quot;</span>' +
- '<span class="content">Hello, World!</span><span class="delimiter">&quot;</span></span>'
+ RUBY_TEST_HTML = 'puts <span class="string"><span class="delimiter">"</span>' +
+ '<span class="content">Hello, World!</span><span class="delimiter">"</span></span>'
def test_simple_highlight
assert_nothing_raised do
- assert_equal RUBY_TEST_HTML, CodeRay.scan(RUBY_TEST_CODE, :ruby).html
+ assert_equal RUBY_TEST_HTML, normalize_html(CodeRay.scan(RUBY_TEST_CODE, :ruby).html)
end
end
@@ -75,7 +79,8 @@ class BasicTest < Test::Unit::TestCase
end
def test_highlight_file
- 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__)
+ assert_match "require <span class=\"string\"><span class=\"delimiter\">'</span><span class=\"content\">test/unit</span><span class=\"delimiter\">'</span></span>\n",
+ normalize_html(CodeRay.highlight_file(__FILE__))
end
def test_duo
diff --git a/test/functional/examples.rb b/test/functional/examples.rb
index 985ef87..49337cb 100644
--- a/test/functional/examples.rb
+++ b/test/functional/examples.rb
@@ -5,12 +5,16 @@ require 'coderay'
class ExamplesTest < Test::Unit::TestCase
+ def normalize_html html
+ html.gsub('&#39;', "'").gsub('&quot;', '"')
+ end
+
def test_examples
# output as HTML div (using inline CSS styles)
div = CodeRay.scan('puts "Hello, world!"', :ruby).div
- assert_equal <<-DIV, div
+ assert_equal <<-DIV, normalize_html(div)
<div class="CodeRay">
- <div class="code"><pre>puts <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">&quot;</span><span style="color:#D20">Hello, world!</span><span style="color:#710">&quot;</span></span></pre></div>
+ <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>
</div>
DIV
@@ -20,7 +24,7 @@ class ExamplesTest < Test::Unit::TestCase
puts 'Hello, world!'
end
CODE
- assert_equal <<-DIV, div
+ assert_equal <<-DIV, normalize_html(div)
<table class="CodeRay"><tr>
<td class="line-numbers"><pre><a href="#n1" name="n1">1</a>
<a href="#n2" name="n2">2</a>
@@ -34,13 +38,13 @@ end
# output as standalone HTML page (using CSS classes)
page = CodeRay.scan('puts "Hello, world!"', :ruby).page
- assert_match <<-PAGE, page
+ assert_match <<-PAGE, normalize_html(page)
<body>
<table class="CodeRay"><tr>
<td class="line-numbers"><pre><a href="#n1" name="n1">1</a>
</pre></td>
- <td class="code"><pre>puts <span class="string"><span class="delimiter">&quot;</span><span class="content">Hello, world!</span><span class="delimiter">&quot;</span></span></pre></td>
+ <td class="code"><pre>puts <span class="string"><span class="delimiter">"</span><span class="content">Hello, world!</span><span class="delimiter">"</span></span></pre></td>
</tr></table>
</body>
@@ -90,9 +94,9 @@ Token Types (7):
# produce a HTML div, but with CSS classes
div = tokens.div(:css => :class)
- assert_equal <<-DIV, div
+ assert_equal <<-DIV, normalize_html(div)
<div class="CodeRay">
- <div class="code"><pre>{ <span class="key"><span class="delimiter">&quot;</span><span class="content">just</span><span class="delimiter">&quot;</span></span>: <span class="string"><span class="delimiter">&quot;</span><span class="content">an</span><span class="delimiter">&quot;</span></span>, <span class="key"><span class="delimiter">&quot;</span><span class="content">example</span><span class="delimiter">&quot;</span></span>: <span class="integer">42</span> }</pre></div>
+ <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>
</div>
DIV
@@ -119,9 +123,9 @@ Token Types (7):
# re-using scanner and encoder
ruby_highlighter = CodeRay::Duo[:ruby, :div]
div = ruby_highlighter.encode('puts "Hello, world!"')
- assert_equal <<-DIV, div
+ assert_equal <<-DIV, normalize_html(div)
<div class="CodeRay">
- <div class="code"><pre>puts <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">&quot;</span><span style="color:#D20">Hello, world!</span><span style="color:#710">&quot;</span></span></pre></div>
+ <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>
</div>
DIV
end
diff --git a/test/functional/for_redcloth.rb b/test/functional/for_redcloth.rb
index 9fd244e..50fc50c 100644
--- a/test/functional/for_redcloth.rb
+++ b/test/functional/for_redcloth.rb
@@ -14,16 +14,20 @@ end
class BasicTest < Test::Unit::TestCase
+ def normalize_html html
+ html.gsub('&#39;', "'").gsub('&quot;', '"')
+ end
+
def test_for_redcloth
require 'coderay/for_redcloth'
- assert_equal "<p><span lang=\"ruby\" class=\"CodeRay\">puts <span style=\"background-color:hsla(0,100%,50%,0.05)\"><span style=\"color:#710\">&quot;</span><span style=\"color:#D20\">Hello, World!</span><span style=\"color:#710\">&quot;</span></span></span></p>",
- RedCloth.new('@[ruby]puts "Hello, World!"@').to_html
+ 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>",
+ normalize_html(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:hsla(0,100%,50%,0.05)"><span style="color:#710">&quot;</span><span style="color:#D20">Hello, World!</span><span style="color:#710">&quot;</span></span></pre></div>
+ <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>
</div>
BLOCKCODE
- RedCloth.new('bc[ruby]. puts "Hello, World!"').to_html
+ normalize_html(RedCloth.new('bc[ruby]. puts "Hello, World!"').to_html)
end
def test_for_redcloth_no_lang
diff --git a/test/unit/html.rb b/test/unit/html.rb
index 0072635..9175a4f 100644
--- a/test/unit/html.rb
+++ b/test/unit/html.rb
@@ -3,6 +3,10 @@ require 'coderay'
class HtmlTest < Test::Unit::TestCase
+ def normalize_html html
+ html.gsub('&#39;', "'").gsub('&quot;', '"')
+ end
+
def test_break_lines_option
snippets = {}
@@ -60,7 +64,7 @@ public class Test {
* used to test the
*/</span>
<span class=\"directive\">public</span> <span class=\"type\">class</span> <span class=\"class\">Test</span> {
- <span class=\"directive\">public</span> <span class=\"directive\">static</span> <span class=\"directive\">final</span> <span class=\"predefined-type\">String</span> MESSAGE = <span class=\"string\"><span class=\"delimiter\">&quot;</span><span class=\"content\">My message To the world</span><span class=\"delimiter\">&quot;</span></span>;
+ <span class=\"directive\">public</span> <span class=\"directive\">static</span> <span class=\"directive\">final</span> <span class=\"predefined-type\">String</span> MESSAGE = <span class=\"string\"><span class=\"delimiter\">\"</span><span class=\"content\">My message To the world</span><span class=\"delimiter\">\"</span></span>;
<span class=\"directive\">static</span> <span class=\"type\">void</span> main() {
<span class=\"comment\">/*
@@ -80,7 +84,7 @@ public class Test {
<span class=\"comment\"> * used to test the</span>
<span class=\"comment\"> */</span>
<span class=\"directive\">public</span> <span class=\"type\">class</span> <span class=\"class\">Test</span> {
- <span class=\"directive\">public</span> <span class=\"directive\">static</span> <span class=\"directive\">final</span> <span class=\"predefined-type\">String</span> MESSAGE = <span class=\"string\"><span class=\"delimiter\">&quot;</span><span class=\"content\">My message To the world</span><span class=\"delimiter\">&quot;</span></span>;
+ <span class=\"directive\">public</span> <span class=\"directive\">static</span> <span class=\"directive\">final</span> <span class=\"predefined-type\">String</span> MESSAGE = <span class=\"string\"><span class=\"delimiter\">\"</span><span class=\"content\">My message To the world</span><span class=\"delimiter\">\"</span></span>;
<span class=\"directive\">static</span> <span class=\"type\">void</span> main() {
<span class=\"comment\">/*</span>
@@ -95,9 +99,9 @@ public class Test {
for lang, code in snippets
tokens = CodeRay.scan code[:in], lang
- assert_equal code[:expected_with_option_off], tokens.html
- assert_equal code[:expected_with_option_off], tokens.html(:break_lines => false)
- assert_equal code[:expected_with_option_on], tokens.html(:break_lines => true)
+ assert_equal code[:expected_with_option_off], normalize_html(tokens.html)
+ assert_equal code[:expected_with_option_off], normalize_html(tokens.html(:break_lines => false))
+ assert_equal code[:expected_with_option_on], normalize_html(tokens.html(:break_lines => true))
end
end
end