1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00

Add tests for html_escape and escape_once

This commit is contained in:
Matt Wildig 2013-01-15 22:24:39 +00:00 committed by Norman Clarke
parent 47c7dbfd37
commit ffd54f64b5

View file

@ -458,5 +458,41 @@ HAML
%div> hi there!
HAML
end
def test_html_escape
assert_equal "&quot;&gt;&lt;&amp;", Haml::Helpers.html_escape('"><&')
end
def test_html_escape_encoding
old_stderr, $stderr = $stderr, StringIO.new
string = "\"><&\u00e9" # if you're curious, u00e9 is "LATIN SMALL LETTER E WITH ACUTE"
assert_equal "&quot;&gt;&lt;&amp;\u00e9", Haml::Helpers.html_escape(string)
assert $stderr.string == "", "html_escape shouldn't generate warnings with UTF-8 strings: #{$stderr.string}"
ensure
$stderr = old_stderr
end
def test_escape_once
assert_equal "&quot;&gt;&lt;&amp;", Haml::Helpers.escape_once('"><&')
end
def test_escape_once_leaves_entity_references
assert_equal "&quot;&gt;&lt;&amp; &nbsp;", Haml::Helpers.escape_once('"><& &nbsp;')
end
def test_escape_once_leaves_numeric_references
assert_equal "&quot;&gt;&lt;&amp; &#160;", Haml::Helpers.escape_once('"><& &#160;') #decimal
#assert_equal "&quot;&gt;&lt;&amp; &#x00a0;", Haml::Helpers.escape_once('"><& &#x00a0;') #hexadecimal
end
def test_escape_once_encoding
old_stderr, $stderr = $stderr, StringIO.new
string = "\"><&\u00e9 &nbsp;"
assert_equal "&quot;&gt;&lt;&amp;\u00e9 &nbsp;", Haml::Helpers.escape_once(string)
assert $stderr.string == "", "html_escape shouldn't generate warnings with UTF-8 strings: #{$stderr.string}"
ensure
$stderr = old_stderr
end
end