summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2021-11-18 12:44:19 -0800
committerJeremy Evans <code@jeremyevans.net>2021-11-18 14:17:57 -0800
commit4adb012926f8bd6011168327d8832cf19976de40 (patch)
tree9457020694002d0a0c07ced988a1d09c79fa74e6 /test
parentea02b93bb95a42439631606269659dffc1981883 (diff)
Anonymous block forwarding allows a method to forward a passed
block to another method without having to provide a name for the block parameter. Implements [Feature #11256] Co-authored-by: Yusuke Endoh mame@ruby-lang.org Co-authored-by: Nobuyoshi Nakada nobu@ruby-lang.org
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/5051
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_iseq.rb18
-rw-r--r--test/ruby/test_parse.rb2
-rw-r--r--test/ruby/test_syntax.rb12
3 files changed, 31 insertions, 1 deletions
diff --git a/test/ruby/test_iseq.rb b/test/ruby/test_iseq.rb
index 692549efa0..49f12019dc 100644
--- a/test/ruby/test_iseq.rb
+++ b/test/ruby/test_iseq.rb
@@ -125,6 +125,16 @@ class TestISeq < Test::Unit::TestCase
assert_equal(42, ISeq.load_from_binary(iseq.to_binary).eval)
end
+ def test_super_with_anonymous_block
+ iseq = compile(<<~EOF)
+ def touch3(&block) # :nodoc:
+ foo { super }
+ end
+ 42
+ EOF
+ assert_equal(42, ISeq.load_from_binary(iseq.to_binary).eval)
+ end
+
def test_ractor_unshareable_outer_variable
name = "\u{2603 26a1}"
y = eval("proc {#{name} = nil; proc {|x| #{name} = x}}").call
@@ -373,6 +383,14 @@ class TestISeq < Test::Unit::TestCase
assert_equal [2], param_names
end
+ def anon_block(&); end
+
+ def test_anon_block_param_in_disasm
+ iseq = RubyVM::InstructionSequence.of(method(:anon_block))
+ param_names = iseq.to_a[iseq.to_a.index(:method) + 1]
+ assert_equal [:&], param_names
+ end
+
def strip_lineno(source)
source.gsub(/^.*?: /, "")
end
diff --git a/test/ruby/test_parse.rb b/test/ruby/test_parse.rb
index 3120016e60..d697a29c1c 100644
--- a/test/ruby/test_parse.rb
+++ b/test/ruby/test_parse.rb
@@ -1044,7 +1044,7 @@ x = __ENCODING__
end;
assert_syntax_error("def\nf(000)end", /^ \^~~/)
- assert_syntax_error("def\nf(&)end", /^ \^/)
+ assert_syntax_error("def\nf(&0)end", /^ \^/)
end
def test_method_location_in_rescue
diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb
index 11953ab563..ce1e489992 100644
--- a/test/ruby/test_syntax.rb
+++ b/test/ruby/test_syntax.rb
@@ -66,6 +66,18 @@ class TestSyntax < Test::Unit::TestCase
f&.close!
end
+ def test_anonymous_block_forwarding
+ assert_syntax_error("def b; c(&); end", /no anonymous block parameter/)
+ assert_separately([], "#{<<-"begin;"}\n#{<<-'end;'}")
+ begin;
+ def b(&); c(&) end
+ def c(&); yield 1 end
+ a = nil
+ b{|c| a = c}
+ assert_equal(1, a)
+ end;
+ end
+
def test_newline_in_block_parameters
bug = '[ruby-dev:45292]'
["", "a", "a, b"].product(["", ";x", [";", "x"]]) do |params|