1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* bootstraptest/runner.rb: fix to show file name.

* bootstraptest/test_*.rb: add bootstarp tests.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12639 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ko1 2007-06-27 16:26:31 +00:00
parent fd78c2193e
commit caa535286d
10 changed files with 2579 additions and 0 deletions

View file

@ -1,3 +1,9 @@
Thu Jun 28 01:24:02 2007 Koichi Sasada <ko1@atdot.net>
* bootstraptest/runner.rb: fix to show file name.
* bootstraptest/test_*.rb: add bootstarp tests.
Thu Jun 28 01:22:15 2007 Koichi Sasada <ko1@atdot.net>
* include/ruby/node.h, parse.y, gc.c, iseq.c: remove NODE_CREF.

View file

@ -66,6 +66,8 @@ def exec_test(pathes)
@errbuf = []
@location = nil
pathes.each do |path|
puts
puts File.basename(path)
load File.expand_path(path)
end
$stderr.puts

337
bootstraptest/test_block.rb Normal file
View file

@ -0,0 +1,337 @@
assert_equal %q{1}, %q{
1.times{
begin
a = 1
ensure
foo = nil
end
}
}
assert_equal %q{2}, %q{
[1,2,3].find{|x| x == 2}
}
assert_equal %q{2}, %q{
class E
include Enumerable
def each(&block)
[1, 2, 3].each(&block)
end
end
E.new.find {|x| x == 2 }
}
assert_equal %q{6}, %q{
sum = 0
for x in [1, 2, 3]
sum += x
end
sum
}
assert_equal %q{15}, %q{
sum = 0
for x in (1..5)
sum += x
end
sum
}
assert_equal %q{0}, %q{
sum = 0
for x in []
sum += x
end
sum
}
assert_equal %q{1}, %q{
ans = []
1.times{
for n in 1..3
a = n
ans << a
end
}
}
assert_equal %q{1..3}, %q{
ans = []
for m in 1..3
for n in 1..3
a = [m, n]
ans << a
end
end
}
assert_equal %q{[1, 2, 3]}, %q{
(1..3).to_a
}
assert_equal %q{[4, 8, 12]}, %q{
(1..3).map{|e|
e * 4
}
}
assert_equal %q{[1, 2, 3]}, %q{
class C
include Enumerable
def each
[1,2,3].each{|e|
yield e
}
end
end
C.new.to_a
}
assert_equal %q{[4, 5, 6]}, %q{
class C
include Enumerable
def each
[1,2,3].each{|e|
yield e
}
end
end
C.new.map{|e|
e + 3
}
}
assert_equal %q{100}, %q{
def m
yield
end
def n
yield
end
m{
n{
100
}
}
}
assert_equal %q{20}, %q{
def m
yield 1
end
m{|ib|
m{|jb|
i = 20
}
}
}
assert_equal %q{2}, %q{
def m
yield 1
end
m{|ib|
m{|jb|
ib = 20
kb = 2
}
}
}
assert_equal %q{3}, %q{
def iter1
iter2{
yield
}
end
def iter2
yield
end
iter1{
jb = 2
iter1{
jb = 3
}
jb
}
}
assert_equal %q{2}, %q{
def iter1
iter2{
yield
}
end
def iter2
yield
end
iter1{
jb = 2
iter1{
jb
}
jb
}
}
assert_equal %q{2}, %q{
def m
yield 1
end
m{|ib|
ib*2
}
}
assert_equal %q{92580}, %q{
def m
yield 12345, 67890
end
m{|ib,jb|
ib*2+jb
}
}
assert_equal %q{[10, nil]}, %q{
def iter
yield 10
end
a = nil
[iter{|a|
a
}, a]
}
assert_equal %q{21}, %q{
def iter
yield 10
end
iter{|a|
iter{|a|
a + 1
} + a
}
}
assert_equal %q{[10, 20, 30, 40, nil, nil, nil, nil]}, %q{
def iter
yield 10, 20, 30, 40
end
a = b = c = d = nil
iter{|a, b, c, d|
[a, b, c, d]
} + [a, b, c, d]
}
assert_equal %q{[10, 20, 30, 40, nil, nil]}, %q{
def iter
yield 10, 20, 30, 40
end
a = b = nil
iter{|a, b, c, d|
[a, b, c, d]
} + [a, b]
}
assert_equal %q{[1]}, %q{
$a = []
def iter
yield 1
end
def m
x = iter{|x|
$a << x
y = 0
}
end
m
$a
}
assert_equal %q{[1, [2]]}, %q{
def iter
yield 1, 2
end
iter{|a, *b|
[a, b]
}
}
assert_equal %q{[[1, 2]]}, %q{
def iter
yield 1, 2
end
iter{|*a|
[a]
}
}
assert_equal %q{[1, 2, []]}, %q{
def iter
yield 1, 2
end
iter{|a, b, *c|
[a, b, c]
}
}
assert_equal %q{[1, 2, nil, []]}, %q{
def iter
yield 1, 2
end
iter{|a, b, c, *d|
[a, b, c, d]
}
}
assert_equal %q{1}, %q{
def m
yield
end
m{
1
}
}
assert_equal %q{15129}, %q{
def m
yield 123
end
m{|ib|
m{|jb|
ib*jb
}
}
}
assert_equal %q{2}, %q{
def m a
yield a
end
m(1){|ib|
m(2){|jb|
ib*jb
}
}
}
assert_equal %q{9}, %q{
sum = 0
3.times{|ib|
2.times{|jb|
sum += ib + jb
}}
sum
}
assert_equal %q{10}, %q{
3.times{|bl|
break 10
}
}
assert_equal %q{[1, 2]}, %q{
def iter
yield 1,2,3
end
iter{|i, j|
[i, j]
}
}
assert_equal %q{[1, nil]}, %q{
def iter
yield 1
end
iter{|i, j|
[i, j]
}
}

