~ubuntu-branches/ubuntu/quantal/ruby1.9.1/quantal

« back to all changes in this revision

Viewing changes to sample/test.rb

  • Committer: Bazaar Package Importer
  • Author(s): Lucas Nussbaum
  • Date: 2011-09-24 19:16:17 UTC
  • mfrom: (1.1.8 upstream) (13.1.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20110924191617-o1qz4rcmqjot8zuy
Tags: 1.9.3~rc1-1
* New upstream release: 1.9.3 RC1.
  + Includes load.c fixes. Closes: #639959.
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
  else
22
22
    STDERR.print "F"
23
23
    printf "not ok %s %d -- %s\n", $what, $testnum, where
24
 
    $failed+=1 
 
24
    $failed+=1
25
25
  end
26
26
  STDOUT.flush
27
27
  STDERR.flush
657
657
begin
658
658
  begin
659
659
    raise "exception in rescue clause"
660
 
  rescue 
 
660
  rescue
661
661
    raise $string
662
662
  end
663
663
  test_ok(false)
671
671
begin
672
672
  begin
673
673
    raise "this must be handled no.4"
674
 
  ensure 
 
674
  ensure
675
675
    raise "exception in ensure clause"
676
676
  end
677
677
  test_ok(false)
741
741
 
742
742
$x[0, 2] = 10
743
743
test_ok($x[0] == 10 && $x[1] == 2)
744
 
  
 
744
 
745
745
$x[0, 0] = -1
746
746
test_ok($x[0] == -1 && $x[1] == 10)
747
747
 
817
817
 
818
818
test_ok($x[1] == 2)
819
819
 
820
 
test_ok(begin   
 
820
test_ok(begin
821
821
     for k,v in $x
822
822
       raise if k*2 != v
823
823
     end
1164
1164
end
1165
1165
test_ok(proc_return4() == 42)
1166
1166
 
1167
 
def ljump_test(state, proc, *args) 
 
1167
def ljump_test(state, proc, *args)
1168
1168
  x = state
1169
1169
  begin
1170
1170
    proc.call(*args)
1362
1362
  end
1363
1363
end
1364
1364
 
1365
 
ITER_TEST4.new.foo(44){55}   
 
1365
ITER_TEST4.new.foo(44){55}
1366
1366
 
1367
1367
class ITER_TEST5
1368
1368
   def tt(aa)
1628
1628
 
1629
1629
a = []
1630
1630
(0..255).each {|n|
1631
 
  ch = [n].pack("C")                     
1632
 
  a.push ch if /a#{Regexp.quote ch}b/x =~ "ab" 
 
1631
  ch = [n].pack("C")
 
1632
  a.push ch if /a#{Regexp.quote ch}b/x =~ "ab"
1633
1633
}
1634
1634
test_ok(a.size == 0)
1635
1635
 
1921
1921
File.unlink "script_tmp" or `/bin/rm -f "script_tmp"`
1922
1922
File.unlink "script_tmp.bak" or `/bin/rm -f "script_tmp.bak"`
1923
1923
 
1924
 
$bad = false
1925
 
if (dir = File.dirname(File.dirname(__FILE__))) == '.'
1926
 
  dir = ""
1927
 
else
1928
 
  dir << "/"
1929
 
end
1930
 
 
1931
 
def valid_syntax?(code, fname)
1932
 
  p fname
1933
 
  code = code.dup.force_encoding("ascii-8bit")
1934
 
  code.sub!(/\A(?:\xef\xbb\xbf)?(\s*\#.*$)*(\n)?/n) {
1935
 
    "#$&#{"\n" if $1 && !$2}BEGIN{throw tag, :ok}\n"
1936
 
  }
1937
 
  code.force_encoding("us-ascii")
1938
 
  catch {|tag| eval(code, binding, fname, 0)}
1939
 
rescue Exception
1940
 
  STDERR.puts $!.message
1941
 
  false
1942
 
end
1943
 
 
1944
 
for script in Dir["#{dir}{lib,sample,ext,test}/**/*.rb"].sort
1945
 
  unless valid_syntax? IO::read(script), script
1946
 
    STDERR.puts script
1947
 
    $bad = true
1948
 
  end
1949
 
end
1950
 
test_ok(!$bad)
1951
 
 
1952
1924
test_check "const"
1953
1925
TEST1 = 1
1954
1926
TEST2 = 2
1988
1960
 
1989
1961
test_ok(bar.test2 == "test2")
1990
1962
test_ok(bar.test == "test")
1991
 
test_ok(foo.test == "test")  
 
1963
test_ok(foo.test == "test")
1992
1964
 
1993
1965
begin
1994
1966
  foo.test2
2082
2054
 
2083
2055
  def self.ruler1               # <= per method definition style
2084
2056
    @@rule
2085
 
  end              
 
2057
  end
2086
2058
  class << self                 # <= multiple method definition style
2087
2059
    def ruler2
2088
2060
      @@rule