mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
Add a bunch of tests for Sass warnings.
One broken test for a minor error.
This commit is contained in:
parent
12724ef809
commit
b555b7efa6
3 changed files with 62 additions and 16 deletions
|
@ -718,12 +718,9 @@ SASS
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def render(sass, options = {})
|
def render(sass, options = {})
|
||||||
unless options[:filename]
|
munge_filename options
|
||||||
test_name = caller.first.gsub(/^.*`(.*)'.*$/, '\1')
|
|
||||||
options[:filename] = "#{test_name}_inline.sass"
|
|
||||||
end
|
|
||||||
Sass::Engine.new(sass, options).render
|
Sass::Engine.new(sass, options).render
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -5,15 +5,6 @@ require 'sass/engine'
|
||||||
class SassScriptTest < Test::Unit::TestCase
|
class SassScriptTest < Test::Unit::TestCase
|
||||||
include Sass::Script
|
include Sass::Script
|
||||||
|
|
||||||
def resolve(str, opts = {}, environment = {})
|
|
||||||
eval(str, opts, environment).to_s
|
|
||||||
end
|
|
||||||
|
|
||||||
def eval(str, opts = {}, environment = {})
|
|
||||||
Sass::Script.parse(str, opts[:line] || 0,
|
|
||||||
opts[:offset] || 0, opts[:filename]).perform(environment)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_color_checks_input
|
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([1, 2, -1])}
|
||||||
assert_raise(Sass::SyntaxError, "Color values must be between 0 and 255") {Color.new([256, 2, 3])}
|
assert_raise(Sass::SyntaxError, "Color values must be between 0 and 255") {Color.new([256, 2, 3])}
|
||||||
|
@ -39,9 +30,43 @@ class SassScriptTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_warning_reporting
|
||||||
|
assert_warning(<<WARN) {eval("foo")}
|
||||||
|
DEPRECATION WARNING:
|
||||||
|
On line 1, character 1 of 'test_warning_reporting_inline.sass'
|
||||||
|
Implicit strings have been deprecated and will be removed in version 2.4.
|
||||||
|
'foo' was not quoted. Please add double quotes (e.g. "foo").
|
||||||
|
WARN
|
||||||
|
assert_warning(<<WARN) {eval("1 + foo")}
|
||||||
|
DEPRECATION WARNING:
|
||||||
|
On line 1, character 5 of 'test_warning_reporting_inline.sass'
|
||||||
|
Implicit strings have been deprecated and will be removed in version 2.4.
|
||||||
|
'foo' was not quoted. Please add double quotes (e.g. "foo").
|
||||||
|
WARN
|
||||||
|
assert_warning(<<WARN) {render("@if 1 + foo")}
|
||||||
|
DEPRECATION WARNING:
|
||||||
|
On line 1, character 9 of 'test_warning_reporting_inline.sass'
|
||||||
|
Implicit strings have been deprecated and will be removed in version 2.4.
|
||||||
|
'foo' was not quoted. Please add double quotes (e.g. "foo").
|
||||||
|
WARN
|
||||||
|
|
||||||
|
# Regression
|
||||||
|
assert_warning(<<WARN) {render("@if if")}
|
||||||
|
DEPRECATION WARNING:
|
||||||
|
On line 1, character 5 of 'test_warning_reporting_inline.sass'
|
||||||
|
Implicit strings have been deprecated and will be removed in version 2.4.
|
||||||
|
'if' was not quoted. Please add double quotes (e.g. "if").
|
||||||
|
WARN
|
||||||
|
end
|
||||||
|
|
||||||
def test_inaccessible_functions
|
def test_inaccessible_functions
|
||||||
assert_warning "DEPRECATION WARNING:\nOn line 2, character 6 of 'test_inaccessible_functions_inline.sass'\nImplicit strings have been deprecated and will be removed in version 2.4.\n'to_s' was not quoted. Please add double quotes (e.g. \"to_s\")." do
|
assert_warning <<WARN do
|
||||||
assert_equal "send(to_s)", resolve("send(to_s)", :line => 2, :filename => 'test_inaccessible_functions_inline.sass')
|
DEPRECATION WARNING:
|
||||||
|
On line 2, character 6 of 'test_inaccessible_functions_inline.sass'
|
||||||
|
Implicit strings have been deprecated and will be removed in version 2.4.
|
||||||
|
'to_s' was not quoted. Please add double quotes (e.g. "to_s").
|
||||||
|
WARN
|
||||||
|
assert_equal "send(to_s)", resolve("send(to_s)", :line => 2)
|
||||||
end
|
end
|
||||||
assert_equal "public_instance_methods()", resolve("public_instance_methods()")
|
assert_equal "public_instance_methods()", resolve("public_instance_methods()")
|
||||||
end
|
end
|
||||||
|
@ -54,6 +79,22 @@ class SassScriptTest < Test::Unit::TestCase
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def resolve(str, opts = {}, environment = {})
|
||||||
|
munge_filename opts
|
||||||
|
eval(str, opts, environment).to_s
|
||||||
|
end
|
||||||
|
|
||||||
|
def eval(str, opts = {}, environment = {})
|
||||||
|
munge_filename opts
|
||||||
|
Sass::Script.parse(str, opts[:line] || 1,
|
||||||
|
opts[:offset] || 0, opts[:filename]).perform(environment)
|
||||||
|
end
|
||||||
|
|
||||||
|
def render(sass, options = {})
|
||||||
|
munge_filename options
|
||||||
|
Sass::Engine.new(sass, options).render
|
||||||
|
end
|
||||||
|
|
||||||
def assert_warning(message)
|
def assert_warning(message)
|
||||||
the_real_stderr, $stderr = $stderr, StringIO.new
|
the_real_stderr, $stderr = $stderr, StringIO.new
|
||||||
yield
|
yield
|
||||||
|
|
|
@ -11,3 +11,11 @@ unless defined? RAILS_ROOT
|
||||||
RAILS_ROOT = '.'
|
RAILS_ROOT = '.'
|
||||||
MERB_ENV = RAILS_ENV = 'testing'
|
MERB_ENV = RAILS_ENV = 'testing'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class Test::Unit::TestCase
|
||||||
|
def munge_filename(opts)
|
||||||
|
return if opts[:filename]
|
||||||
|
test_name = caller[1].gsub(/^.*`(.*)'.*$/, '\1')
|
||||||
|
opts[:filename] = "#{test_name}_inline.sass"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue