[Sass] Add a method to assert that a SassScript value is an integer.
This commit is contained in:
parent
6a8684f229
commit
dfb9239058
|
@ -170,5 +170,8 @@ module Sass::Script
|
||||||
def to_i
|
def to_i
|
||||||
raise Sass::SyntaxError.new("#{self.inspect} is not an integer.")
|
raise Sass::SyntaxError.new("#{self.inspect} is not an integer.")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# @raise [Sass::SyntaxError] if this literal isn't an integer
|
||||||
|
def assert_int!; to_i; end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -30,9 +30,10 @@ module Sass::Tree
|
||||||
def _perform(environment)
|
def _perform(environment)
|
||||||
from = @from.perform(environment)
|
from = @from.perform(environment)
|
||||||
to = @to.perform(environment)
|
to = @to.perform(environment)
|
||||||
if to.respond_to?(:coerce)
|
from.assert_int!
|
||||||
to = to.send(:coerce, from.numerator_units, from.denominator_units)
|
to.assert_int!
|
||||||
end
|
|
||||||
|
to = to.send(:coerce, from.numerator_units, from.denominator_units)
|
||||||
range = Range.new(from.to_i, to.to_i, @exclusive)
|
range = Range.new(from.to_i, to.to_i, @exclusive)
|
||||||
|
|
||||||
children = []
|
children = []
|
||||||
|
|
|
@ -76,6 +76,7 @@ class SassEngineTest < Test::Unit::TestCase
|
||||||
"@if false\n@else if " => "Invalid else directive '@else if': expected 'if <expr>'.",
|
"@if false\n@else if " => "Invalid else directive '@else if': expected 'if <expr>'.",
|
||||||
"a\n !b = 12\nc\n d = !b" => 'Undefined variable: "!b".',
|
"a\n !b = 12\nc\n d = !b" => 'Undefined variable: "!b".',
|
||||||
"=foo\n !b = 12\nc\n +foo\n d = !b" => 'Undefined variable: "!b".',
|
"=foo\n !b = 12\nc\n +foo\n d = !b" => 'Undefined variable: "!b".',
|
||||||
|
'@for !a from "foo" to 1' => '"foo" is not an integer.',
|
||||||
'@for !a from 1 to "2"' => '"2" is not an integer.',
|
'@for !a from 1 to "2"' => '"2" is not an integer.',
|
||||||
'@for !a from 1 to "foo"' => '"foo" is not an integer.',
|
'@for !a from 1 to "foo"' => '"foo" is not an integer.',
|
||||||
'@for !a from 1 to 1.232323' => '1.232 is not an integer.',
|
'@for !a from 1 to 1.232323' => '1.232 is not an integer.',
|
||||||
|
|
Loading…
Reference in New Issue