mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
Add tests for implicit strings.
This commit is contained in:
parent
b2f17de575
commit
12724ef809
3 changed files with 55 additions and 30 deletions
|
@ -50,6 +50,10 @@ class Sass::Script::Literal # :nodoc:
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def ==(other)
|
||||||
|
eq(other).to_bool
|
||||||
|
end
|
||||||
|
|
||||||
def to_i
|
def to_i
|
||||||
raise SyntaxError.new("#{value.dump} is not an integer.")
|
raise SyntaxError.new("#{value.dump} is not an integer.")
|
||||||
end
|
end
|
||||||
|
|
|
@ -717,13 +717,6 @@ SASS
|
||||||
assert_raise(Sass::SyntaxError) { render("a\n b = hsl(1)") }
|
assert_raise(Sass::SyntaxError) { render("a\n b = hsl(1)") }
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_inaccessible_functions
|
|
||||||
assert_warning "DEPRECATION WARNING:\nOn line 2, character 12 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_equal("a {\n b: send(to_s); }\n", render("a\n b = send(to_s)"))
|
|
||||||
end
|
|
||||||
assert_equal("a {\n b: public_instance_methods(); }\n", render("a\n b = public_instance_methods()"))
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def render(sass, options = {})
|
def render(sass, options = {})
|
||||||
|
@ -752,19 +745,4 @@ SASS
|
||||||
def filename(name, type)
|
def filename(name, type)
|
||||||
File.dirname(__FILE__) + "/#{type == 'sass' ? 'templates' : 'results'}/#{name}.#{type}"
|
File.dirname(__FILE__) + "/#{type == 'sass' ? 'templates' : 'results'}/#{name}.#{type}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_warning(message)
|
|
||||||
the_real_stderr, $stderr = $stderr, StringIO.new
|
|
||||||
yield
|
|
||||||
assert_equal message.strip, $stderr.string.strip
|
|
||||||
ensure
|
|
||||||
$stderr = the_real_stderr
|
|
||||||
end
|
|
||||||
|
|
||||||
def silence_warnings
|
|
||||||
the_real_stderr, $stderr = $stderr, StringIO.new
|
|
||||||
yield
|
|
||||||
ensure
|
|
||||||
$stderr = the_real_stderr
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,8 +5,13 @@ require 'sass/engine'
|
||||||
class SassScriptTest < Test::Unit::TestCase
|
class SassScriptTest < Test::Unit::TestCase
|
||||||
include Sass::Script
|
include Sass::Script
|
||||||
|
|
||||||
def eval(str, environment = {})
|
def resolve(str, opts = {}, environment = {})
|
||||||
Sass::Script.resolve(str, 0, 0, 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
|
end
|
||||||
|
|
||||||
def test_color_checks_input
|
def test_color_checks_input
|
||||||
|
@ -15,14 +20,52 @@ class SassScriptTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_string_escapes
|
def test_string_escapes
|
||||||
assert_equal '"', eval("\"\\\"\"")
|
assert_equal '"', resolve("\"\\\"\"")
|
||||||
assert_equal "\\", eval("\"\\\\\"")
|
assert_equal "\\", resolve("\"\\\\\"")
|
||||||
assert_equal "\\02fa", eval("\"\\02fa\"")
|
assert_equal "\\02fa", resolve("\"\\02fa\"")
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_color_names
|
def test_color_names
|
||||||
assert_equal "white", eval("white")
|
assert_equal "white", resolve("white")
|
||||||
assert_equal "white", eval("#ffffff")
|
assert_equal "white", resolve("#ffffff")
|
||||||
assert_equal "#fffffe", eval("white - #000001")
|
assert_equal "#fffffe", resolve("white - #000001")
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_implicit_strings
|
||||||
|
silence_warnings do
|
||||||
|
assert_equal Sass::Script::String.new("foo"), eval("foo")
|
||||||
|
assert_equal Sass::Script::String.new("foo bar"), eval("foo bar")
|
||||||
|
assert_equal Sass::Script::String.new("foo/bar"), eval("foo/bar")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
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_equal "send(to_s)", resolve("send(to_s)", :line => 2, :filename => 'test_inaccessible_functions_inline.sass')
|
||||||
|
end
|
||||||
|
assert_equal "public_instance_methods()", resolve("public_instance_methods()")
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_ruby_equality
|
||||||
|
assert_equal eval('"foo"'), eval('"foo"')
|
||||||
|
assert_equal eval('1'), eval('1.0')
|
||||||
|
assert_not_equal eval('1'), eval('"1"')
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def assert_warning(message)
|
||||||
|
the_real_stderr, $stderr = $stderr, StringIO.new
|
||||||
|
yield
|
||||||
|
assert_equal message.strip, $stderr.string.strip
|
||||||
|
ensure
|
||||||
|
$stderr = the_real_stderr
|
||||||
|
end
|
||||||
|
|
||||||
|
def silence_warnings
|
||||||
|
the_real_stderr, $stderr = $stderr, StringIO.new
|
||||||
|
yield
|
||||||
|
ensure
|
||||||
|
$stderr = the_real_stderr
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue