diff --git a/lib/sass/script/number.rb b/lib/sass/script/number.rb index 8872039e..6ce05cf3 100644 --- a/lib/sass/script/number.rb +++ b/lib/sass/script/number.rb @@ -155,9 +155,19 @@ module Sass::Script # @param other [Literal] The right-hand side of the operator # @return [Boolean] Whether this number is equal to the other object def eq(other) - Sass::Script::Bool.new(super.to_bool && - self.numerator_units.sort == other.numerator_units.sort && - self.denominator_units.sort == other.denominator_units.sort) + return Sass::Script::Bool.new(false) unless other.is_a?(Sass::Script::Number) + this = self + begin + if unitless? + this = this.coerce(other.numerator_units, other.denominator_units) + else + other = other.coerce(numerator_units, denominator_units) + end + rescue Sass::SyntaxError + return Sass::Script::Bool.new(false) + end + + Sass::Script::Bool.new(this.value == other.value) end # The SassScript `>` operation. @@ -253,7 +263,7 @@ module Sass::Script def operate(other, operation) this = self - if [:+, :-].include?(operation) + if [:+, :-, :<=, :<, :>, :>=].include?(operation) if unitless? this = this.coerce(other.numerator_units, other.denominator_units) else diff --git a/lib/sass/tree/for_node.rb b/lib/sass/tree/for_node.rb index 92600b70..02675130 100644 --- a/lib/sass/tree/for_node.rb +++ b/lib/sass/tree/for_node.rb @@ -28,14 +28,17 @@ module Sass::Tree # @return [Array] The resulting static nodes # @see Sass::Tree def _perform(environment) - from = @from.perform(environment).to_i - to = @to.perform(environment).to_i - range = Range.new(from, to, @exclusive) + from = @from.perform(environment) + to = @to.perform(environment) + if to.respond_to?(:coerce) + to = to.send(:coerce, from.numerator_units, from.denominator_units) + end + range = Range.new(from.to_i, to.to_i, @exclusive) children = [] environment = Sass::Environment.new(environment) range.each do |i| - environment.set_local_var(@var, Sass::Script::Number.new(i)) + environment.set_local_var(@var, Sass::Script::Number.new(i, from.numerator_units, from.denominator_units)) children += perform_children(environment) end children diff --git a/test/sass/engine_test.rb b/test/sass/engine_test.rb index 67c47bdb..4803c2ef 100755 --- a/test/sass/engine_test.rb +++ b/test/sass/engine_test.rb @@ -76,8 +76,10 @@ class SassEngineTest < Test::Unit::TestCase "@if false\n@else if " => "Invalid else directive '@else if': expected 'if '.", "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 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.', + '@for !a from 1px to 3em' => "Incompatible units: 'em' and 'px'.", '@if' => "Invalid if directive '@if': expected expression.", '@while' => "Invalid while directive '@while': expected expression.", '@debug' => "Invalid debug directive '@debug': expected expression.",