summaryrefslogtreecommitdiff
path: root/test/ruby/test_module.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/ruby/test_module.rb')
-rw-r--r--test/ruby/test_module.rb27
1 files changed, 23 insertions, 4 deletions
diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb
index 92b2f7b561..2df31d06df 100644
--- a/test/ruby/test_module.rb
+++ b/test/ruby/test_module.rb
@@ -216,10 +216,29 @@ class TestModule < Test::Unit::TestCase
remove_rake_mixins(remove_json_mixins(remove_pp_mixins(String.ancestors))))
end
+ CLASS_EVAL = 2
+ @@class_eval = 'b'
+
def test_class_eval
Other.class_eval("CLASS_EVAL = 1")
assert_equal(1, Other::CLASS_EVAL)
assert(Other.constants.include?(:CLASS_EVAL))
+ assert_equal(2, Other.class_eval { CLASS_EVAL })
+
+ Other.class_eval("@@class_eval = 'a'")
+ assert_equal('a', Other.class_variable_get(:@@class_eval))
+ assert_equal('b', Other.class_eval { @@class_eval })
+
+ Other.class_eval do
+ module_function
+
+ def class_eval_test
+ "foo"
+ end
+ end
+ assert("foo", Other.class_eval_test)
+
+ assert_equal([Other], Other.class_eval { |*args| args })
end
def test_const_defined?
@@ -451,7 +470,7 @@ class TestModule < Test::Unit::TestCase
def test_class_variable_get
c = Class.new
- c.class_eval { @@foo = :foo }
+ c.class_eval('@@foo = :foo')
assert_equal(:foo, c.class_variable_get(:@@foo))
assert_raise(NameError) { c.class_variable_get(:@@bar) } # c.f. instance_variable_get
assert_raise(NameError) { c.class_variable_get(:foo) }
@@ -460,13 +479,13 @@ class TestModule < Test::Unit::TestCase
def test_class_variable_set
c = Class.new
c.class_variable_set(:@@foo, :foo)
- assert_equal(:foo, c.class_eval { @@foo })
+ assert_equal(:foo, c.class_eval('@@foo'))
assert_raise(NameError) { c.class_variable_set(:foo, 1) }
end
def test_class_variable_defined
c = Class.new
- c.class_eval { @@foo = :foo }
+ c.class_eval('@@foo = :foo')
assert_equal(true, c.class_variable_defined?(:@@foo))
assert_equal(false, c.class_variable_defined?(:@@bar))
assert_raise(NameError) { c.class_variable_defined?(:foo) }
@@ -474,7 +493,7 @@ class TestModule < Test::Unit::TestCase
def test_remove_class_variable
c = Class.new
- c.class_eval { @@foo = :foo }
+ c.class_eval('@@foo = :foo')
c.class_eval { remove_class_variable(:@@foo) }
assert_equal(false, c.class_variable_defined?(:@@foo))
end