diff options
author | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-12-03 18:25:57 +0000 |
---|---|---|
committer | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-12-03 18:25:57 +0000 |
commit | 7dbfe89630f429255ae346cd02d7ca7d2d109650 (patch) | |
tree | e6bb9639b21f89e4f250fe523e3602e6abc05bc5 /test/ruby/test_module.rb | |
parent | 9998481d4efaf86dde652617ed3b2777924c3373 (diff) | |
download | ruby-7dbfe89630f429255ae346cd02d7ca7d2d109650.tar.gz |
* compile.c (compile_cpath, iseq_compile_each): reverted
constant/class variable lookup in instance_eval etc. to the
behavior of 1.8.
* eval.c (rb_mod_nesting): ditto.
* insns.def (putspecialobject, defineclass): ditto.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL): ditto.
* vm_core.h (VM_SPECIAL_OBJECT_CONST_BASE): ditto.
* vm_eval.c (yield_under, eval_under): ditto.
* vm_insnhelper.c (vm_cref_push, vm_get_const_base,
vm_get_ev_const, vm_get_cvar_base): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25984 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_module.rb')
-rw-r--r-- | test/ruby/test_module.rb | 27 |
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 |