1
0
Fork 0
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:
Nathan Weizenbaum 2008-12-25 13:27:15 -08:00
parent b2f17de575
commit 12724ef809
3 changed files with 55 additions and 30 deletions

View file

@ -50,6 +50,10 @@ class Sass::Script::Literal # :nodoc:
true
end
def ==(other)
eq(other).to_bool
end
def to_i
raise SyntaxError.new("#{value.dump} is not an integer.")
end

View file

@ -717,13 +717,6 @@ SASS
assert_raise(Sass::SyntaxError) { render("a\n b = hsl(1)") }
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
def render(sass, options = {})
@ -752,19 +745,4 @@ SASS
def filename(name, type)
File.dirname(__FILE__) + "/#{type == 'sass' ? 'templates' : 'results'}/#{name}.#{type}"
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

View file

@ -5,8 +5,13 @@ require 'sass/engine'
class SassScriptTest < Test::Unit::TestCase
include Sass::Script
def eval(str, environment = {})
Sass::Script.resolve(str, 0, 0, environment)
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
@ -15,14 +20,52 @@ class SassScriptTest < Test::Unit::TestCase
end
def test_string_escapes
assert_equal '"', eval("\"\\\"\"")
assert_equal "\\", eval("\"\\\\\"")
assert_equal "\\02fa", eval("\"\\02fa\"")
assert_equal '"', resolve("\"\\\"\"")
assert_equal "\\", resolve("\"\\\\\"")
assert_equal "\\02fa", resolve("\"\\02fa\"")
end
def test_color_names
assert_equal "white", eval("white")
assert_equal "white", eval("#ffffff")
assert_equal "#fffffe", eval("white - #000001")
assert_equal "white", resolve("white")
assert_equal "white", resolve("#ffffff")
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