190
bootstraptest/test_eval.rb Normal file
View file

@ -0,0 +1,190 @@
assert_equal %q{ok}, %q{
def m
a = :ok
$b = binding
end
m
eval('a', $b)
}
assert_equal %q{[:ok, :ok2]}, %q{
def m
a = :ok
$b = binding
end
m
eval('b = :ok2', $b)
eval('[a, b]', $b)
}
assert_equal %q{[nil, 1]}, %q{
$ans = []
def m
$b = binding
end
m
$ans << eval(%q{
$ans << eval(%q{
a
}, $b)
a = 1
}, $b)
$ans
}
assert_equal %q{C}, %q{
Const = :top
class C
Const = :C
def m
binding
end
end
eval('Const', C.new.m)
}
assert_equal %q{top}, %q{
Const = :top
a = 1
class C
Const = :C
def m
eval('Const', TOPLEVEL_BINDING)
end
end
C.new.m
}
assert_equal %q{:ok
ok}, %q{
class C
$b = binding
end
eval %q{
def m
:ok
end
}, $b
p C.new.m
}
assert_equal %q{ok}, %q{
b = proc{
a = :ok
binding
}.call
a = :ng
eval("a", b)
}
assert_equal %q{C}, %q{
class C
def foo
binding
end
end
C.new.foo.eval("self.class.to_s")
}
assert_equal %q{1}, %q{
eval('1')
}
assert_equal %q{1}, %q{
eval('a=1; a')
}
assert_equal %q{1}, %q{
a = 1
eval('a')
}
assert_equal %q{ok}, %q{
__send! :eval, %{
:ok
}
}
assert_equal %q{ok}, %q{
1.__send! :instance_eval, %{
:ok
}
}
assert_equal %q{1}, %q{
1.instance_eval{
self
}
}
assert_equal %q{foo}, %q{
'foo'.instance_eval{
self
}
}
assert_equal %q{1}, %q{
class Fixnum
Const = 1
end
1.instance_eval %{
Const
}
}
assert_equal %q{C}, %q{
Const = :top
class C
Const = :C
end
C.module_eval{
Const
}
}
assert_equal %q{C}, %q{
Const = :top
class C
Const = :C
end
C.class_eval %{
def m
Const
end
}
C.new.m
}
assert_equal %q{C}, %q{
Const = :top
class C
Const = :C
end
C.class_eval{
def m
Const
end
}
C.new.m
}
assert_equal %q{[:top, :C, :top, :C]}, %q{
Const = :top
class C
Const = :C
end
$nest = false
$ans = []
def m
$ans << Const
C.module_eval %{
$ans << Const
Boo = false unless defined? Boo
unless $nest
$nest = true
m
end
}
end
m
$ans
}
assert_equal %q{[10, main]}, %q{
$nested = false
$ans = []
$pr = proc{
$ans << self
unless $nested
$nested = true
$pr.call
end
}
class C
def initialize &b
10.instance_eval(&b)
end
end
C.new(&$pr)
$ans
}

View file

