diff options
Diffstat (limited to 'sample')
-rw-r--r-- | sample/README | 56 | ||||
-rw-r--r-- | sample/biorhythm.rb | 10 | ||||
-rw-r--r-- | sample/cal.rb | 119 | ||||
-rw-r--r-- | sample/fib.py | 10 | ||||
-rw-r--r-- | sample/from.rb | 1 | ||||
-rw-r--r-- | sample/goodfriday.rb | 35 | ||||
-rw-r--r-- | sample/list.rb | 16 | ||||
-rw-r--r-- | sample/mine.rb | 42 | ||||
-rw-r--r-- | sample/rbc.rb | 8 | ||||
-rw-r--r-- | sample/rcs.rb | 10 | ||||
-rw-r--r-- | sample/rename.rb | 14 | ||||
-rw-r--r-- | sample/sieve.rb | 21 | ||||
-rw-r--r-- | sample/test.rb | 97 | ||||
-rw-r--r-- | sample/trojan.rb | 3 | ||||
-rw-r--r-- | sample/uumerge.rb | 4 |
15 files changed, 344 insertions, 102 deletions
diff --git a/sample/README b/sample/README new file mode 100644 index 0000000000..1bdc85f32b --- /dev/null +++ b/sample/README @@ -0,0 +1,56 @@ +README this file +biorhythm.rb biorhythm calculator +cal.rb cal(1) clone +cbreak.rb no echo done by ioctl +clnt.rb socket client +dbmtest.rb test for dbm +dir.rb directory access +dualstack-fetch.rb IPv6 demo +dualstack-httpd.rb IPv6 demo +dstore.rb object database on dbm +eval.rb simple evaluator +export.rb method access example +exyacc.rb extrace BNF from yacc file +fact.rb factorial calculator +fib.awk Fibonacci number (AWK) +fib.pl Fibonacci number (Perl) +fib.py Fibonacci number (Python) +fib.rb Fibonacci number (Ruby) +fib.scm Fibonacci number (Scheme) +freq.rb count word occurrence +from.rb scan mail spool +fullpath.rb convert ls -lR to fullpath format +getopts.test test fot getopt.rb +goodfriday.rb print various christian calendar event. +inf-ruby.el program to run ruby under emacs +io.rb io test +less.rb front end for less +list.rb stupid object sample +list2.rb stupid object sample +list3.rb stupid object sample +mine.rb simple mine sweeper +mkproto.rb extract protptype from C +mpart.rb split file int multi part +mrshtest.rb test marshal +observ.rb observer design pattern sample +occur.pl count word occurrence (Perl) +occur.rb count word occurrence (Ruby) +occur2.rb count word occurrence - another style +philos.rb famous dining philosophers +pi.rb calculate PI +rbc.rb interactive ruby, to be removed by irb +rcs.awk random character stereogram (AWK) +rcs.rb random character stereogram (Ruby) +rcs.dat data for random character stereogram +rd2html.rb rd (Ruby Document) to HTML translator +regx.rb regular expression tester +ruby-mode.el ruby mode for emacs +rubydb2x.el ruby debugger support for emacs 19.2x or before +rubydb3x.el ruby debugger support for emacs 19.3x or later +sieve.rb sieve of Eratosthenes +svr.rb socket server +test.rb test suite used by `make test' +time.rb /usr/bin/time clone +trojan.rb simple tool to find file that may be trojan horse. +tsvr.rb socket server using thread +uumerge.rb merge files and uudecode them diff --git a/sample/biorhythm.rb b/sample/biorhythm.rb index 50ad1f2ef7..d2cbb113ec 100644 --- a/sample/biorhythm.rb +++ b/sample/biorhythm.rb @@ -19,11 +19,11 @@ def usage() print "Usage:\n" print "biorhythm.rb [options]\n" print " options...\n" - print " -D YYYYMMDD(birthday) : ���٤� default �ͤ�Ȥ�. \n" - print " --sdate | --date YYYYMMDD : system date �⤷���ϻ��ꤷ�����դ�Ȥ�.\n" - print " --birthday YYYYMMDD : �������λ����. \n" - print " -v | -g : Values or Graph �λ���. \n" - print " --days DAYS : ���֤λ����(Graph �λ��Τ�ͭ��). \n" + print " -D YYYYMMDD(birthday) : use default values.\n" + print " --sdate | --date YYYYMMDD : use system date; use specified date.\n" + print " --birthday YYYYMMDD : specifies your birthday.\n" + print " -v | -g : show values or graph.\n" + print " --days DAYS : graph range (only in effect for graphs).\n" print " --help : help\n" end $USAGE = 'usage' diff --git a/sample/cal.rb b/sample/cal.rb new file mode 100644 index 0000000000..cf82c6421c --- /dev/null +++ b/sample/cal.rb @@ -0,0 +1,119 @@ +#! /usr/local/bin/ruby + +# cal.rb: Written by Tadayoshi Funaba 1998, 1999 +# $Id: cal.rb,v 1.5 1999/08/04 14:54:18 tadf Exp $ + +require 'date2' + +$tab = +{ + 'cn' => true, # China + 'de' => 2342032, # Germany (protestant states) + 'dk' => 2342032, # Denmark + 'es' => 2299161, # Spain + 'fi' => 2361390, # Finland + 'fr' => 2299227, # France + 'gb' => 2361222, # United Kingdom + 'gr' => 2423868, # Greece + 'hu' => 2301004, # Hungary + 'it' => 2299161, # Italy + 'jp' => true, # Japan + 'no' => 2342032, # Norway + 'pl' => 2299161, # Poland + 'pt' => 2299161, # Portugal + 'ru' => 2421639, # Russia + 'se' => 2361390, # Sweden + 'us' => 2361222, # United States + 'os' => false, # (old style) + 'ns' => true # (new style) +} + +$cc = 'gb' + +def usage + $stderr.puts 'usage: cal [-c iso3166] [-jy] [[month] year]' + exit 1 +end + +def cal(m, y, sg) + for d in 1..31 + break if jd = Date.exist?(y, m, d, sg) + end + fst = cur = Date.new(jd, sg) + ti = Date::MONTHNAMES[m] + ti << ' ' << y.to_s unless $yr + mo = ti.center((($w + 1) * 7) - 1) << "\n" + mo << ['S', 'M', 'Tu', 'W', 'Th', 'F', 'S']. + collect{|x| x.rjust($w)}.join(' ') << "\n" + mo << ' ' * (($w + 1) * fst.wday) + while cur.mon == fst.mon + mo << (if $jd then cur.yday else cur.mday end).to_s.rjust($w) + mo << (if (cur += 1).wday != 0 then "\s" else "\n" end) + end + mo << "\n" * (6 - ((fst.wday + (cur - fst)) / 7)) + mo +end + +def zip(xs) + yr = '' + until xs.empty? + ln = (if $jd then l, r, *xs = xs; [l, r] + else l, c, r, *xs = xs; [l, c, r] end). + collect{|x| x.split(/\n/no, -1)} + 8.times do + yr << ln.collect{|x| + x.shift.ljust((($w + 1) * 7) - 1)}.join(' ') << "\n" + end + end + yr +end + +while /^-([^-].*)$/no =~ $*[0] + a = $1 + if /^c(.+)?$/no =~ a + if $1 + $cc = $1.downcase + elsif $*.length >= 2 + $cc = $*[1].downcase + $*.shift + else + usage + end + else + a.scan(/./no) do |c| + case c + when 'j'; $jd = true + when 'y'; $yr = true + else usage + end + end + end + $*.shift +end +$*.shift if /^--/no =~ $*[0] +usage if (sg = $tab[$cc]).nil? +case $*.length +when 0 + td = Date.today + m = td.mon + y = td.year +when 1 + y = $*[0].to_i + $yr = true +when 2 + m = $*[0].to_i + y = $*[1].to_i +else + usage +end +usage unless m.nil? or (1..12) === m +usage unless y >= -4712 +$w = if $jd then 3 else 2 end +unless $yr + print cal(m, y, sg) +else + print y.to_s.center(((($w + 1) * 7) - 1) * + (if $jd then 2 else 3 end) + + (if $jd then 2 else 4 end)), "\n\n", + zip((1..12).collect{|m| cal(m, y, sg)}), "\n" +end diff --git a/sample/fib.py b/sample/fib.py new file mode 100644 index 0000000000..8318021d24 --- /dev/null +++ b/sample/fib.py @@ -0,0 +1,10 @@ +# calculate Fibonacci(20) +# for benchmark +def fib(n): + if n<2: + return n + else: + return fib(n-2)+fib(n-1) + +print fib(20) + diff --git a/sample/from.rb b/sample/from.rb index 93b6c4bade..bed3433f1e 100644 --- a/sample/from.rb +++ b/sample/from.rb @@ -17,6 +17,7 @@ class String len += 1 me = self[0, len].ljust(len) if me =~ /.$/ and $&.size == 2 + me[-2..-1] = ' ' me[-2, 2] = ' ' end me.chop! diff --git a/sample/goodfriday.rb b/sample/goodfriday.rb new file mode 100644 index 0000000000..cc541af3f3 --- /dev/null +++ b/sample/goodfriday.rb @@ -0,0 +1,35 @@ +#! /usr/local/bin/ruby + +# goodfriday.rb: Written by Tadayoshi Funaba 1998 +# $Id: goodfriday.rb,v 1.3 1999/08/04 14:54:18 tadf Exp $ + +require 'date2' +require 'holiday' + +es = Date.easter(Date.today.year) +[[-9*7, 'Septuagesima Sunday'], + [-8*7, 'Sexagesima Sunday'], + [-7*7, 'Quinquagesima Sunday (Shrove Sunday)'], + [-48, 'Shrove Monday'], + [-47, 'Shrove Tuesday'], + [-46, 'Ash Wednesday'], + [-6*7, 'Quadragesima Sunday'], + [-3*7, 'Mothering Sunday'], + [-2*7, 'Passion Sunday'], + [-7, 'Palm Sunday'], + [-3, 'Maunday Thursday'], + [-2, 'Good Friday'], + [-1, 'Easter Eve'], + [0, 'Easter Day'], + [1, 'Easter Monday'], + [7, 'Low Sunday'], + [5*7, 'Rogation Sunday'], + [39, 'Ascension Day (Holy Thursday)'], + [42, 'Sunday after Ascension Day'], + [7*7, 'Pentecost (Whitsunday)'], + [50, 'Whitmonday'], + [8*7, 'Trinity Sunday'], + [60, 'Corpus Christi (Thursday after Trinity)']]. +each do |xs| + puts ((es + xs.shift).to_s + ' ' + xs.shift) +end diff --git a/sample/list.rb b/sample/list.rb index 76035e67d6..221f7edb16 100644 --- a/sample/list.rb +++ b/sample/list.rb @@ -1,8 +1,8 @@ # Linked list example class MyElem - # ���֥��������������˼�ưŪ�˸ƤФ���å� + # object initializer called from Class#new def initialize(item) - # @�ѿ��ϥ������ѿ�(������פ�ʤ�) + # @variables are instance variable, no declaration needed @data = item @succ = nil end @@ -15,7 +15,7 @@ class MyElem @succ end - # ��obj.data = val�פȤ����Ȥ��˰��ۤ˸ƤФ���å� + # the method invoked by ``obj.data = val'' def succ=(new) @succ = new end @@ -40,12 +40,12 @@ class MyList end end - # ���֥������Ȥ�ʸ������Ѵ������å� - # ��������������print�Ǥ�ɽ�����Ѥ�� + # the method to convert object into string. + # redefining this will affect print. def to_s str = "<MyList:\n"; for elt in self - # ��str = str + elt.data.to_s + "\n"�פξ�ά�� + # short form of ``str = str + elt.data.to_s + "\n"'' str += elt.data.to_s + "\n" end str += ">" @@ -64,7 +64,7 @@ class Point end end -# ����ѿ���`$'�ǻϤޤ롥 +# global variable name starts with `$'. $list1 = MyList.new $list1.add_to_list(10) $list1.add_to_list(20) @@ -75,6 +75,6 @@ $list2.add_to_list(20) $list2.add_to_list(Point.new(4, 5)) $list2.add_to_list($list1) -# ۣ��Ǥʤ��¤��åɸƤӽФ��γ�̤Ͼ�ά�Ǥ��� +# parenthesises around method arguments can be ommitted unless ambiguous. print "list1:\n", $list1, "\n" print "list2:\n", $list2, "\n" diff --git a/sample/mine.rb b/sample/mine.rb index b9557d54a2..fd326482a5 100644 --- a/sample/mine.rb +++ b/sample/mine.rb @@ -10,19 +10,19 @@ class Board end def put(x, y, col, str) pos(x,y); colorstr(43,str) - pos(0,@hi); print "$B;D$j(B:",@mc,"/",@total," " + pos(0,@hi); print "�Ĥ�:",@mc,"/",@total," " pos(x,y) end private :clr, :pos, :colorstr, :put - CHR=["$B!&(B","$B#1(B","$B#2(B","$B#3(B","$B#4(B","$B#5(B","$B#6(B","$B#7(B","$B#8(B","$B!z(B","$B!|(B","@@"] + CHR=["��","��","��","��","��","��","��","��","��","��","��","@@"] COL=[46,43,45] # default,opened,over def initialize(h,w,m) - # $B%2!<%`HW$N@8@.(B(h:$B=D!$(Bw:$B2#!$(Bm:$BGzCF$N?t(B) + # �������פ�����(h:�ġ�w:����m:���Ƥο�) @hi=h; @wi=w; @m=m reset end def reset - # $B%2!<%`HW$r(B($B:F(B)$B=i4|2=$9$k(B + # �������פ�(��)��������� srand() @cx=0; @cy=0; @mc=@m @over=false @@ -44,7 +44,7 @@ class Board pos(@cx,@cy) end def mark - # $B8=:_$N%+!<%=%k0LCV$K%^!<%/$r$D$1$k(B + # ���ߤΥ���������֤˥ޡ�����Ĥ��� if @state[@wi*@cy+@cx] != nil then return end @state[@wi*@cy+@cx] = "MARK" @mc=@mc-1; @@ -52,8 +52,8 @@ class Board put(@cx, @cy, COL[1], CHR[9]) end def open(x=@cx,y=@cy) - # $B8=:_$N%+!<%=%k0LCV$r%*!<%W%s$K$9$k(B - # $BGzCF$,$"$l$P%2!<%`%*!<%P!<(B + # ���ߤΥ���������֤��ץ�ˤ��� + # ���Ƥ�����Х����४���С� if @state[@wi*y+x] =="OPEN" then return 0 end if @state[@wi*y+x] == nil then @total=@total-1 end if @state[@wi*y+x] =="MARK" then @mc=@mc+1 end @@ -73,7 +73,7 @@ class Board pos(@cx,@cy) end def fetch(x,y) - # (x,y)$B$N0LCV$NGzCF$N?t(B(0 or 1)$B$rJV$9(B + # (x,y)�ΰ��֤����Ƥο�(0 or 1)���֤� if x < 0 then 0 elsif x >= @wi then 0 elsif y < 0 then 0 @@ -83,13 +83,13 @@ class Board end end def count(x,y) - # (x,y)$B$KNY@\$9$kGzCF$N?t$rJV$9(B + # (x,y)�����ܤ������Ƥο����֤� fetch(x-1,y-1)+fetch(x,y-1)+fetch(x+1,y-1)+ fetch(x-1,y) + fetch(x+1,y)+ fetch(x-1,y+1)+fetch(x,y+1)+fetch(x+1,y+1) end def over(win) - # $B%2!<%`$N=*N;(B + # ������ν�λ quit unless win pos(@cx,@cy); print CHR[11] @@ -100,8 +100,8 @@ class Board end end def over? - # $B%2!<%`$N=*N;%A%'%C%/(B - # $B=*N;=hM}$b8F$S=P$9(B + # ������ν�λ�����å� + # ��λ������ƤӽФ� remain = (@mc+@total == 0) if @over || remain over(remain) @@ -111,8 +111,8 @@ class Board end end def quit - # $B%2!<%`$NCfCG(B($B$^$?$O=*N;(B) - # $BHWLL$rA4$F8+$;$k(B + # �����������(�ޤ��Ͻ�λ) + # ���̤����Ƹ����� @hi.times do|y| pos(0,y) @wi.times do|x| @@ -122,19 +122,19 @@ class Board end end def down - # $B%+!<%=%k$r2<$K(B + # ��������� if @cy < @hi-1 then @cy=@cy+1; pos(@cx, @cy) end end def up - # $B%+!<%=%k$r>e$K(B + # ����������� if @cy > 0 then @cy=@cy-1; pos(@cx, @cy) end end def left - # $B%+!<%=%k$r:8$K(B + # ��������� if @cx > 0 then @cx=@cx-1; pos(@cx, @cy) end end def right - # $B%+!<%=%k$r1&$K(B + # ��������� if @cx < @wi-1 then @cx=@cx+1; pos(@cx, @cy) end end end @@ -143,7 +143,7 @@ bd=Board.new(10,10,10) system("stty raw -echo") begin loop do - case getc + case STDIN.getc when ?n # new game bd.reset when ?m # mark @@ -163,11 +163,11 @@ begin break end if bd.over? - if getc == ?q then break end + if STDIN.getc == ?q then break end bd.reset end end ensure - system("stty -raw echo") + system("stty -raw echo") end print "\n" diff --git a/sample/rbc.rb b/sample/rbc.rb index 83796255cc..9f1ab9443d 100644 --- a/sample/rbc.rb +++ b/sample/rbc.rb @@ -273,7 +273,7 @@ module BC_APPLICATION__ rests.unshift op identify_number(rests) else - # obj.if �ʤɤ��б� + # handle ``obj.if'' and such identify_identifier(rests, TRUE) @lex_state = EXPR_ARG end @@ -344,7 +344,7 @@ module BC_APPLICATION__ @lex_state = EXPR_BEG end end - @OP.def_rule('$') do + @OP.def_rule('$') do #' |op, rests| identify_gvar(rests) end @@ -466,7 +466,7 @@ module BC_APPLICATION__ print token, "\n" if CONFIG[:DEBUG] if state = CLAUSE_STATE_TRANS[token] if @lex_state != EXPR_BEG and token =~ /^(if|unless|while|until)/ - # ������ + # modifiers else if ENINDENT_CLAUSE.include?(token) @indent += 1 @@ -640,7 +640,7 @@ module BC_APPLICATION__ def_exception :ErrNodeAlreadyExists, "node already exists" class Node - # postproc���ʤ������ݥΡ���, nil����ʤ���ж�ݥΡ��� + # abstract node if postproc is nil. def initialize(preproc = nil, postproc = nil) @Tree = {} @preproc = preproc diff --git a/sample/rcs.rb b/sample/rcs.rb index 3f74da9ef2..7c091936f3 100644 --- a/sample/rcs.rb +++ b/sample/rcs.rb @@ -1,12 +1,12 @@ # random dot steraogram # usage: rcs.rb rcs.dat -sw = 40.0 # ���̃p�^�[���̕� -dw = 78.0 # ��������� Random Character Streogram �̕� +sw = 40.0 # width of original pattern +dw = 78.0 # width of generating Random Character Streogram hdw = dw / 2.0 -w = 20.0 # ����̕� -h =1.0 # ��ʂƊ�ʂ̋��� -d = 0.2 # �P�ʓ�����̕����オ��� +w = 20.0 # distance between eyes +h =1.0 # distance from screen and base plane +d = 0.2 # z value unit ss="abcdefghijklmnopqrstuvwxyz0123456789#!$%^&*()-=\\[];'`,./" rnd = srand() diff --git a/sample/rename.rb b/sample/rename.rb index 9abea7e327..cacb2b7508 100644 --- a/sample/rename.rb +++ b/sample/rename.rb @@ -140,8 +140,8 @@ gsub!(/\beof_error\b/,"rb_eof_error") gsub!(/\bf_gets\b/,"rb_f_gets") gsub!(/\bio_binmode\b/,"rb_io_binmode") gsub!(/\bio_check_closed\b/,"rb_io_check_closed") -gsub!(/\bio_check_readable\b/,"rb_io_check_readable") -gsub!(/\bio_check_writable\b/,"rb_io_check_writable") +gsub!(/\bio_readable\b/,"rb_io_check_readable") +gsub!(/\bio_writable\b/,"rb_io_check_writable") gsub!(/\bio_close\b/,"rb_io_close") gsub!(/\bio_fptr_finalize\b/,"rb_io_fptr_finalize") gsub!(/\bio_getc\b/,"rb_io_getc") @@ -248,8 +248,8 @@ gsub!(/\bstr_plus\b/,"rb_str_plus") gsub!(/\bstr_resize\b/,"rb_str_resize") gsub!(/\bstr_split\b/,"rb_str_split") gsub!(/\bstr_substr\b/,"rb_str_substr") -gsub!(/\bstr_taint\b/,"rb_str_taint") -gsub!(/\bstr_tainted\b/,"rb_str_tainted") +gsub!(/\bstr_taint\b/,"rb_obj_taint") +gsub!(/\bstr_tainted\b/,"rb_obj_tainted") gsub!(/\bstr_times\b/,"rb_str_times") gsub!(/\bstr_to_str\b/,"rb_str_to_str") gsub!(/\bstr_upto\b/,"rb_str_upto") @@ -283,8 +283,8 @@ gsub!(/\bobj_instance_variables\b/,"rb_obj_instance_variables") gsub!(/\bobj_remove_instance_variable\b/,"rb_obj_remove_instance_variable") gsub!(/\bshow_copyright\b/,"ruby_show_copyright") gsub!(/\bshow_version\b/,"ruby_show_version") -gsub!(/\bdebug\b/,"rb_debug") -gsub!(/\bverbose\b/,"rb_verbose") +gsub!(/\bdebug\b/,"ruby_debug") +gsub!(/\bverbose\b/,"ruby_verbose") gsub!(/\bFail\(/,"rb_raise(rb_eRuntimeError, ") gsub!(/\bArgError\(/,"rb_raise(rb_eArgError, ") gsub!(/\bTypeError\(/,"rb_raise(rb_eTypeError, ") @@ -294,4 +294,4 @@ gsub!(/\bError\b/,"rb_compile_error") gsub!(/\bErrorAppend\b/,"rb_compile_error_append") gsub!(/\bTRUE\b/,"Qtrue") gsub!(/\bFALSE\b/,"Qfalse") -gsub!(/\berrinfo\b/,"rb_errinfo") +gsub!(/\berrinfo\b/,"ruby_errinfo") diff --git a/sample/sieve.rb b/sample/sieve.rb index 5e9f792d81..359c185f20 100644 --- a/sample/sieve.rb +++ b/sample/sieve.rb @@ -1,17 +1,14 @@ # sieve of Eratosthenes -sieve = [] max = Integer(ARGV.shift || 100) +sieve = [] +for i in 2 .. max + sieve[i] = i +end -print "1" -for i in 2 .. max - begin - for d in sieve - fail if i % d == 0 - end - print ", " - print i - sieve.push(i) - rescue +for i in 2 .. Math.sqrt(max) + next unless sieve[i] + (i*i).step(max, i) do |j| + sieve[j] = nil end end -print "\n" +puts sieve.compact.join ", " diff --git a/sample/test.rb b/sample/test.rb index f28327659e..a849a42fc2 100644 --- a/sample/test.rb +++ b/sample/test.rb @@ -183,7 +183,7 @@ ok(i>4) check "exception"; begin - fail "this must be handled" + raise "this must be handled" ok(false) rescue ok(true) @@ -191,7 +191,7 @@ end $bad = true begin - fail "this must be handled no.2" + raise "this must be handled no.2" rescue if $bad $bad = false @@ -205,9 +205,9 @@ ok(true) $string = "this must be handled no.3" begin begin - fail "exception in rescue clause" + raise "exception in rescue clause" rescue - fail $string + raise $string end ok(false) rescue @@ -217,9 +217,9 @@ end # exception in ensure clause begin begin - fail "this must be handled no.4" + raise "this must be handled no.4" ensure - fail "exception in ensure clause" + raise "exception in ensure clause" end ok(false) rescue @@ -229,7 +229,7 @@ end $bad = true begin begin - fail "this must be handled no.5" + raise "this must be handled no.5" ensure $bad = false end @@ -240,7 +240,7 @@ ok(!$bad) $bad = true begin begin - fail "this must be handled no.6" + raise "this must be handled no.6" ensure $bad = false end @@ -355,7 +355,7 @@ ok($x[1] == 2) ok(begin for k,v in $y - fail if k*2 != v + raise if k*2 != v end true rescue @@ -417,7 +417,7 @@ ok(i == 5) done = true loop{ break - done = false + done = false # should not reach here } ok(done) @@ -427,7 +427,7 @@ loop { break if done done = true next - $bad = true + $bad = true # should not reach here } ok(!$bad) @@ -437,7 +437,7 @@ loop { break if done done = true redo - $bad = true + $bad = true # should not reach here } ok(!$bad) @@ -599,14 +599,29 @@ ok(("abc" =~ /d*$/) == 3) ok("" =~ /^$/) ok("\n" =~ /^$/) ok("a\n\n" =~ /^$/) -"abcabc" =~ /.*a/ -ok($& == "abca") -"abcabc" =~ /.*c/ -ok($& == "abcabc") -"abcabc" =~ /.*?a/ -ok($& == "a") -"abcabc" =~ /.*?c/ -ok($& == "abc") +ok("abcabc" =~ /.*a/ && $& == "abca") +ok("abcabc" =~ /.*c/ && $& == "abcabc") +ok("abcabc" =~ /.*?a/ && $& == "a") +ok("abcabc" =~ /.*?c/ && $& == "abc") +ok(/(.|\n)*?\n(b|\n)/ =~ "a\nb\n\n" && $& == "a\nb") +$x = <<END; +ABCD +ABCD +END + +ok(/^(ab+)+b/ =~ "ababb" && $& == "ababb") +ok(/^(?:ab+)+b/ =~ "ababb" && $& == "ababb") +ok(/^(ab+)+/ =~ "ababb" && $& == "ababb") +ok(/^(?:ab+)+/ =~ "ababb" && $& == "ababb") + +ok(/(\s+\d+){2}/ =~ " 1 2" && $& == " 1 2") +ok(/(?:\s+\d+){2}/ =~ " 1 2" && $& == " 1 2") + +$x.gsub!(/((.|\n)*?)B((.|\n)*?)D/){$1+$3} +ok($x == "AC\nAC\n") + +ok("foobar" =~ /foo(?=(bar)|(baz))/) +ok("foobaz" =~ /foo(?=(bar)|(baz))/) $foo = "abc" ok("#$foo = abc" == "abc = abc") @@ -746,7 +761,7 @@ if defined? Process.kill sleep 0.1 ok($x == 2) - trap "SIGINT", proc{fail "Interrupt"} + trap "SIGINT", proc{raise "Interrupt"} x = false begin @@ -841,47 +856,55 @@ $x = [] x = proc{binding}.call eval "(0..9).each{|i5| $x[i5] = proc{i5*2}}", x ok($x[4].call == 8) +x = proc{binding}.call +eval "for i6 in 1..1; j6=i6; end", x +ok(eval("defined? i6", x)) +ok(eval("defined? j6", x)) proc { p = binding eval "foo11 = 1", p + foo22 = 5 proc{foo11=22}.call + proc{foo22=55}.call ok(eval("foo11", p) == eval("foo11")) ok(eval("foo11") == 1) + ok(eval("foo22", p) == eval("foo22")) + ok(eval("foo22") == 55) }.call -p1 = proc{i6 = 0; proc{i6}}.call +p1 = proc{i7 = 0; proc{i7}}.call ok(p1.call == 0) -eval "i6=5", p1 +eval "i7=5", p1 ok(p1.call == 5) -ok(!defined?(i6)) +ok(!defined?(i7)) -p1 = proc{i6 = 0; proc{i6}}.call -i6 = nil +p1 = proc{i7 = 0; proc{i7}}.call +i7 = nil ok(p1.call == 0) -eval "i6=1", p1 +eval "i7=1", p1 ok(p1.call == 1) -eval "i6=5", p1 +eval "i7=5", p1 ok(p1.call == 5) -ok(i6 == nil) +ok(i7 == nil) check "system" ok(`echo foobar` == "foobar\n") -ok(`./ruby -e 'print "foobar"'` == 'foobar') +ok(`./miniruby -e 'print "foobar"'` == 'foobar') tmp = open("script_tmp", "w") tmp.print "print $zzz\n"; tmp.close -ok(`./ruby -s script_tmp -zzz` == 'true') -ok(`./ruby -s script_tmp -zzz=555` == '555') +ok(`./miniruby -s script_tmp -zzz` == 'true') +ok(`./miniruby -s script_tmp -zzz=555` == '555') tmp = open("script_tmp", "w") tmp.print "#! /usr/local/bin/ruby -s\n"; tmp.print "print $zzz\n"; tmp.close -ok(`./ruby script_tmp -zzz=678` == '678') +ok(`./miniruby script_tmp -zzz=678` == '678') tmp = open("script_tmp", "w") tmp.print "this is a leading junk\n"; @@ -891,8 +914,8 @@ tmp.print "__END__\n"; tmp.print "this is a trailing junk\n"; tmp.close -ok(`./ruby -x script_tmp` == 'nil') -ok(`./ruby -x script_tmp -zzz=555` == '555') +ok(`./miniruby -x script_tmp` == 'nil') +ok(`./miniruby -x script_tmp -zzz=555` == '555') tmp = open("script_tmp", "w") for i in 1..5 @@ -900,7 +923,7 @@ for i in 1..5 end tmp.close -`./ruby -i.bak -pe 'sub(/^[0-9]+$/){$&.to_i * 5}' script_tmp` +`./miniruby -i.bak -pe 'sub(/^[0-9]+$/){$&.to_i * 5}' script_tmp` done = true tmp = open("script_tmp", "r") while tmp.gets @@ -917,7 +940,7 @@ File.unlink "script_tmp.bak" or `/bin/rm -f "script_tmp.bak"` $bad = false for script in Dir["{lib,sample}/*.rb"] - unless `./ruby -c #{script}`.chomp == "Syntax OK" + unless `./miniruby -c #{script}`.chomp == "Syntax OK" $bad = true end end diff --git a/sample/trojan.rb b/sample/trojan.rb index edf8ee63ce..6e9b18f502 100644 --- a/sample/trojan.rb +++ b/sample/trojan.rb @@ -1,5 +1,6 @@ #! /usr/local/bin/ruby -path = ENV['PATH'].split(/:/) + +path = ENV['PATH'].split(File::PATH_SEPARATOR) for dir in path if File.directory?(dir) diff --git a/sample/uumerge.rb b/sample/uumerge.rb index 26f28923d5..418323c439 100644 --- a/sample/uumerge.rb +++ b/sample/uumerge.rb @@ -1,4 +1,4 @@ -#!/usr/local/bin/ruby +#!/usr/bin/env ruby if ARGV[0] == "-c" out_stdout = 1 @@ -18,7 +18,7 @@ while gets() out = open($file, "w") if $file != "" end out.binmode - next + break end end |