mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
[Sass] Add a method to assert that a SassScript value is an integer.
This commit is contained in:
parent
6a8684f229
commit
dfb9239058
3 changed files with 8 additions and 3 deletions
|
@ -170,5 +170,8 @@ module Sass::Script
|
|||
def to_i
|
||||
raise Sass::SyntaxError.new("#{self.inspect} is not an integer.")
|
||||
end
|
||||
|
||||
# @raise [Sass::SyntaxError] if this literal isn't an integer
|
||||
def assert_int!; to_i; end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -30,9 +30,10 @@ module Sass::Tree
|
|||
def _perform(environment)
|
||||
from = @from.perform(environment)
|
||||
to = @to.perform(environment)
|
||||
if to.respond_to?(:coerce)
|
||||
to = to.send(:coerce, from.numerator_units, from.denominator_units)
|
||||
end
|
||||
from.assert_int!
|
||||
to.assert_int!
|
||||
|
||||
to = to.send(:coerce, from.numerator_units, from.denominator_units)
|
||||
range = Range.new(from.to_i, to.to_i, @exclusive)
|
||||
|
||||
children = []
|
||||
|
|
|
@ -76,6 +76,7 @@ class SassEngineTest < Test::Unit::TestCase
|
|||
"@if false\n@else if " => "Invalid else directive '@else if': expected 'if <expr>'.",
|
||||
"a\n !b = 12\nc\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 "foo"' => '"foo" is not an integer.',
|
||||
'@for !a from 1 to 1.232323' => '1.232 is not an integer.',
|
||||
|
|
Loading…
Reference in a new issue