@ -0,0 +1,370 @@
assert_equal %q{2}, %q{
begin
1+1
ensure
2+2
end
}
assert_equal %q{4}, %q{
begin
1+1
begin
2+2
ensure
3+3
end
ensure
4+4
end
}
assert_equal %q{4}, %q{
begin
1+1
begin
2+2
ensure
3+3
end
ensure
4+4
begin
5+5
ensure
6+6
end
end
}
assert_equal %q{NilClass}, %q{
a = nil
1.times{|e|
begin
rescue => err
end
a = err.class
}
a
}
assert_equal %q{RuntimeError}, %q{
a = nil
1.times{|e|
begin
raise
rescue => err
end
a = err.class
}
a
}
assert_equal %q{}, %q{
$!
}
assert_equal %q{FOO}, %q{
begin
raise "FOO"
rescue
$!
end
}
assert_equal %q{FOO}, %q{
def m
$!
end
begin
raise "FOO"
rescue
m()
end
}
assert_equal %q{[#<RuntimeError: BAR>, #<RuntimeError: FOO>]}, %q{
$ans = []
def m
$!
end
begin
raise "FOO"
rescue
begin
raise "BAR"
rescue
$ans << m()
end
$ans << m()
end
$ans
}
assert_equal %q{[#<RuntimeError: FOO>, #<RuntimeError: FOO>]}, %q{
$ans = []
def m
$!
end
begin
begin
raise "FOO"
ensure
$ans << m()
end
rescue
$ans << m()
end
}
assert_equal %q{[nil]}, %q{
$ans = []
def m
$!
end
def m2
1.times{
begin
return
ensure
$ans << m
end
}
end
m2
$ans
}
assert_equal %q{ok}, %q{
begin
raise
rescue
:ok
end
}
assert_equal %q{ok}, %q{
begin
raise
rescue
:ok
ensure
:ng
end
}
assert_equal %q{RuntimeError}, %q{
begin
raise
rescue => e
e.class
end
}
assert_equal %q{ng}, %q{
begin
raise
rescue StandardError
:ng
rescue Exception
:ok
end
}
assert_equal %q{c}, %q{
begin
begin
raise "a"
rescue
raise "b"
ensure
raise "c"
end
rescue => e
e.message
end
}
assert_equal %q{33}, %q{
def m a, b
a + b
end
m(1, begin
raise
rescue
2
end) +
m(10, begin
raise
rescue
20
ensure
30
end)
}
assert_equal %q{3}, %q{
def m a, b
a + b
end
m(begin
raise
rescue
1
end,
begin
raise
rescue
2
end)
}
assert_equal %q{ok3}, %q{
class E1 < Exception
end
def m
yield
end
begin
begin
begin
m{
raise
}
rescue E1
:ok2
ensure
end
rescue
:ok3
ensure
end
rescue E1
:ok
ensure
end
}
assert_equal %q{7}, %q{
$i = 0
def m
iter{
begin
$i += 1
begin
$i += 2
break
ensure
end
ensure
$i += 4
end
$i = 0
}
end
def iter
yield
end
m
$i
}
assert_equal %q{10}, %q{
$i = 0
def m
begin
$i += 1
begin
$i += 2
return
ensure
$i += 3
end
ensure
$i += 4
end
p :end
end
m
$i
}
assert_equal %q{1}, %q{
begin
1
rescue
2
end
}
assert_equal %q{4}, %q{
begin
1
begin
2
rescue
3
end
4
rescue
5
end
}
assert_equal %q{3}, %q{
begin
1
rescue
2
else
3
end
}
assert_equal %q{2}, %q{
begin
1+1
rescue
2+2
ensure
3+3
end
}
assert_equal %q{2}, %q{
begin
1+1
rescue
2+2
ensure
3+3
end
}
assert_equal %q{6}, %q{
begin
1+1
rescue
2+2
else
3+3
ensure
4+4
end
}
assert_equal %q{12}, %q{
begin
1+1
begin
2+2
rescue
3+3
else
4+4
end
rescue
5+5
else
6+6
ensure
7+7
end
}
assert_equal %q{ok}, %q{ #
proc{
begin
raise
break
rescue
:ok
end
}.call
}
assert_equal %q{}, %q{
proc do
begin
raise StandardError
redo
rescue StandardError
end
end.call
}

491
bootstraptest/test_flow.rb Normal file
View file

@ -0,0 +1,491 @@
assert_equal %q{[1, 2, 4, 5, 6, 7, 8]}, %q{$a = []; begin; ; $a << 1
[1,2].each{; $a << 2
break; $a << 3
}; $a << 4
begin; $a << 5
ensure; $a << 6
end; $a << 7
; $a << 8
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 2, 3, 5, 6, 7, 8]}, %q{$a = []; begin; ; $a << 1
begin; $a << 2
[1,2].each do; $a << 3
break; $a << 4
end; $a << 5
ensure; $a << 6
end; $a << 7
; $a << 8
; rescue Exception; $a << 99; end; $a}
assert_equal %q{ok}, %q{
["a"].inject("ng"){|x,y|
break :ok
}
}
assert_equal %q{ok}, %q{
unless ''.respond_to? :lines
class String
def lines
self
end
end
end
('a').lines.map{|e|
break :ok
}
}
assert_equal %q{[1, 2, 4, 5]}, %q{$a = []; begin; ; $a << 1
["a"].inject("ng"){|x,y|; $a << 2
break :ok; $a << 3
}; $a << 4
; $a << 5
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 2, 4, 5]}, %q{$a = []; begin; ; $a << 1
('a'..'b').map{|e|; $a << 2
break :ok; $a << 3
}; $a << 4
; $a << 5
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 2, 3, 5, 7, 8]}, %q{$a = []; begin; ; $a << 1
[1,2].each do; $a << 2
begin; $a << 3
break; $a << 4
ensure; $a << 5
end; $a << 6
end; $a << 7
; $a << 8
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 2, 3, 4, 5, 6, 9, 10]}, %q{$a = []; begin; ; $a << 1
i=0; $a << 2
while i<3; $a << 3
i+=1; $a << 4
begin; $a << 5
ensure; $a << 6
break; $a << 7
end; $a << 8
end; $a << 9
; $a << 10
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 2, 3, 4, 5, 7, 10, 11]}, %q{$a = []; begin; ; $a << 1
i=0; $a << 2
while i<3; $a << 3
i+=1; $a << 4
begin; $a << 5
raise; $a << 6
ensure; $a << 7
break; $a << 8
end; $a << 9
end; $a << 10
; $a << 11
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 2, 3, 4, 5, 7, 10, 11]}, %q{$a = []; begin; ; $a << 1
i=0; $a << 2
while i<3; $a << 3
i+=1; $a << 4
begin; $a << 5
raise; $a << 6
rescue; $a << 7
break; $a << 8
end; $a << 9
end; $a << 10
; $a << 11
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 2, 3, 5, 8, 9]}, %q{$a = []; begin; ; $a << 1
[1,2].each do; $a << 2
begin; $a << 3
raise StandardError; $a << 4
ensure; $a << 5
break; $a << 6
end; $a << 7
end; $a << 8
; $a << 9
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 2, 3, 5, 8, 9]}, %q{$a = []; begin; ; $a << 1
[1,2].each do; $a << 2
begin; $a << 3
raise StandardError; $a << 4
rescue; $a << 5
break; $a << 6
end; $a << 7
end; $a << 8
; $a << 9
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 2, 3, 4, 6, 8, 10, 11]}, %q{$a = []; begin; ; $a << 1
[1,2].each do; $a << 2
begin; $a << 3
begin; $a << 4
break; $a << 5
ensure; $a << 6
end; $a << 7
ensure; $a << 8
end; $a << 9
end; $a << 10
; $a << 11
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 2, 3, 4, 5, 6, 7, 8, 10, 13, 3, 4, 5, 6, 7, 8, 10, 13, 3, 4, 5, 6, 7, 8, 10, 13, 14, 15]}, %q{$a = []; begin; ; $a << 1
i = 0; $a << 2
while i<3; $a << 3
i+=1; $a << 4
j = 0; $a << 5
while j<3; $a << 6
j+=1; $a << 7
begin; $a << 8
raise; $a << 9
rescue; $a << 10
break; $a << 11
end; $a << 12
end; $a << 13
end; $a << 14
; $a << 15
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 14, 6, 7, 8, 9, 11, 14, 6, 7, 8, 9, 11, 14, 15, 3, 4, 5, 6, 7, 8, 9, 11, 14, 6, 7, 8, 9, 11, 14, 6, 7, 8, 9, 11, 14, 15, 3, 4, 5, 6, 7, 8, 9, 11, 14, 6, 7, 8, 9, 11, 14, 6, 7, 8, 9, 11, 14, 15, 16, 17]}, %q{$a = []; begin; ; $a << 1
i = 0; $a << 2
while i<3; $a << 3
i+=1; $a << 4
j = 0; $a << 5
while j<3; $a << 6
j+=1; $a << 7
1.times{; $a << 8
begin; $a << 9
raise; $a << 10
rescue; $a << 11
break; $a << 12
end; $a << 13
}; $a << 14
end; $a << 15
end; $a << 16
; $a << 17
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 2, 3, 4, 5, 6, 7, 8, 10, 13, 3, 4, 5, 6, 7, 8, 10, 13, 3, 4, 5, 6, 7, 8, 10, 13, 14, 15]}, %q{$a = []; begin; ; $a << 1
i = 0; $a << 2
while i<3; $a << 3
i+=1; $a << 4
j = 0; $a << 5
while j<3; $a << 6
j+=1; $a << 7
begin; $a << 8
raise; $a << 9
ensure; $a << 10
break; $a << 11
end; $a << 12
end; $a << 13
end; $a << 14
; $a << 15
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 14, 6, 7, 8, 9, 11, 14, 6, 7, 8, 9, 11, 14, 15, 3, 4, 5, 6, 7, 8, 9, 11, 14, 6, 7, 8, 9, 11, 14, 6, 7, 8, 9, 11, 14, 15, 3, 4, 5, 6, 7, 8, 9, 11, 14, 6, 7, 8, 9, 11, 14, 6, 7, 8, 9, 11, 14, 15, 16, 17]}, %q{$a = []; begin; ; $a << 1
i = 0; $a << 2
while i<3; $a << 3
i+=1; $a << 4
j = 0; $a << 5
while j<3; $a << 6
j+=1; $a << 7
1.times{; $a << 8
begin; $a << 9
raise; $a << 10
ensure; $a << 11
break; $a << 12
end; $a << 13
}; $a << 14
end; $a << 15
end; $a << 16
; $a << 17
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 2, 3, 5, 8, 9]}, %q{$a = []; begin; ; $a << 1
while true; $a << 2
begin; $a << 3
break; $a << 4
ensure; $a << 5
break; $a << 6
end; $a << 7
end; $a << 8
; $a << 9
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 2, 3, 5, 99]}, %q{$a = []; begin; ; $a << 1
while true; $a << 2
begin; $a << 3
break; $a << 4
ensure; $a << 5
raise; $a << 6
end; $a << 7
end; $a << 8
; $a << 9
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 2, 3, 4, 6, 8, 9, 10, 11]}, %q{$a = []; begin; ; $a << 1
begin; $a << 2
[1,2].each do; $a << 3
begin; $a << 4
break; $a << 5
ensure; $a << 6
end; $a << 7
end; $a << 8
ensure; $a << 9
end; $a << 10
; $a << 11
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 2, 4, 99]}, %q{$a = []; begin; ; $a << 1
begin; $a << 2
raise StandardError; $a << 3
ensure; $a << 4
end; $a << 5
; $a << 6
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 2, 3, 4]}, %q{$a = []; begin; ; $a << 1
begin; $a << 2
ensure; $a << 3
end ; $a << 4
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 2, 3, 5, 99]}, %q{$a = []; begin; ; $a << 1
[1,2].each do; $a << 2
begin; $a << 3
break; $a << 4
ensure; $a << 5
raise StandardError; $a << 6
end; $a << 7
end; $a << 8
; $a << 9
; rescue Exception; $a << 99; end; $a}
assert_equal %q{3}, %q{
def m a, b
a + b
end
m(1,
while true
break 2
end
)
}
assert_equal %q{4}, %q{
def m a, b
a + b
end
m(1,
(i=0; while i<2
i+=1
class C
next 2
end
end; 3)
)
}
assert_equal %q{34}, %q{
def m a, b
a+b
end
m(1, 1.times{break 3}) +
m(10, (1.times{next 3}; 20))
}
assert_equal %q{[1, 2, 3, 6, 7]}, %q{$a = []; begin; ; $a << 1
3.times{; $a << 2
class C; $a << 3
break; $a << 4
end; $a << 5
}; $a << 6
; $a << 7
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 2, 3, 4, 8, 9]}, %q{$a = []; begin; ; $a << 1
3.times{; $a << 2
class A; $a << 3
class B; $a << 4
break; $a << 5
end; $a << 6
end; $a << 7
}; $a << 8
; $a << 9
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 2, 3, 2, 3, 2, 3, 6, 7]}, %q{$a = []; begin; ; $a << 1
3.times{; $a << 2
class C; $a << 3
next; $a << 4
end; $a << 5
}; $a << 6
; $a << 7
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 2, 3, 4, 2, 3, 4, 2, 3, 4, 8, 9]}, %q{$a = []; begin; ; $a << 1
3.times{; $a << 2
class C; $a << 3
class D; $a << 4
next; $a << 5
end; $a << 6
end; $a << 7
}; $a << 8
; $a << 9
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 2, 3, 6, 7]}, %q{$a = []; begin; ; $a << 1
while true; $a << 2
class C; $a << 3
break; $a << 4
end; $a << 5
end; $a << 6
; $a << 7
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 2, 3, 4, 8, 9]}, %q{$a = []; begin; ; $a << 1
while true; $a << 2
class C; $a << 3
class D; $a << 4
break; $a << 5
end; $a << 6
end; $a << 7
end; $a << 8
; $a << 9
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 2, 3, 4, 5, 3, 4, 5, 3, 4, 5, 8, 9]}, %q{$a = []; begin; ; $a << 1
i=0; $a << 2
while i<3; $a << 3
i+=1; $a << 4
class C; $a << 5
next 10; $a << 6
end; $a << 7
end; $a << 8
; $a << 9
; rescue Exception; $a << 99; end; $a}
assert_equal %q{1}, %q{
1.times{
while true
class C
begin
break
ensure
break
end
end
end
}
}
assert_equal %q{[1, 2, 3, 5, 2, 3, 5, 7, 8]}, %q{$a = []; begin; ; $a << 1
[1,2].each do; $a << 2
begin; $a << 3
next; $a << 4
ensure; $a << 5
end; $a << 6
end; $a << 7
; $a << 8
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 2, 6, 3, 5, 7, 8]}, %q{$a = []; begin; ; $a << 1
o = "test"; $a << 2
def o.test(a); $a << 3
return a; $a << 4
ensure; $a << 5
end; $a << 6
o.test(123); $a << 7
; $a << 8
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 4, 7, 5, 8, 9]}, %q{$a = []; begin; ; $a << 1
def m1 *args; $a << 2
; $a << 3
end; $a << 4
def m2; $a << 5
m1(:a, :b, (return 1; :c)); $a << 6
end; $a << 7
m2; $a << 8
; $a << 9
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 8, 2, 3, 4, 5, 9, 10]}, %q{$a = []; begin; ; $a << 1
def m(); $a << 2
begin; $a << 3
2; $a << 4
ensure; $a << 5
return 3; $a << 6
end; $a << 7
end; $a << 8
m; $a << 9
; $a << 10
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 3, 11, 4, 5, 6, 7, 12, 13]}, %q{$a = []; begin; ; $a << 1
def m2; $a << 2
end; $a << 3
def m(); $a << 4
m2(begin; $a << 5
2; $a << 6
ensure; $a << 7
return 3; $a << 8
end); $a << 9
4; $a << 10
end; $a << 11
m(); $a << 12
; $a << 13
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 16, 2, 3, 4, 5, 6, 7, 10, 11, 17, 18]}, %q{$a = []; begin; ; $a << 1
def m; $a << 2
1; $a << 3
1.times{; $a << 4
2; $a << 5
begin; $a << 6
3; $a << 7
return; $a << 8
4; $a << 9
ensure; $a << 10
5; $a << 11
end; $a << 12
6; $a << 13
}; $a << 14
7; $a << 15
end; $a << 16
m(); $a << 17
; $a << 18
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[:ok, :ok2, :last]}, %q{
a = []
i = 0
begin
while i < 1
i+=1
begin
begin
next
ensure
a << :ok
end
ensure
a << :ok2
end
end
ensure
a << :last
end
a
}
assert_equal %q{[:ok, :ok2, :last]}, %q{
a = []
i = 0
begin
while i < 1
i+=1
begin
begin
break
ensure
a << :ok
end
ensure
a << :ok2
end
end
ensure
a << :last
end
a
}
assert_equal %q{[:ok, :ok2, :last]}, %q{
a = []
i = 0
begin
while i < 1
if i>0
break
end
i+=1
begin
begin
redo
ensure
a << :ok
end
ensure
a << :ok2
end
end
ensure
a << :last
end
a
}

