From 5e9a18ee5bb25078e11076f9dba96c9b3b0a06e6 Mon Sep 17 00:00:00 2001 From: matz Date: Wed, 26 Mar 2003 07:01:14 +0000 Subject: * eval.c (avalue_splat): new function to do unary * (splat) operator. * eval.c (avalue_to_svalue,svalue_to_avalue,svalue_to_mrhs): do not use implicit "to_ary" conversion. * ext/curses/curses.c (GetWINDOW,GetMOUSE): add taint check. * ext/curses/curses.c (curses_init_screen): ditto. * ext/curses/curses.c (window_initialize): ditto. * gc.c (os_each_obj): prohibit ObjectSpace#each_object in safe mode ($SAFE >= 4). git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@3616 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- sample/test.rb | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) (limited to 'sample') diff --git a/sample/test.rb b/sample/test.rb index fb7c0f675..5c263090d 100644 --- a/sample/test.rb +++ b/sample/test.rb @@ -248,13 +248,33 @@ f = lambda {|r,*l| test_ok([] == r); test_ok([1] == l)} f.call([], *[1]) f.yield([], *[1]) -a = [42,55] -lambda{|x| test_ok([42,55] == x)}.call(a) -lambda{|x,| test_ok([42,55] == x)}.call(a) -lambda{|*x| test_ok([[42,55]] == x)}.call(a) + +f = lambda{|x| x} +test_ok(f.call(42) == 42) +test_ok(f.call([42]) == [42]) +test_ok(f.call([[42]]) == [[42]]) +test_ok(f.call([42,55]) == [42,55]) +test_ok(f.call(42,55) == [42,55]) + +f = lambda{|x,| x} +test_ok(f.call(42) == 42) +test_ok(f.call([42]) == [42]) +test_ok(f.call([[42]]) == [[42]]) +test_ok(f.call([42,55]) == [42,55]) + +f = lambda{|*x| x} +test_ok(f.call(42) == [42]) +test_ok(f.call([42]) == [[42]]) +test_ok(f.call([[42]]) == [[[42]]]) +test_ok(f.call([42,55]) == [[42,55]]) +test_ok(f.call(42,55) == [42,55]) a,=*[1] test_ok(a == 1) +a,=*[[1]] +test_ok(a == 1) +a,=*[[[1]]] +test_ok(a == [1]) a = loop do break; end; test_ok(a == nil) a = loop do break nil; end; test_ok(a == nil) @@ -905,10 +925,12 @@ class IterTest def each8; @body.each {|x| yield(x) } end def f(a) - test_ok(a == [1]) + a end end -IterTest.new(nil).method(:f).to_proc.call([1]) +test_ok(IterTest.new(nil).method(:f).to_proc.call([1]) == [1]) +m = /\w+/.match("abc") +test_ok(IterTest.new(nil).method(:f).to_proc.call([m]) == [m]) IterTest.new([0]).each0 {|x| test_ok(x == 0)} IterTest.new([1]).each1 {|x| test_ok(x == 1)} -- cgit