Add tests for error line numbers in Sass.
This exposes a bug.
This commit is contained in:
parent
506623645d
commit
79034f3752
|
@ -5,6 +5,10 @@ require File.dirname(__FILE__) + '/../../lib/sass'
|
||||||
require 'sass/engine'
|
require 'sass/engine'
|
||||||
|
|
||||||
class SassEngineTest < Test::Unit::TestCase
|
class SassEngineTest < Test::Unit::TestCase
|
||||||
|
# A map of erroneous Sass documents to the error messages they should produce.
|
||||||
|
# The error messages may be arrays;
|
||||||
|
# if so, the second element should be the line number that should be reported for the error.
|
||||||
|
# If this isn't provided, the tests will assume the line number should be the last line of the document.
|
||||||
EXCEPTION_MAP = {
|
EXCEPTION_MAP = {
|
||||||
"!a = 1 + " => 'Constant arithmetic error: "1 +".',
|
"!a = 1 + " => 'Constant arithmetic error: "1 +".',
|
||||||
"!a = 1 + 2 +" => 'Constant arithmetic error: "1 + 2 +".',
|
"!a = 1 + 2 +" => 'Constant arithmetic error: "1 + 2 +".',
|
||||||
|
@ -77,8 +81,10 @@ END
|
||||||
begin
|
begin
|
||||||
Sass::Engine.new(key).render
|
Sass::Engine.new(key).render
|
||||||
rescue Sass::SyntaxError => err
|
rescue Sass::SyntaxError => err
|
||||||
assert_equal(value, err.message)
|
value = [value] unless value.is_a?(Array)
|
||||||
assert(err.sass_line, "Line: #{key}")
|
|
||||||
|
assert_equal(value.first, err.message, "Line: #{key}")
|
||||||
|
assert_equal(value[1] || key.split("\n").length, err.sass_line, "Line: #{key}")
|
||||||
assert_match(/\(sass\):[0-9]+/, err.backtrace[0], "Line: #{key}")
|
assert_match(/\(sass\):[0-9]+/, err.backtrace[0], "Line: #{key}")
|
||||||
else
|
else
|
||||||
assert(false, "Exception not raised for\n#{key}")
|
assert(false, "Exception not raised for\n#{key}")
|
||||||
|
|
Loading…
Reference in New Issue