mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Added more tests to make btest
This commit is contained in:
parent
8ed77f96fc
commit
d192b149ba
1 changed files with 99 additions and 36 deletions
|
@ -10,6 +10,77 @@ assert_equal '2', %q{
|
||||||
check_index 2
|
check_index 2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# foo leaves a temp on the stack before the call
|
||||||
|
assert_equal '6', %q{
|
||||||
|
def bar
|
||||||
|
return 5
|
||||||
|
end
|
||||||
|
|
||||||
|
def foo
|
||||||
|
return 1 + bar
|
||||||
|
end
|
||||||
|
|
||||||
|
foo()
|
||||||
|
retval = foo()
|
||||||
|
}
|
||||||
|
|
||||||
|
# Method with one arguments
|
||||||
|
# foo leaves a temp on the stack before the call
|
||||||
|
assert_equal '7', %q{
|
||||||
|
def bar(a)
|
||||||
|
return a + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
def foo
|
||||||
|
return 1 + bar(5)
|
||||||
|
end
|
||||||
|
|
||||||
|
foo()
|
||||||
|
retval = foo()
|
||||||
|
}
|
||||||
|
|
||||||
|
# Method with two arguments
|
||||||
|
# foo leaves a temp on the stack before the call
|
||||||
|
assert_equal '0', %q{
|
||||||
|
def bar(a, b)
|
||||||
|
return a - b
|
||||||
|
end
|
||||||
|
|
||||||
|
def foo
|
||||||
|
return 1 + bar(1, 2)
|
||||||
|
end
|
||||||
|
|
||||||
|
foo()
|
||||||
|
retval = foo()
|
||||||
|
}
|
||||||
|
|
||||||
|
# Recursive Ruby-to-Ruby calls
|
||||||
|
assert_equal '21', %q{
|
||||||
|
def fib(n)
|
||||||
|
if n < 2
|
||||||
|
return n
|
||||||
|
end
|
||||||
|
|
||||||
|
return fib(n-1) + fib(n-2)
|
||||||
|
end
|
||||||
|
|
||||||
|
r = fib(8)
|
||||||
|
}
|
||||||
|
|
||||||
|
# Ruby-to-Ruby call and C call
|
||||||
|
assert_normal_exit %q{
|
||||||
|
def bar
|
||||||
|
puts('hi!')
|
||||||
|
end
|
||||||
|
|
||||||
|
def foo
|
||||||
|
bar
|
||||||
|
end
|
||||||
|
|
||||||
|
foo()
|
||||||
|
foo()
|
||||||
|
}
|
||||||
|
|
||||||
# Method redefinition (code invalidation) test
|
# Method redefinition (code invalidation) test
|
||||||
assert_equal '1', %q{
|
assert_equal '1', %q{
|
||||||
def ret1
|
def ret1
|
||||||
|
@ -41,60 +112,52 @@ assert_equal '1', %q{
|
||||||
retval
|
retval
|
||||||
}
|
}
|
||||||
|
|
||||||
# foo leaves a temp on the stack before the call
|
# Method redefinition (code invalidation) and GC
|
||||||
assert_equal '6', %q{
|
assert_equal '7', %q{
|
||||||
def bar
|
def bar()
|
||||||
return 5
|
return 5
|
||||||
end
|
end
|
||||||
|
|
||||||
def foo
|
def foo()
|
||||||
return 1 + bar
|
bar()
|
||||||
end
|
end
|
||||||
|
|
||||||
foo()
|
foo()
|
||||||
retval = foo()
|
foo()
|
||||||
|
|
||||||
|
def bar()
|
||||||
|
return 7
|
||||||
|
end
|
||||||
|
|
||||||
|
4.times { GC.start }
|
||||||
|
|
||||||
|
foo()
|
||||||
|
foo()
|
||||||
}
|
}
|
||||||
|
|
||||||
# foo leaves a temp on the stack before the call
|
# Method redefinition with two block versions
|
||||||
assert_equal '0', %q{
|
assert_equal '7', %q{
|
||||||
def bar(a, b)
|
def bar()
|
||||||
return a - b
|
return 5
|
||||||
end
|
end
|
||||||
|
|
||||||
def foo
|
def foo(n)
|
||||||
return 1 + bar(1, 2)
|
return ((n < 5)? 5:false), bar()
|
||||||
end
|
end
|
||||||
|
|
||||||
foo()
|
foo(4)
|
||||||
retval = foo()
|
foo(4)
|
||||||
}
|
foo(10)
|
||||||
|
foo(10)
|
||||||
|
|
||||||
# Recursive Ruby-to-Ruby calls
|
def bar()
|
||||||
assert_equal '21', %q{
|
return 7
|
||||||
|
|
||||||
def fib(n)
|
|
||||||
if n < 2
|
|
||||||
return n
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return fib(n-1) + fib(n-2)
|
4.times { GC.start }
|
||||||
end
|
|
||||||
|
|
||||||
r = fib(8)
|
foo(4)
|
||||||
}
|
foo(4)[1]
|
||||||
|
|
||||||
# Ruby-to-Ruby call and C call
|
|
||||||
assert_normal_exit %q{
|
|
||||||
def bar
|
|
||||||
puts('hi!')
|
|
||||||
end
|
|
||||||
|
|
||||||
def foo
|
|
||||||
bar
|
|
||||||
end
|
|
||||||
|
|
||||||
foo()
|
|
||||||
foo()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Test for GC safety. Don't invalidate dead iseqs.
|
# Test for GC safety. Don't invalidate dead iseqs.
|
||||||
|
|
Loading…
Add table
Reference in a new issue