test/sass/engine_test.rb in sass-3.3.0.alpha.88 vs test/sass/engine_test.rb in sass-3.3.0.alpha.93

- old
+ new

@@ -9,10 +9,19 @@ module Sass::Script::Functions::UserFunctions def option(name) Sass::Script::String.new(@options[name.value.to_sym].to_s) end + + def set_a_variable(name, value) + environment.set_var(name.value, value) + return Sass::Script::Null.new + end + + def get_a_variable(name) + environment.var(name.value) || Sass::Script::String.new("undefined") + end end class SassEngineTest < Test::Unit::TestCase FAKE_FILE_NAME = __FILE__.gsub(/rb$/,"sass") # A map of erroneous Sass documents to the error messages they should produce. @@ -1395,9 +1404,47 @@ $intermediate: $val1 + $val2 @return $intermediate/3 bar a: foo(1, 2) +SASS + end + + def test_user_defined_function_variable_scope + render(<<SASS) +bar + -no-op: set-a-variable(variable, 5) + a: $variable +SASS + flunk("Exception not raised for test_user_defined_function_variable_scope") + rescue Sass::SyntaxError => e + assert_equal('Undefined variable: "$variable".', e.message) + end + + def test_user_defined_function_can_change_global_variable + assert_equal(<<CSS, render(<<SASS)) +bar { + a: 5; } +CSS +$variable: 0 +bar + $local: 10 + -no-op: set-a-variable(variable, 5) + a: $variable +SASS + end + + def test_user_defined_function_cannot_read_local_variable + assert_equal(<<CSS, render(<<SASS)) +bar { + global: 0; + local: undefined; } +CSS +$global: 0 +bar + $local: 10 + global: get-a-variable(global) + local: get-a-variable(local) SASS end def test_control_directive_in_nested_property assert_equal(<<CSS, render(<<SASS))