232
bootstraptest/test_jump.rb Normal file
View file

@ -0,0 +1,232 @@
assert_equal %q{ok}, %q{
def m
:ng1
mm{
yield
}
:ng2
end
def mm
:ng3
yield
:ng4
end
m{
break :ok
}
}
assert_equal %q{ok}, %q{
3.times{
break :ok
}
}
assert_equal %q{}, %q{
catch(:foo){
throw :foo
}
}
assert_equal %q{false}, %q{
catch(:foo){
throw :foo, false
}
}
assert_equal %q{}, %q{
catch(:foo){
throw :foo, nil
}
}
assert_equal %q{ok}, %q{
catch(:foo){
throw :foo, :ok
}
}
assert_equal %q{}, %q{
catch(:foo){
1.times{
throw :foo
}
}
}
assert_equal %q{ok}, %q{
catch(:foo){
1.times{
throw :foo, :ok
}
}
}
assert_equal %q{ok}, %q{
catch(:foo){
catch(:bar){
throw :foo, :ok
}
:ng
}
}
assert_equal %q{ok}, %q{
catch(:foo){
catch(:bar){
1.times{
throw :foo, :ok
}
}
:ng
}
}
assert_equal %q{2}, %q{
module Enumerable
def all_?
self.each{|e|
unless yield(e)
return false
end
}
true
end
end
xxx = 0
[1,2].each{|bi|
[3,4].each{|bj|
[true, nil, true].all_?{|be| be}
break
}
xxx += 1
}
xxx
}
assert_equal %q{ok}, %q{
def m
yield
end
m{
begin
ensure
break :ok
end
}
}
assert_equal %q{ok}, %q{
def m
yield
:ok
end
i=0
m{
if i>10
i*i
else
i+=1
next
end
}
}
assert_equal %q{ok}, %q{
def m
yield
end
m{
next :ok
}
}
assert_equal %q{131}, %q{
def m
yield + 10
end
i=0
m{
if i>10
i*i
else
i+=1
redo
end
}
}
assert_equal %q{ok}, %q{
def m a
yield
end
i=0
m(i+=1){
retry if i<10
:ok
}
}
assert_equal %q{3}, %q{
def m
return 3
end
m
}
assert_equal %q{ok}, %q{
def m
:ng1
mm{
return :ok
}
:ng2
end
def mm
:ng3
yield
:ng4
end
m
}
assert_equal %q{100}, %q{
$i = 0
def m
begin
iter{
return
}
ensure
$i = 100
end
end
def iter
yield
end
m
$i
}
assert_equal %q{ok}, %q{
def m
begin
raise
rescue
return :ok
end
:ng
end
m
}
assert_equal %q{1}, %q{
def m
begin
raise
rescue
return 1
end
end
m
}
assert_equal %q{1}, %q{
def m
begin
#
ensure
return 1
end
end
m
}

