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

Apparently assert_raise doesn't validate the message name.

Add a version that does, and fix the numerous test errors and bugs
that this exposes.
This commit is contained in:
Nathan Weizenbaum 2010-08-08 16:05:01 -07:00
parent e7b6764093
commit 1631533a2e
10 changed files with 41 additions and 30 deletions

View file

@ -99,7 +99,7 @@ module Haml
@index = 0
unless [:xhtml, :html4, :html5].include?(@options[:format])
raise Haml::Error, "Invalid format #{@options[:format].inspect}"
raise Haml::Error, "Invalid output format #{@options[:format].inspect}"
end
if @options[:encoding] && @options[:encoding].is_a?(Encoding)

View file

@ -114,7 +114,7 @@ module Sass::Script
end
unless (0..1).include?(@attrs[:alpha])
raise Sass::SyntaxError.new("Alpha channel must between 0 and 1")
raise Sass::SyntaxError.new("Alpha channel must be between 0 and 1")
end
end

View file

@ -278,7 +278,7 @@ module Sass
def color
return unless s = scan(REGULAR_EXPRESSIONS[:color])
raise Sass::SyntaxError.new(<<MESSAGE) unless s.size == 4 || s.size == 7
raise Sass::SyntaxError.new(<<MESSAGE.rstrip) unless s.size == 4 || s.size == 7
Colors must have either three or six digits: '#{s}'
MESSAGE
value = s.scan(/^#(..?)(..?)(..?)$/).first.

View file

@ -167,7 +167,7 @@ module Sass::Tree
def declaration(tabs = 0, opts = {:old => @prop_syntax == :old}, fmt = :sass)
name = self.name.map {|n| n.is_a?(String) ? n : "\#{#{n.to_sass(opts)}}"}.join
if name[0] == ?:
raise Sass::SyntaxError.new("The \":#{name}: #{self.class.val_to_sass(value, opts)}\" hack is not allowed in the Sass indented syntax")
raise Sass::SyntaxError.new("The \"#{name}: #{self.class.val_to_sass(value, opts)}\" hack is not allowed in the Sass indented syntax")
end
old = opts[:old] && fmt == :sass

View file

@ -1236,7 +1236,9 @@ SASS
end
def test_arbitrary_output_option
assert_raise(Haml::Error, "Invalid output format :html1") { engine("%br", :format => :html1) }
assert_raise_message(Haml::Error, "Invalid output format :html1") do
engine("%br", :format => :html1)
end
end
def test_static_hashes

View file

@ -1031,7 +1031,7 @@ SCSS
end
def test_disallowed_colon_hack
assert_raise(Sass::SyntaxError, '":foo: bar" is not allowed in the Sass syntax') do
assert_raise_message(Sass::SyntaxError, 'The ":name: val" hack is not allowed in the Sass indented syntax') do
to_sass("foo {:name: val;}", :syntax => :scss)
end
end

View file

@ -2057,7 +2057,7 @@ SASS
end
def test_mixin_no_arg_error
assert_raise(Sass::SyntaxError, 'Invalid CSS after "($bar,": expected variable name, was ")"') do
assert_raise_message(Sass::SyntaxError, 'Invalid CSS after "($bar,": expected variable (e.g. $foo), was ")"') do
render(<<SASS)
=foo($bar,)
bip: bap

View file

@ -13,13 +13,13 @@ class SassScriptTest < Test::Unit::TestCase
include Sass::Script
def test_color_checks_input
assert_raise(Sass::SyntaxError, "Color values must be between 0 and 255") {Color.new([1, 2, -1])}
assert_raise(Sass::SyntaxError, "Color values must be between 0 and 255") {Color.new([256, 2, 3])}
assert_raise_message(Sass::SyntaxError, "Blue value must be between 0 and 255") {Color.new([1, 2, -1])}
assert_raise_message(Sass::SyntaxError, "Red value must be between 0 and 255") {Color.new([256, 2, 3])}
end
def test_color_checks_rgba_input
assert_raise(Sass::SyntaxError, "Alpha channel must be between 0 and 1") {Color.new([1, 2, 3, 1.1])}
assert_raise(Sass::SyntaxError, "Alpha channel must be between 0 and 1") {Color.new([1, 2, 3, -0.1])}
assert_raise_message(Sass::SyntaxError, "Alpha channel must be between 0 and 1") {Color.new([1, 2, 3, 1.1])}
assert_raise_message(Sass::SyntaxError, "Alpha channel must be between 0 and 1") {Color.new([1, 2, 3, -0.1])}
end
def test_string_escapes
@ -63,13 +63,13 @@ class SassScriptTest < Test::Unit::TestCase
assert_equal "rgba(50, 50, 100, 0.35)", resolve("rgba(1, 1, 2, 0.35) * rgba(50, 50, 50, 0.35)")
assert_equal "rgba(52, 52, 52, 0.25)", resolve("rgba(2, 2, 2, 0.25) + rgba(50, 50, 50, 0.25)")
assert_raise(Sass::SyntaxError, "Alpha channels must be equal: rgba(1, 2, 3, 0.15) + rgba(50, 50, 50, 0.75)") do
assert_raise_message(Sass::SyntaxError, "Alpha channels must be equal: rgba(1, 2, 3, 0.15) + rgba(50, 50, 50, 0.75)") do
resolve("rgba(1, 2, 3, 0.15) + rgba(50, 50, 50, 0.75)")
end
assert_raise(Sass::SyntaxError, "Alpha channels must be equal: #123456 * rgba(50, 50, 50, 0.75)") do
assert_raise_message(Sass::SyntaxError, "Alpha channels must be equal: #123456 * rgba(50, 50, 50, 0.75)") do
resolve("#123456 * rgba(50, 50, 50, 0.75)")
end
assert_raise(Sass::SyntaxError, "Alpha channels must be equal: #123456 / #123456") do
assert_raise_message(Sass::SyntaxError, "Alpha channels must be equal: rgba(50, 50, 50, 0.75) / #123456") do
resolve("rgba(50, 50, 50, 0.75) / #123456")
end
end
@ -360,15 +360,15 @@ SASS
end
def test_colors_with_wrong_number_of_digits
assert_raise(Sass::SyntaxError,
assert_raise_message(Sass::SyntaxError,
"Colors must have either three or six digits: '#0'") {eval("#0")}
assert_raise(Sass::SyntaxError,
assert_raise_message(Sass::SyntaxError,
"Colors must have either three or six digits: '#12'") {eval("#12")}
assert_raise(Sass::SyntaxError,
assert_raise_message(Sass::SyntaxError,
"Colors must have either three or six digits: '#abcd'") {eval("#abcd")}
assert_raise(Sass::SyntaxError,
assert_raise_message(Sass::SyntaxError,
"Colors must have either three or six digits: '#abcdE'") {eval("#abcdE")}
assert_raise(Sass::SyntaxError,
assert_raise_message(Sass::SyntaxError,
"Colors must have either three or six digits: '#abcdEFA'") {eval("#abcdEFA")}
end
@ -386,7 +386,7 @@ SASS
end
def test_misplaced_comma_in_funcall
assert_raise(Sass::SyntaxError,
assert_raise_message(Sass::SyntaxError,
'Invalid CSS after "foo(bar, ": expected function argument, was ")"') {eval('foo(bar, )')}
end

View file

@ -965,7 +965,7 @@ SCSS
end
def test_parent_in_mid_selector_error
assert_raise(Sass::SyntaxError, <<MESSAGE) {render <<SCSS}
assert_raise_message(Sass::SyntaxError, <<MESSAGE) {render <<SCSS}
Invalid CSS after ".foo": expected "{", was "&.bar"
In Sass 3, the parent selector & can only be used where element names are valid,
@ -978,8 +978,8 @@ SCSS
end
def test_parent_in_mid_selector_error
assert_raise(Sass::SyntaxError, <<MESSAGE) {render <<SCSS}
Invalid CSS after ".foo.bar": expected "{", was "&"
assert_raise_message(Sass::SyntaxError, <<MESSAGE) {render <<SCSS}
Invalid CSS after " .foo.bar": expected "{", was "& {a: b}"
In Sass 3, the parent selector & can only be used where element names are valid,
since it could potentially be replaced by an element name.
@ -991,8 +991,8 @@ SCSS
end
def test_double_parent_selector_error
assert_raise(Sass::SyntaxError, <<MESSAGE) {render <<SCSS}
Invalid CSS after "&": expected "{", was "&"
assert_raise_message(Sass::SyntaxError, <<MESSAGE) {render <<SCSS}
Invalid CSS after " &": expected "{", was "& {a: b}"
In Sass 3, the parent selector & can only be used where element names are valid,
since it could potentially be replaced by an element name.
@ -1004,8 +1004,8 @@ SCSS
end
def test_no_interpolation_in_media_queries
assert_raise(Sass::SyntaxError, <<MESSAGE) {render <<SCSS}
Invalid CSS after "...nd (min-width: ": expected expression (e.g. 1px, bold), was "\#{100}px) {
assert_raise_message(Sass::SyntaxError, <<MESSAGE.rstrip) {render <<SCSS}
Invalid CSS after "...nd (min-width: ": expected expression (e.g. 1px, bold), was "\#{100}px) {"
MESSAGE
@media screen and (min-width: \#{100}px) {
foo {bar: baz}
@ -1014,7 +1014,7 @@ SCSS
end
def test_no_interpolation_in_unrecognized_directives
assert_raise(Sass::SyntaxError, <<MESSAGE) {render <<SCSS}
assert_raise_message(Sass::SyntaxError, <<MESSAGE.rstrip) {render <<SCSS}
Invalid CSS after "@foo ": expected selector or at-rule, was "\#{100} {"
MESSAGE
@foo \#{100} {
@ -1049,8 +1049,8 @@ SCSS
end
def test_extra_comma_in_mixin_arglist_error
assert_raise(Sass::SyntaxError, <<MESSAGE) {render <<SCSS}
Invalid CSS after "@include foo(bar, ": expected mixin argument, was ")"
assert_raise_message(Sass::SyntaxError, <<MESSAGE.rstrip) {render <<SCSS}
Invalid CSS after "...clude foo(bar, ": expected mixin argument, was ");"
MESSAGE
@mixin foo($a1, $a2) {
baz: $a1 $a2;

View file

@ -78,4 +78,13 @@ class Test::Unit::TestCase
return '' unless Haml::Util.ap_geq?("3.0.0.rc")
return '<div style="margin:0;padding:0;display:inline"><input name="_snowman" type="hidden" value="&#9731;" /></div>'
end
def assert_raise_message(klass, message)
yield
rescue Exception => e
assert_instance_of(klass, e)
assert_equal(message, e.message)
else
flunk "Expected exception #{klass}, none raised"
end
end