aboutsummaryrefslogtreecommitdiffstats
path: root/test/ruby/test_proc.rb
diff options
context:
space:
mode:
authormame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-03-08 17:26:26 +0000
committermame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-03-08 17:26:26 +0000
commitd84595deb0a38a88d2b501969f135fba8da34b80 (patch)
tree8f1889a8d6ce3855e515439efda4b9a5e62bfade /test/ruby/test_proc.rb
parentf725819666fea2eb3746f02ef81fca64f4b03992 (diff)
downloadruby-d84595deb0a38a88d2b501969f135fba8da34b80.tar.gz
* test/ruby/test_proc.rb: add some tests.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22827 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_proc.rb')
-rw-r--r--test/ruby/test_proc.rb31
1 files changed, 31 insertions, 0 deletions
diff --git a/test/ruby/test_proc.rb b/test/ruby/test_proc.rb
index cb0548ba66..8439f8cd6b 100644
--- a/test/ruby/test_proc.rb
+++ b/test/ruby/test_proc.rb
@@ -176,6 +176,11 @@ class TestProc < Test::Unit::TestCase
b = proc { :foo }
assert_equal(:foo, b.curry[])
+
+ b = lambda {|x, y, &b| b.call(x + y) }.curry
+ b = b.call(2) { raise }
+ b = b.call(3) {|x| x + 4 }
+ assert_equal(9, b)
end
def test_curry_ski_fib
@@ -279,6 +284,10 @@ class TestProc < Test::Unit::TestCase
def test_arity2
assert_equal(0, method(:proc).to_proc.arity)
assert_equal(-1, proc {}.curry.arity)
+
+ c = Class.new
+ c.class_eval { attr_accessor :foo }
+ assert_equal(1, c.new.method(:foo=).to_proc.arity)
end
def test_proc_location
@@ -688,6 +697,9 @@ class TestProc < Test::Unit::TestCase
assert_equal([[:opt, :a], [:opt, :b], [:rest, :c], [:opt, :d], [:block, :e]], proc {|a, b=:b, *c, d, &e|}.parameters)
assert_equal([[:opt, nil], [:block, :b]], proc {|(a), &b|}.parameters)
assert_equal([[:opt, :a], [:opt, :b], [:opt, :c], [:opt, :d], [:rest, :e], [:opt, :f], [:opt, :g], [:block, :h]], proc {|a,b,c=:c,d=:d,*e,f,g,&h|}.parameters)
+
+ assert_equal([[:req]], method(:require).parameters)
+ assert_equal([[:rest]], method(:p).parameters)
end
def pm0() end
@@ -716,4 +728,23 @@ class TestProc < Test::Unit::TestCase
assert_equal([[:req, :a], [:opt, :b], [:rest, :c], [:req, :d], [:block, :e]], method(:pmo7).to_proc.parameters)
assert_equal([[:req], [:block, :b]], method(:pma1).to_proc.parameters)
end
+
+ def test_to_s
+ assert_match(/^#<Proc:0x\h+@#{ Regexp.quote(__FILE__) }:\d+>$/, proc {}.to_s)
+ assert_match(/^#<Proc:0x\h+@#{ Regexp.quote(__FILE__) }:\d+ \(lambda\)>$/, lambda {}.to_s)
+ assert_match(/^#<Proc:0x\h+ \(lambda\)>$/, method(:p).to_proc.to_s)
+ x = proc {}
+ x.taint
+ assert(x.to_s.tainted?)
+ end
+
+ def source_location_test
+ __LINE__
+ end
+
+ def test_source_location
+ file, lineno = method(:source_location_test).source_location
+ assert_match(/^#{ Regexp.quote(__FILE__) }$/, file)
+ assert_equal(source_location_test - 1, lineno)
+ end
end