255
bootstraptest/test_proc.rb Normal file
View file

@ -0,0 +1,255 @@
assert_equal %q{[1, 2, 3]}, %q{
def getproc &b
b
end
def m
yield
end
m{
i = 1
m{
j = 2
m{
k = 3
getproc{
[i, j, k]
}
}
}
}.call
}
assert_equal %q{7}, %q{
def make_proc(&b)
b
end
def make_closure
a = 0
make_proc{
a+=1
}
end
cl = make_closure
cl.call + cl.call * cl.call
}
assert_equal %q{ok}, %q{
class C
def foo
:ok
end
end
def block
C.method(:new).to_proc
end
b = block()
b.call.foo
}
assert_equal %q{[0, 1, :last, 0, 2, :last]}, %q{
def proc &b
b
end
pr = []
proc{|i_b|
p3 = proc{|j_b|
pr << proc{|k_b|
[i_b, j_b, k_b]
}
}
p3.call(1)
p3.call(2)
}.call(0)
pr[0].call(:last).concat pr[1].call(:last)
}
assert_equal %q{12}, %q{
def iter
yield
end
def getproc &b
b
end
iter{
bvar = 3
getproc{
bvar2 = 4
bvar * bvar2
}
}.call
}
assert_equal %q{200}, %q{
def iter
yield
end
def getproc &b
b
end
loc1 = 0
pr1 = iter{
bl1 = 1
getproc{
loc1 += 1
bl1 += 1
loc1 + bl1
}
}
pr2 = iter{
bl1 = 1
getproc{
loc1 += 1
bl1 += 1
loc1 + bl1
}
}
pr1.call; pr2.call
pr1.call; pr2.call
pr1.call; pr2.call
(pr1.call + pr2.call) * loc1
}
assert_equal %q{[1, 2]}, %q{
def proc(&pr)
pr
end
def m
a = 1
m2{
a
}
end
def m2
b = 2
proc{
[yield, b]
}
end
pr = m
x = ['a', 1,2,3,4,5,6,7,8,9,0,
1,2,3,4,5,6,7,8,9,0,
1,2,3,4,5,6,7,8,9,0,
1,2,3,4,5,6,7,8,9,0,
1,2,3,4,5,6,7,8,9,0,]
pr.call
}
assert_equal %q{1}, %q{
def proc(&pr)
pr
end
def m
a = 1
m2{
a
}
end
def m2
b = 2
proc{
[yield, b]
}
100000.times{|x|
"#{x}"
}
yield
end
m
}
assert_equal %q{[:C, :C]}, %q{
Const = :top
class C
Const = :C
$pr = proc{
(1..2).map{
Const
}
}
end
$pr.call
}
assert_equal %q{top}, %q{
Const = :top
class C
Const = :C
end
pr = proc{
Const
}
C.class_eval %q{
pr.call
}
}
assert_equal %q{1}, %q{
def m(&b)
b
end
m{|e_proctest| e_proctest}.call(1)
}
assert_equal %q{12}, %q{
def m(&b)
b
end
m{|e_proctest1, e_proctest2|
a = e_proctest1 * e_proctest2 * 2
a * 3
}.call(1, 2)
}
assert_equal %q{[[], [1], [1, 2], [1, 2, 3]]}, %q{
[
Proc.new{|*args| args}.call(),
Proc.new{|*args| args}.call(1),
Proc.new{|*args| args}.call(1, 2),
Proc.new{|*args| args}.call(1, 2, 3),
]
}
assert_equal %q{[[nil, []], [1, []], [1, [2]], [1, [2, 3]]]}, %q{
[
Proc.new{|a, *b| [a, b]}.call(),
Proc.new{|a, *b| [a, b]}.call(1),
Proc.new{|a, *b| [a, b]}.call(1, 2),
Proc.new{|a, *b| [a, b]}.call(1, 2, 3),
]
}
assert_equal %q{0}, %q{
pr = proc{
$SAFE
}
$SAFE = 1
pr.call
}
assert_equal %q{[1, 0]}, %q{
pr = proc{
$SAFE += 1
}
[pr.call, $SAFE]
}
assert_equal %q{1}, %q{
def m(&b)
b
end
m{1}.call
}
assert_equal %q{3}, %q{
def m(&b)
b
end
m{
a = 1
a + 2
}.call
}

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,171 @@
assert_equal %q{ok}, %q{
Thread.new{
}.join
:ok
}
assert_equal %q{ok}, %q{
Thread.new{
:ok
}.value
}
assert_equal %q{20100}, %q{
v = 0
(1..200).map{|i|
Thread.new{
i
}
}.each{|t|
v += t.value
}
v
}
assert_equal %q{5000}, %q{
5000.times{|e|
(1..2).map{
Thread.new{
}
}.each{|e|
e.join
}
}
}
assert_equal %q{5000}, %q{
5000.times{
t = Thread.new{}
while t.alive?
Thread.pass
end
}
}
assert_equal %q{100}, %q{
100.times{
Thread.new{loop{Thread.pass}}
}
}
assert_equal %q{ok}, %q{
Thread.new{
:ok
}.join.value
}
assert_equal %q{ok}, %q{
begin
Thread.new{
raise "ok"
}.join
rescue => e
e
end
}
assert_equal %q{ok}, %q{
ans = nil
t = Thread.new{
begin
sleep 0.5
ensure
ans = :ok
end
}
Thread.pass
t.kill
t.join
ans
}
assert_equal %q{ok}, %q{
t = Thread.new{
sleep
}
sleep 0.1
t.raise
begin
t.join
:ng
rescue
:ok
end
}
assert_equal %q{ok}, %q{
t = Thread.new{
loop{}
}
Thread.pass
t.raise
begin
t.join
:ng
rescue
:ok
end
}
assert_equal %q{ok}, %q{
t = Thread.new{
}
Thread.pass
t.join
t.raise # raise to exited thread
begin
t.join
:ok
rescue
:ng
end
}
assert_equal %q{run}, %q{
t = Thread.new{
loop{}
}
st = t.status
t.kill
st
}
assert_equal %q{sleep}, %q{
t = Thread.new{
sleep
}
sleep 0.1
st = t.status
t.kill
st
}
assert_equal %q{false}, %q{
t = Thread.new{
}
t.kill
sleep 0.1
t.status
}
assert_equal %q{[ThreadGroup, true]}, %q{
ptg = Thread.current.group
Thread.new{
ctg = Thread.current.group
[ctg.class, ctg == ptg]
}.value
}
assert_equal %q{[1, 1]}, %q{
thg = ThreadGroup.new
t = Thread.new{
thg.add Thread.current
sleep
}
sleep 0.1
[thg.list.size, ThreadGroup::Default.list.size]
}
assert_equal %q{[true, nil, true]}, %q{
/a/ =~ 'a'
$a = $~
Thread.new{
$b = $~
/a/ =~ 'a'
$c = $~
}
$d = $~
[$a == $d, $b, $c != $d]
}
assert_equal %q{11}, %q{
Thread.current[:a] = 1
Thread.new{
Thread.current[:a] = 10
Thread.pass
Thread.current[:a]
}.value + Thread.current[:a]
}