Avoid duplicated assert_render naming

This commit is contained in:
Takashi Kokubun 2015-11-21 17:30:40 +09:00
parent 1ec855e108
commit bb469026b2
4 changed files with 74 additions and 74 deletions

View File

@ -127,9 +127,9 @@ class EngineTest < Haml::TestCase
end
def test_flexible_tabulation
assert_render("%p\n foo\n%q\n bar\n %a\n baz")
assert_render("%p\n\tfoo\n%q\n\tbar\n\t%a\n\t\tbaz")
assert_render("%p\n :plain\n \t \t bar\n baz")
assert_haml_ugly("%p\n foo\n%q\n bar\n %a\n baz")
assert_haml_ugly("%p\n\tfoo\n%q\n\tbar\n\t%a\n\t\tbaz")
assert_haml_ugly("%p\n :plain\n \t \t bar\n baz")
end
def test_empty_render_should_remain_empty
@ -189,7 +189,7 @@ class EngineTest < Haml::TestCase
end
def test_dynamic_attributes_with_no_content
assert_render(<<HAML)
assert_haml_ugly(<<HAML)
%p
%a{:href => "http://" + "haml.info"}
HAML
@ -227,7 +227,7 @@ HAML
end
def test_one_liner_with_newline_shouldnt_be_one_line
assert_render('%p= "foo\nbar"')
assert_haml_ugly('%p= "foo\nbar"')
end
def test_multi_render; skip
@ -238,10 +238,10 @@ HAML
end
def test_interpolation
assert_render('%p Hello #{who}', locals: {who: 'World'}, escape_html: false)
assert_render("%p\n Hello \#{who}", locals: {who: 'World'}, escape_html: false)
assert_render('%p Hello #{who}', locals: {who: 'World'}, escape_html: true)
assert_render("%p\n Hello \#{who}", locals: {who: 'World'}, escape_html: true)
assert_haml_ugly('%p Hello #{who}', locals: {who: 'World'}, escape_html: false)
assert_haml_ugly("%p\n Hello \#{who}", locals: {who: 'World'}, escape_html: false)
assert_haml_ugly('%p Hello #{who}', locals: {who: 'World'}, escape_html: true)
assert_haml_ugly("%p\n Hello \#{who}", locals: {who: 'World'}, escape_html: true)
end
def test_interpolation_with_instance_var; skip # special interpolation
@ -288,8 +288,8 @@ HAML
end
def test_interpolation_at_the_beginning_of_a_line
assert_render('%p #{1 + 1}')
assert_render("%p\n \#{1 + 1}")
assert_haml_ugly('%p #{1 + 1}')
assert_haml_ugly("%p\n \#{1 + 1}")
end
def test_interpolation_with_instance_var_at_the_beginning_of_a_line; skip # special interpolation
@ -332,15 +332,15 @@ HAML
end
def test_attribute_hash_with_newlines
assert_render("%p{:a => 'b',\n :c => 'd'} foop")
assert_render("%p{:a => 'b',\n :c => 'd'}\n foop")
assert_render("%p{:a => 'b',\n :c => 'd'}/")
assert_render("%p{:a => 'b',\n :c => 'd',\n :e => 'f'}")
assert_haml_ugly("%p{:a => 'b',\n :c => 'd'} foop")
assert_haml_ugly("%p{:a => 'b',\n :c => 'd'}\n foop")
assert_haml_ugly("%p{:a => 'b',\n :c => 'd'}/")
assert_haml_ugly("%p{:a => 'b',\n :c => 'd',\n :e => 'f'}")
end
def test_attr_hashes_not_modified
hash = {:color => 'red'}
assert_render(<<HAML, :locals => {:hash => hash})
assert_haml_ugly(<<HAML, :locals => {:hash => hash})
<div color='red'></div>
<div class='special' color='red'></div>
<div color='red'></div>
@ -481,7 +481,7 @@ HAML
# Regression tests
def test_indentation_after_dynamic_attr_hash; skip # dynamic indentation
assert_render(<<HAML)
assert_haml_ugly(<<HAML)
%html
%body
%img{:src => 'te'+'st'}
@ -502,7 +502,7 @@ HAML
end
def test_whitespace_nuke_with_tags_and_else
assert_render(<<HAML)
assert_haml_ugly(<<HAML)
%a
%b<
- if false
@ -511,7 +511,7 @@ HAML
foo
HAML
assert_render(<<HAML)
assert_haml_ugly(<<HAML)
%a
%b
- if false
@ -534,7 +534,7 @@ HAML
end
def test_both_case_indentation_work_with_deeply_nested_code
assert_render(<<HAML)
assert_haml_ugly(<<HAML)
- case 'other'
- when 'test'
%h2
@ -543,7 +543,7 @@ HAML
%h2
other
HAML
assert_render(<<HAML)
assert_haml_ugly(<<HAML)
- case 'other'
- when 'test'
%h2
@ -679,7 +679,7 @@ HAML
end
def test_escape_attrs_false
assert_render(<<HAML, :escape_attrs => false)
assert_haml_ugly(<<HAML, :escape_attrs => false)
#foo{:class => '<?php echo "&quot;" ?>'}
bar
HAML
@ -937,7 +937,7 @@ HAML
# HTML escaping tests
def test_ampersand_equals_should_escape
assert_render("%p\n &= 'foo & bar'", :escape_html => false)
assert_haml_ugly("%p\n &= 'foo & bar'", :escape_html => false)
end
def test_ampersand_equals_inline_should_escape; skip # script bug
@ -949,7 +949,7 @@ HAML
end
def test_bang_equals_should_not_escape
assert_render("%p\n != 'foo & bar'", :escape_html => true)
assert_haml_ugly("%p\n != 'foo & bar'", :escape_html => true)
end
def test_bang_equals_inline_should_not_escape
@ -994,13 +994,13 @@ HAML
end
def test_escaped_string_double_equals
assert_render("%p\n &== \#{2+2}&\#{'<'}", :escape_html => true)
assert_render("%p\n &== \#{2+2}&\#{'<'}", :escape_html => false)
assert_haml_ugly("%p\n &== \#{2+2}&\#{'<'}", :escape_html => true)
assert_haml_ugly("%p\n &== \#{2+2}&\#{'<'}", :escape_html => false)
end
def test_unescaped_string_double_equals
assert_render("%p\n !== \#{2+2}&\#{'<'}", :escape_html => true)
assert_render("%p\n !== \#{2+2}&\#{'<'}", :escape_html => false)
assert_haml_ugly("%p\n !== \#{2+2}&\#{'<'}", :escape_html => true)
assert_haml_ugly("%p\n !== \#{2+2}&\#{'<'}", :escape_html => false)
end
def test_string_interpolation_should_be_esaped
@ -1019,8 +1019,8 @@ HAML
end
def test_escaped_string_interpolation
assert_render("%p\n & \#{2+2}&\#{'<'}", :escape_html => true)
assert_render("%p\n & \#{2+2}&\#{'<'}", :escape_html => false)
assert_haml_ugly("%p\n & \#{2+2}&\#{'<'}", :escape_html => true)
assert_haml_ugly("%p\n & \#{2+2}&\#{'<'}", :escape_html => false)
end
def test_escaped_string_interpolation_with_no_space
@ -1029,8 +1029,8 @@ HAML
end
def test_unescaped_string_interpolation
assert_render("%p\n ! \#{2+2}&\#{'<'}", :escape_html => true)
assert_render("%p\n ! \#{2+2}&\#{'<'}", :escape_html => false)
assert_haml_ugly("%p\n ! \#{2+2}&\#{'<'}", :escape_html => true)
assert_haml_ugly("%p\n ! \#{2+2}&\#{'<'}", :escape_html => false)
end
def test_unescaped_string_interpolation_with_no_space
@ -1039,8 +1039,8 @@ HAML
end
def test_scripts_should_respect_escape_html_option
assert_render("%p\n = 'foo & bar'", :escape_html => true)
assert_render("%p\n = 'foo & bar'", :escape_html => false)
assert_haml_ugly("%p\n = 'foo & bar'", :escape_html => true)
assert_haml_ugly("%p\n = 'foo & bar'", :escape_html => false)
end
def test_inline_scripts_should_respect_escape_html_option; skip # escape html
@ -1166,8 +1166,8 @@ HAML
end
def test_empty_attrs
assert_render("%p{ :attr => '' } empty")
assert_render("%p{ :attr => x } empty", :locals => {:x => ''})
assert_haml_ugly("%p{ :attr => '' } empty")
assert_haml_ugly("%p{ :attr => x } empty", :locals => {:x => ''})
end
def test_nil_attrs
@ -1190,7 +1190,7 @@ HAML
end
def test_locals
assert_render("%p= text", :locals => { :text => "Paragraph!" })
assert_haml_ugly("%p= text", :locals => { :text => "Paragraph!" })
end
def test_dynamic_attrs_shouldnt_register_as_literal_values
@ -1298,7 +1298,7 @@ HAML
end
def test_local_assigns_dont_modify_class
assert_render("= foo", :locals => {:foo => 'bar'})
assert_haml_ugly("= foo", :locals => {:foo => 'bar'})
assert_equal(nil, defined?(foo))
end
@ -1327,7 +1327,7 @@ HAML
end
def test_non_literal_attributes
assert_render("%p{a2, a1, :a3 => 'baz'}",
assert_haml_ugly("%p{a2, a1, :a3 => 'baz'}",
:locals => {:a1 => {:a1 => 'foo'}, :a2 => {:a2 => 'bar'}})
end
@ -1342,7 +1342,7 @@ HAML
binding
end
assert_render("%p= upcase\n%p= @var\n%p= var", :scope => b)
assert_haml_ugly("%p= upcase\n%p= @var\n%p= var", :scope => b)
end
def test_yield_should_work_with_binding; skip # options
@ -1447,8 +1447,8 @@ HAML
end
def test_xhtml_output_option
assert_render("%p\n %br", :format => :xhtml)
assert_render("%a/", :format => :xhtml)
assert_haml_ugly("%p\n %br", :format => :xhtml)
assert_haml_ugly("%a/", :format => :xhtml)
end
def test_arbitrary_output_option; skip # error
@ -1472,7 +1472,7 @@ HAML
def test_interpolates_instance_vars_in_attribute_values
scope = Object.new
scope.instance_variable_set :@foo, 'bar'
assert_render('%a{:b => "a #@foo b"}', :scope => scope)
assert_haml_ugly('%a{:b => "a #@foo b"}', :scope => scope)
end
def test_interpolates_global_vars_in_attribute_values
@ -1492,8 +1492,8 @@ HAML
# HTML 4.0
def test_html_has_no_self_closing_tags
assert_render("%p\n %br", :format => :html4)
assert_render("%br/", :format => :html4)
assert_haml_ugly("%p\n %br", :format => :html4)
assert_haml_ugly("%br/", :format => :html4)
end
def test_html_renders_empty_node_with_closing_tag
@ -1682,14 +1682,14 @@ HAML
end
def test_dynamic_new_attributes
assert_render("%a(href=foo) bar", :locals => {:foo => 12})
assert_render("%a(b=b c='13' d=d) bar", :locals => {:b => 12, :d => 14})
assert_haml_ugly("%a(href=foo) bar", :locals => {:foo => 12})
assert_haml_ugly("%a(b=b c='13' d=d) bar", :locals => {:b => 12, :d => 14})
end
def test_new_attribute_interpolation
assert_render('%a(href="1#{1 + 1}") bar')
assert_render(%q{%a(href='2: #{1 + 1}, 3: #{foo}') bar}, :locals => {:foo => 3})
assert_render('%a(href="1\#{1 + 1}") bar')
assert_haml_ugly('%a(href="1#{1 + 1}") bar')
assert_haml_ugly(%q{%a(href='2: #{1 + 1}, 3: #{foo}') bar}, :locals => {:foo => 3})
assert_haml_ugly('%a(href="1\#{1 + 1}") bar')
end
def test_truthy_new_attributes; skip # xhtml
@ -1725,26 +1725,26 @@ HAML
end
def test_multiline_new_attribute
assert_render("%a(a='b'\n c='d') bar")
assert_render("%a(a='b' b='c'\n c='d' d=e\n e='f' f='j') bar", :locals => {:e => 'e'})
assert_haml_ugly("%a(a='b'\n c='d') bar")
assert_haml_ugly("%a(a='b' b='c'\n c='d' d=e\n e='f' f='j') bar", :locals => {:e => 'e'})
end
def test_new_and_old_attributes
assert_render("%a(a='b'){:c => 'd'} bar")
assert_render("%a{:c => 'd'}(a='b') bar")
assert_render("%a(c='d'){:a => 'b'} bar")
assert_render("%a{:a => 'b'}(c='d') bar")
assert_haml_ugly("%a(a='b'){:c => 'd'} bar")
assert_haml_ugly("%a{:c => 'd'}(a='b') bar")
assert_haml_ugly("%a(c='d'){:a => 'b'} bar")
assert_haml_ugly("%a{:a => 'b'}(c='d') bar")
# Old-style always takes precedence over new-style,
# because theoretically old-style could have arbitrary end-of-method-call syntax.
assert_render("%a{:a => 'b'}(a='d') bar")
assert_render("%a(a='d'){:a => 'b'} bar")
assert_haml_ugly("%a{:a => 'b'}(a='d') bar")
assert_haml_ugly("%a(a='d'){:a => 'b'} bar")
assert_render("%a{:a => 'b',\n:b => 'c'}(c='d'\nd='e') bar")
assert_haml_ugly("%a{:a => 'b',\n:b => 'c'}(c='d'\nd='e') bar")
locals = {:b => 'b', :d => 'd'}
assert_render("%p{:a => b}(c=d)", :locals => locals)
assert_render("%p(a=b){:c => d}", :locals => locals)
assert_haml_ugly("%p{:a => b}(c=d)", :locals => locals)
assert_haml_ugly("%p(a=b){:c => d}", :locals => locals)
end
# Ruby Multiline

View File

@ -67,7 +67,7 @@ class FiltersTest < Haml::TestCase
end
test "should respect escaped newlines and interpolation" do
assert_render(":plain\n \\n\#{""}")
assert_haml_ugly(":plain\n \\n\#{""}")
end
test "should process an filter with no content" do
@ -116,14 +116,14 @@ class FiltersTest < Haml::TestCase
end
test "interpolated code should be escaped if escape_html is set" do
assert_render(":plain\n \#{'<script>evil</script>'}")
assert_haml_ugly(":plain\n \#{'<script>evil</script>'}")
end
end
class ErbFilterTest < Haml::TestCase
test "multiline expressions should work" do; skip
assert_render(%Q{:erb\n <%= "foo" +\n "bar" +\n "baz" %>})
assert_haml_ugly(%Q{:erb\n <%= "foo" +\n "bar" +\n "baz" %>})
end
test "should evaluate in the same context as Haml" do; skip

View File

@ -148,7 +148,7 @@ class TemplateTest < Haml::TestCase
def test_simple_rendering_with_ugly
skip
assert_render("%p test\n= capture { 'foo' }")
assert_haml_ugly("%p test\n= capture { 'foo' }")
end
def test_templates_should_render_correctly_with_render_proc; skip
@ -168,22 +168,22 @@ class TemplateTest < Haml::TestCase
def test_instance_variables_should_work_inside_templates
@base.instance_variable_set(:@content_for_layout, 'something')
assert_render("%p= @content_for_layout")
assert_haml_ugly("%p= @content_for_layout")
@base.instance_eval("@author = 'Hampton Catlin'")
assert_render(".author= @author")
assert_haml_ugly(".author= @author")
@base.instance_eval("@author = 'Hampton'")
assert_render("= @author")
assert_haml_ugly("= @author")
@base.instance_eval("@author = 'Catlin'")
assert_render("= @author")
assert_haml_ugly("= @author")
end
def test_instance_variables_should_work_inside_attributes
skip
@base.instance_eval("@author = 'hcatlin'")
assert_render("%p{:class => @author} foo")
assert_haml_ugly("%p{:class => @author} foo")
end
def test_template_renders_should_eval
@ -277,7 +277,7 @@ HAML
end
def test_xss_protection_with_bang; skip
assert_render('!= "Foo & Bar"', :action_view)
assert_haml_ugly('!= "Foo & Bar"', :action_view)
end
def test_xss_protection_in_interpolation; skip
@ -293,7 +293,7 @@ HAML
end
def test_xss_protection_with_bang_in_interpolation; skip
assert_render('! Foo #{"&"} Bar', :action_view)
assert_haml_ugly('! Foo #{"&"} Bar', :action_view)
end
def test_xss_protection_with_safe_strings_in_interpolation; skip
@ -313,7 +313,7 @@ HAML
end
def test_xss_html_escaping_with_non_strings
assert_render("= html_escape(4)")
assert_haml_ugly("= html_escape(4)")
end
def test_xss_protection_with_concat; skip

View File

@ -52,7 +52,7 @@ class Haml::TestCase < BASE_TEST_CLASS
eval Hamlit::Engine.new(options).call(text)
end
def assert_render(text, options = {}, base = nil)
def assert_haml_ugly(text, options = {}, base = nil)
haml_base = { ugly: true, escape_html: true, escape_attrs: true }
hamlit_base = { escape_html: true }
scope = options.delete(:scope) || Object.new