ruby-changes:60876
From: Nobuyoshi <ko1@a...>
Date: Thu, 23 Apr 2020 09:48:12 +0900 (JST)
Subject: [ruby-changes:60876] de9d6a7a8c (master): Split test_defined
https://git.ruby-lang.org/ruby.git/commit/?id=de9d6a7a8c From de9d6a7a8cb0929e0b4cf0a3120971c7b8ee8927 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Wed, 22 Apr 2020 22:21:11 +0900 Subject: Split test_defined diff --git a/test/ruby/test_defined.rb b/test/ruby/test_defined.rb index 9976db3..d254857 100644 --- a/test/ruby/test_defined.rb +++ b/test/ruby/test_defined.rb @@ -23,24 +23,30 @@ class TestDefined < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_defined.rb#L23 return !defined?(yield) end - def test_defined + def test_defined_gloval_variable $x = nil assert(defined?($x)) # global variable assert_equal('global-variable', defined?($x))# returns description + end + def test_defined_local_variable assert_nil(defined?(foo)) # undefined foo=5 assert(defined?(foo)) # local variable + end + def test_defined_constant assert(defined?(Array)) # constant assert(defined?(::Array)) # toplevel constant assert(defined?(File::Constants)) # nested constant + end + + def test_defined_method assert(defined?(Object.new)) # method assert(defined?(Object::new)) # method assert(!defined?(Object.print)) # private method assert(defined?(1 == 2)) # operator expression - f = Foo.new assert_nil(defined?(f.foo)) # protected method f.bar(f) { |v| assert(v) } @@ -53,10 +59,14 @@ class TestDefined < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_defined.rb#L59 assert_nil(defined?(quux(x))) assert(defined?(f.attr = 1)) f.attrasgn_test { |v| assert(v) } + end + def test_defined_yield assert(defined_test) # not iterator assert(!defined_test{}) # called as iterator + end + def test_defined_matchdata /a/ =~ '' assert_equal nil, defined?($&) assert_equal nil, defined?($`) @@ -85,12 +95,16 @@ class TestDefined < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_defined.rb#L95 assert_equal 'global-variable', defined?($+) assert_equal 'global-variable', defined?($1) assert_equal nil, defined?($2) + end + def test_defined_literal assert_equal("nil", defined?(nil)) assert_equal("true", defined?(true)) assert_equal("false", defined?(false)) assert_equal("expression", defined?(1)) + end + def test_defined_empty_paren_expr bug8224 = '[ruby-core:54024] [Bug #8224]' (1..3).each do |level| expr = "("*level+")"*level -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/