0
@@ -12,7 +12,9 @@ require 'haml/engine'
0
class EngineTest < Test::Unit::TestCase
0
def render(text, options = {}, &block)
0
- Haml::Engine.new(text, options).to_html(options.delete(:scope) || Object.new, &block)
0
+ scope = options.delete(:scope) || Object.new
0
+ locals = options.delete(:locals) || {}
0
+ Haml::Engine.new(text, options).to_html(scope, locals, &block)
0
def test_empty_render_should_remain_empty
0
@@ -137,12 +139,16 @@ class EngineTest < Test::Unit::TestCase
0
assert_equal("<p>Paragraph!</p>\n", render("%p= text", :locals => { :text => "Paragraph!" }))
0
- def test_same_templates_with_different_options_should_cache_separately
0
- assert_equal("foobar\n", render("- puts 'foobar'"))
0
- assert_equal("", render("- puts 'foobar'", :suppress_eval => true))
0
+ def test_deprecated_locals_option
0
+ def warn_with_stub(msg); end
0
+ alias_method :warn_without_stub, :warn
0
+ alias_method :warn, :warn_with_stub
0
+ assert_equal("<p>Paragraph!</p>\n", Haml::Engine.new("%p= text", :locals => { :text => "Paragraph!" }).render)
0
- assert_equal("<a href='boo'>Boo!</a>\n", render("%a{:href => 'boo'} Boo!"))
0
- assert_equal("<a href=\"boo\">Boo!</a>\n", render("%a{:href => 'boo'} Boo!", :attr_wrapper => '"'))
0
+ Kernel.module_eval { alias_method :warn, :warn_without_stub }
0
def test_dynamic_attrs_shouldnt_register_as_literal_values
0
@@ -159,49 +165,6 @@ class EngineTest < Test::Unit::TestCase
0
assert_equal(hash3, hash1)
0
- def test_exception_type
0
- render("%p hi\n= undefined\n= 12")
0
- assert(e.is_a?(Haml::Error))
0
- assert_equal(2, e.haml_line)
0
- assert_equal(nil, e.haml_filename)
0
- assert_equal('(haml):2', e.backtrace[0])
0
- # Test failed... should have raised an exception
0
- def test_def_method_exception_type
0
- Haml::Engine.new("%p hi\n= undefined\n= 12").def_method(o, :render)
0
- assert(e.is_a?(Haml::Error))
0
- assert_equal(2, e.haml_line)
0
- assert_equal(nil, e.haml_filename)
0
- assert_equal('(haml):2', e.backtrace[0])
0
- # Test failed... should have raised an exception
0
- def test_render_proc_exception_type
0
- Haml::Engine.new("%p hi\n= undefined\n= 12").render_proc.call
0
- assert(e.is_a?(Haml::Error))
0
- assert_equal(2, e.haml_line)
0
- assert_equal(nil, e.haml_filename)
0
- assert_equal('(haml):2', e.backtrace[0])
0
- # Test failed... should have raised an exception
0
errs = [ "!!!\n a", "a\n b", "a\n:foo\nb", "/ a\n b",
0
"% a", "%p a\n b", "a\n%p=\nb", "%p=\n a",
0
@@ -221,30 +184,85 @@ class EngineTest < Test::Unit::TestCase
0
- render("a\nb\n!!!\n c\nd")
0
- rescue Haml::SyntaxError => e
0
- assert_equal(e.message, "Illegal Nesting: Nesting within a header command is illegal.")
0
- assert_equal(3, e.haml_line)
0
- assert_equal(nil, e.haml_filename)
0
- assert_equal('(haml):3', e.backtrace[0])
0
- assert(false, '"a\nb\n!!!\n c\nd" doesn\'t produce a Haml::SyntaxError')
0
- assert(false, '"a\nb\n!!!\n c\nd" doesn\'t produce an exception')
0
+ render("a\nb\n!!!\n c\nd")
0
+ rescue Haml::SyntaxError => e
0
+ assert_equal(e.message, "Illegal Nesting: Nesting within a header command is illegal.")
0
+ assert_equal(3, e.haml_line)
0
+ assert_equal(nil, e.haml_filename)
0
+ assert_equal('(haml):3', e.backtrace[0])
0
+ assert(false, '"a\nb\n!!!\n c\nd" doesn\'t produce a Haml::SyntaxError')
0
+ assert(false, '"a\nb\n!!!\n c\nd" doesn\'t produce an exception')
0
+ def test_exception_type
0
+ render("%p hi\n= undefined\n= 12")
0
+ assert(e.is_a?(Haml::Error))
0
+ assert_equal(2, e.haml_line)
0
+ assert_equal(nil, e.haml_filename)
0
+ assert_equal('(haml):2', e.backtrace[0])
0
+ # Test failed... should have raised an exception
0
+ def test_def_method_exception_type
0
+ Haml::Engine.new("%p hi\n= undefined\n= 12").def_method(o, :render)
0
+ assert(e.is_a?(Haml::Error))
0
+ assert_equal(2, e.haml_line)
0
+ assert_equal(nil, e.haml_filename)
0
+ assert_equal('(haml):2', e.backtrace[0])
0
+ # Test failed... should have raised an exception
0
+ def test_render_proc_exception_type
0
+ Haml::Engine.new("%p hi\n= undefined\n= 12").render_proc.call
0
+ assert(e.is_a?(Haml::Error))
0
+ assert_equal(2, e.haml_line)
0
+ assert_equal(nil, e.haml_filename)
0
+ assert_equal('(haml):2', e.backtrace[0])
0
+ # Test failed... should have raised an exception
0
- render("a\nb\n- fee do\nc")
0
- assert_equal("compile error: syntax error, unexpected $end, expecting kEND", e.message)
0
- assert_equal(3, e.haml_line)
0
- '"a\nb\n- fee do\nc" doesn\'t produce an exception!')
0
+ render("a\nb\n- fee do\nc")
0
+ assert_match(/^compile error: syntax error/, e.message)
0
+ assert_equal(3, e.haml_line)
0
+ '"a\nb\n- fee do\nc" doesn\'t produce an exception!')
0
+ def test_def_method_compile_error
0
+ Haml::Engine.new("a\nb\n- fee do\nc").def_method(o, :render)
0
+ assert_match(/^compile error: syntax error/, e.message)
0
+ assert_equal(3, e.haml_line)
0
+ '"a\nb\n- fee do\nc" doesn\'t produce an exception!')
0
+ def test_render_proc_compile_error
0
+ Haml::Engine.new("a\nb\n- fee do\nc").render_proc
0
+ assert_match(/^compile error: syntax error/, e.message)
0
+ assert_equal(3, e.haml_line)
0
+ '"a\nb\n- fee do\nc" doesn\'t produce an exception!')
0
@@ -354,4 +372,19 @@ class EngineTest < Test::Unit::TestCase
0
Haml::Engine.new("= yield\n= upcase").def_method(String, :render_haml)
0
assert_equal("12\nFOO\n", "foo".render_haml { 12 })
0
+ def test_def_method_locals
0
+ Haml::Engine.new("%p= foo\n.bar{:baz => baz}= boom").def_method(obj, :render, :foo, :baz, :boom)
0
+ assert_equal("<p>1</p>\n<div baz='2' class='bar'>3</div>\n", obj.render(:foo => 1, :baz => 2, :boom => 3))
0
+ def test_render_proc_locals
0
+ proc = Haml::Engine.new("%p= foo\n.bar{:baz => baz}= boom").render_proc(Object.new, :foo, :baz, :boom)
0
+ assert_equal("<p>1</p>\n<div baz='2' class='bar'>3</div>\n", proc[:foo => 1, :baz => 2, :boom => 3])
0
+ def test_render_proc_with_binding
0
+ assert_equal("FOO\n", Haml::Engine.new("= upcase").render_proc("foo".instance_eval{binding}).call)
Comments
No one has commented yet.