1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00

Test inputs for hsl() as well.

This commit is contained in:
Nathan Weizenbaum 2008-10-25 19:02:54 -07:00
parent ce15479a65
commit 8f4ac8e888
2 changed files with 14 additions and 6 deletions

View file

@ -27,8 +27,13 @@ module Sass::Script
# hue is in degrees,
# and saturation and lightness are percentages.
def hsl(h, s, l)
original_s = s
original_l = l
# This algorithm is from http://www.w3.org/TR/css3-color#hsl-color
h, s, l = [h, s, l].map { |a| a.value }
raise ArgumentError.new("Saturation #{s} must be between 0% and 100%") if s < 0 || s > 100
raise ArgumentError.new("Lightness #{l} must be between 0% and 100%") if l < 0 || l > 100
h = (h % 360) / 360.0
s /= 100.0
l /= 100.0

View file

@ -43,6 +43,11 @@ class SassFunctionTest < Test::Unit::TestCase
assert_rgb_hsl(purple, ['2820', '100%', '50%'])
end
def test_hsl_checks_bounds
assert_error_message("Saturation -114 must be between 0% and 100% for `hsl'", "hsl(10, -114, 12)");
assert_error_message("Lightness 256 must be between 0% and 100% for `hsl'", "hsl(10, 10, 256%)");
end
def test_percentage
assert_equal("50%", evaluate("percentage(.5)"))
assert_equal("100%", evaluate("percentage(1)"))
@ -81,12 +86,10 @@ class SassFunctionTest < Test::Unit::TestCase
end
def assert_error_message(message, value)
begin
evaluate(value)
flunk("Error message expected but not raised: #{message}")
rescue Sass::SyntaxError => e
assert_equal(message, e.message)
end
evaluate(value)
flunk("Error message expected but not raised: #{message}")
rescue Sass::SyntaxError => e
assert_equal(message, e.message)
end
end