Skip to content

Commit e992075

Browse files
committed
Add tests, support returning a boolean also
1 parent 39772b4 commit e992075

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

lib/sassc/script/value_conversion.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ def self.to_native(value)
5656
Number.new(value).to_native
5757
when "Map"
5858
Map.new(value).to_native
59+
when "Bool"
60+
Bool.new(value).to_native
5961
else
6062
raise UnsupportedValue.new("Sass return type #{value_name} unsupported")
6163
end

test/functions_test.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,22 @@ def test_function_that_takes_a_number
8080
CSS
8181
end
8282

83+
def test_function_that_returns_a_bool
84+
assert_sass <<-SCSS, <<-CSS
85+
div { width: returns-a-bool(); }
86+
SCSS
87+
div { width: true; }
88+
CSS
89+
end
90+
91+
def test_function_that_takes_a_bool
92+
assert_sass <<-SCSS, <<-CSS
93+
div { display: inspect-bool(true)}
94+
SCSS
95+
div { display: true; }
96+
CSS
97+
end
98+
8399
def test_function_with_optional_arguments
84100
assert_sass <<-SCSS, <<-EXPECTED_CSS
85101
div {
@@ -199,6 +215,15 @@ def returns_a_number
199215
return Sass::Script::Value::Number.new(-312,'rem')
200216
end
201217

218+
def returns_a_bool
219+
return Sass::Script::Value::Bool.new(true)
220+
end
221+
222+
def inspect_bool ( argument )
223+
raise StandardError.new "passed value is not a Sass::Script::Value::Bool" unless argument.is_a? Sass::Script::Value::Bool
224+
return argument
225+
end
226+
202227
def inspect_number ( argument )
203228
raise StandardError.new "passed value is not a Sass::Script::Value::Number" unless argument.is_a? Sass::Script::Value::Number
204229
return argument

0 commit comments

Comments
 (0)