summaryrefslogtreecommitdiff
path: root/test/ruby/test_lambda.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/ruby/test_lambda.rb')
-rw-r--r--test/ruby/test_lambda.rb54
1 files changed, 3 insertions, 51 deletions
diff --git a/test/ruby/test_lambda.rb b/test/ruby/test_lambda.rb
index 175183d847..241042d2c7 100644
--- a/test/ruby/test_lambda.rb
+++ b/test/ruby/test_lambda.rb
@@ -22,11 +22,13 @@ class TestLambdaParameters < Test::Unit::TestCase
assert_raise(ArgumentError) { ->(a,b){ }.call(1,2,3) }
end
+end
+
+__END__
def test_lambda_as_iterator
a = 0
2.times(&->(_){ a += 1 })
assert_equal(a, 2)
- assert_raise(ArgumentError) {1.times(&->(){ a += 1 })}
end
def test_call_rest_args
@@ -63,54 +65,4 @@ class TestLambdaParameters < Test::Unit::TestCase
def foo
assert_equal(nil, ->(&b){ b }.call)
end
-
- def test_in_basic_object
- bug5966 = '[ruby-core:42349]'
- called = false
- BasicObject.new.instance_eval {->() {called = true}.()}
- assert_equal(true, called, bug5966)
- end
-
- def test_location_on_error
- bug6151 = '[ruby-core:43314]'
- called = 0
- line, f = __LINE__, lambda do
- called += 1
- true
- end
- e = assert_raise(ArgumentError) do
- f.call(42)
- end
- assert_send([e.backtrace.first, :start_with?, "#{__FILE__}:#{line}:"], bug6151)
- assert_equal(0, called)
- e = assert_raise(ArgumentError) do
- 42.times(&f)
- end
- assert_send([e.backtrace.first, :start_with?, "#{__FILE__}:#{line}:"], bug6151)
- assert_equal(0, called)
- end
-
- def test_do_lambda_source_location
- exp_lineno = __LINE__ + 3
- lmd = ->(x,
- y,
- z) do
- #
- end
- file, lineno = lmd.source_location
- assert_match(/^#{ Regexp.quote(__FILE__) }$/, file)
- assert_equal(exp_lineno, lineno, "must be at the beginning of the block")
- end
-
- def test_brace_lambda_source_location
- exp_lineno = __LINE__ + 3
- lmd = ->(x,
- y,
- z) {
- #
- }
- file, lineno = lmd.source_location
- assert_match(/^#{ Regexp.quote(__FILE__) }$/, file)
- assert_equal(exp_lineno, lineno, "must be at the beginning of the block")
- end
end