mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
Clean up Haml exception tests.
This commit is contained in:
parent
740d6afb8c
commit
70778c95eb
1 changed files with 31 additions and 19 deletions
|
@ -2,6 +2,30 @@
|
||||||
require File.dirname(__FILE__) + '/test_helper'
|
require File.dirname(__FILE__) + '/test_helper'
|
||||||
|
|
||||||
class EngineTest < Test::Unit::TestCase
|
class EngineTest < Test::Unit::TestCase
|
||||||
|
EXCEPTION_MAP = {
|
||||||
|
"!!!\n a" => "Illegal Nesting: Nesting within a header command is illegal.",
|
||||||
|
"a\n b" => "Illegal Nesting: Nesting within plain text is illegal.",
|
||||||
|
":a" => "Filters must have nested text.",
|
||||||
|
"/ a\n b" => "Illegal Nesting: Nesting within a tag that already has content is illegal.",
|
||||||
|
"% a" => 'Invalid tag: "% a"',
|
||||||
|
"%p a\n b" => "Illegal Nesting: Content can't be both given on the same line as %p and nested within it.",
|
||||||
|
"%p=" => "Tag has no content.",
|
||||||
|
"%p~" => "Tag has no content.",
|
||||||
|
"~" => "Tag has no content.",
|
||||||
|
"=" => "Tag has no content.",
|
||||||
|
"%p/\n a" => "Illegal Nesting: Nesting within an atomic tag is illegal.",
|
||||||
|
"%p\n\ta" => "Illegal Indentation: Only two space characters are allowed as tabulation.",
|
||||||
|
"%p\n a" => "Illegal Indentation: Only two space characters are allowed as tabulation.",
|
||||||
|
"%p\n a" => "Illegal Indentation: Indenting more than once per line is illegal.",
|
||||||
|
":a\n b" => '"a" filter is not defined!',
|
||||||
|
":a= b" => 'Invalid filter name ":a= b"',
|
||||||
|
"." => "Illegal element: classes and ids must have values.",
|
||||||
|
".#" => "Illegal element: classes and ids must have values.",
|
||||||
|
".{} a" => "Illegal element: classes and ids must have values.",
|
||||||
|
".= a" => "Illegal element: classes and ids must have values.",
|
||||||
|
"%p..a" => "Illegal element: classes and ids must have values.",
|
||||||
|
"%a/ b" => "Atomic tags can't have content.",
|
||||||
|
}
|
||||||
|
|
||||||
def render(text, options = {}, &block)
|
def render(text, options = {}, &block)
|
||||||
scope = options.delete(:scope) || Object.new
|
scope = options.delete(:scope) || Object.new
|
||||||
|
@ -301,34 +325,22 @@ class EngineTest < Test::Unit::TestCase
|
||||||
assert_equal(hash3, hash1)
|
assert_equal(hash3, hash1)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_syntax_errors
|
def test_exceptions
|
||||||
|
EXCEPTION_MAP.each do |key, value|
|
||||||
errs = [ "!!!\n a", "a\n b", "a\n:foo\nb", "/ a\n b",
|
|
||||||
"% a", "%p a\n b", "a\n%p=\nb", "%p=\n a",
|
|
||||||
"a\n%p~\nb", "a\n~\nb", "a\n~\n b", "%p~\n b", "%p/\n a",
|
|
||||||
"%p\n \t%a b", "%a\n b\nc", "%a\n b\nc",
|
|
||||||
":notafilter\n This isn't\n a filter!",
|
|
||||||
":invalidfilter= foo\n This isn't a valid filter!",
|
|
||||||
".{} a", "\#{} a", ".= 'foo'", "%a/ b", "%p..class", "%p..#.", "=" ]
|
|
||||||
|
|
||||||
errs.each do |err|
|
|
||||||
begin
|
begin
|
||||||
render(err)
|
render(key)
|
||||||
rescue Exception => e
|
rescue Haml::Error => err
|
||||||
assert(e.is_a?(Haml::Error), "#{err.dump} doesn't produce Haml::SyntaxError")
|
assert_equal(value, err.message)
|
||||||
else
|
else
|
||||||
assert(false, "#{err.dump} doesn't produce an exception")
|
assert(false, "Haml::Error not raised for\n#{key}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_syntax_error
|
def test_exception_line
|
||||||
render("a\nb\n!!!\n c\nd")
|
render("a\nb\n!!!\n c\nd")
|
||||||
rescue Haml::SyntaxError => e
|
rescue Haml::SyntaxError => e
|
||||||
assert_equal(e.message, "Illegal Nesting: Nesting within a header command is illegal.")
|
|
||||||
assert_equal("(haml):4", e.backtrace[0])
|
assert_equal("(haml):4", e.backtrace[0])
|
||||||
rescue Exception => e
|
|
||||||
assert(false, '"a\nb\n!!!\n c\nd" doesn\'t produce a Haml::SyntaxError')
|
|
||||||
else
|
else
|
||||||
assert(false, '"a\nb\n!!!\n c\nd" doesn\'t produce an exception')
|
assert(false, '"a\nb\n!!!\n c\nd" doesn\'t produce an exception')
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue