diff options
| author | Satoshi Tagomori <s-tagomori@sakura.ad.jp> | 2025-11-05 12:02:07 +0900 |
|---|---|---|
| committer | Satoshi Tagomori <tagomoris@gmail.com> | 2025-11-07 13:14:54 +0900 |
| commit | f19b29d1dbb2918dee112b0df0cba2ca1165a399 (patch) | |
| tree | 035d0e3e988fbe662e3797ee4d520d04aa28ea71 | |
| parent | cf4a034d59913fb71a7dd1b052164984be4a3d14 (diff) | |
Add namespace tests about global variables, toplevel methods
| -rw-r--r-- | test/ruby/test_namespace.rb | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/test/ruby/test_namespace.rb b/test/ruby/test_namespace.rb index daa4e9e0ba..4241ce62ff 100644 --- a/test/ruby/test_namespace.rb +++ b/test/ruby/test_namespace.rb @@ -700,8 +700,13 @@ class TestNamespace < Test::Unit::TestCase assert_separately([ENV_ENABLE_NAMESPACE], __FILE__, __LINE__, "#{<<~"begin;"}\n#{<<~'end;'}", ignore_stderr: true) begin; ns = Namespace.new + $gvar1 = 'bar' code = <<~EOC NS1 = Namespace.current + $gvar1 = 'foo' + + def toplevel = $gvar1 + class Foo NS2 = Namespace.current NS2_proc = ->(){ NS2 } @@ -721,6 +726,9 @@ class TestNamespace < Test::Unit::TestCase def self.yield_block = yield def self.call_block(&b) = b.call + + def self.gvar1 = $gvar1 + def self.call_toplevel = toplevel end FOO_NAME = Foo.name @@ -749,6 +757,10 @@ class TestNamespace < Test::Unit::TestCase assert_equal outer, ns::Foo.yield_block{ Namespace.current } # method yields assert_equal outer, ns::Foo.call_block{ Namespace.current } # method calls a block + assert_equal 'foo', ns::Foo.gvar1 # method refers gvar + assert_equal 'bar', $gvar1 # gvar value out of the ns + assert_equal 'foo', ns::Foo.call_toplevel # toplevel method referring gvar + assert_equal ns, ns::NS_X # on TOP frame, referring a class in the current assert_equal ns, ns::NS_Y # on TOP frame, referring Kernel method defined by a CFUNC method |
