improve method test
mostly by actually testing main, which is what is checked
This commit is contained in:
parent
cd96e78e2d
commit
c1d31a541d
@ -5,44 +5,34 @@ module Virtual
|
|||||||
class TestMethods < MiniTest::Test
|
class TestMethods < MiniTest::Test
|
||||||
include CodeChecker
|
include CodeChecker
|
||||||
|
|
||||||
def test_module
|
def test_simplest_function
|
||||||
@string_input = <<HERE
|
@string_input = <<HERE
|
||||||
class Some
|
class Object
|
||||||
int foo()
|
int main()
|
||||||
return 5
|
return 5
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
HERE
|
HERE
|
||||||
@output = [[MethodEnter] ,[MethodReturn]]
|
@output = [[MethodEnter,Set] ,[MethodReturn]]
|
||||||
check
|
check
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_simplest_function
|
|
||||||
|
def test_second_simplest_function
|
||||||
@string_input = <<HERE
|
@string_input = <<HERE
|
||||||
class Object
|
class Object
|
||||||
int foo(int x)
|
int main()
|
||||||
|
int x = 5
|
||||||
return x
|
return x
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
HERE
|
HERE
|
||||||
@output = [[MethodEnter] ,[MethodReturn]]
|
@output = [[Virtual::MethodEnter,Set],[Virtual::MethodReturn]]
|
||||||
check
|
check
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_second_simplest_function
|
def test_puts_string
|
||||||
@string_input = <<HERE
|
@string_input = <<HERE
|
||||||
class Object
|
|
||||||
ref foo(ref x)
|
|
||||||
return x
|
|
||||||
end
|
|
||||||
end
|
|
||||||
HERE
|
|
||||||
@output = [[Virtual::MethodEnter],[Virtual::MethodReturn]]
|
|
||||||
check
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_puts_string
|
|
||||||
@string_input = <<HERE
|
|
||||||
class Object
|
class Object
|
||||||
int puts(ref str)
|
int puts(ref str)
|
||||||
return str
|
return str
|
||||||
@ -52,26 +42,26 @@ class Object
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
HERE
|
HERE
|
||||||
@output = [[MethodEnter , NewMessage, Set, Set , Set, Set, MethodCall],[MethodReturn]]
|
@output = [[MethodEnter , NewMessage, Set, Set , Set, Set, MethodCall],[MethodReturn]]
|
||||||
check
|
check
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_int_function
|
def test_int_function
|
||||||
@string_input = <<HERE
|
@string_input = <<HERE
|
||||||
class Integer < Object
|
class Integer < Object
|
||||||
int times(int x)
|
int times(int x)
|
||||||
self * x
|
self * x
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
HERE
|
HERE
|
||||||
@output = [[Virtual::MethodEnter] , [Virtual::MethodReturn]]
|
@output = [[Virtual::MethodEnter] , [Virtual::MethodReturn]]
|
||||||
check
|
check
|
||||||
cla = Virtual.machine.space.get_class_by_name :Integer
|
cla = Virtual.machine.space.get_class_by_name :Integer
|
||||||
assert cla.get_instance_method( :times )
|
assert cla.get_instance_method( :times )
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_function_ops
|
def test_function_ops
|
||||||
@string_input = <<HERE
|
@string_input = <<HERE
|
||||||
class Object
|
class Object
|
||||||
int foo(int abba)
|
int foo(int abba)
|
||||||
abba = 5
|
abba = 5
|
||||||
@ -79,28 +69,29 @@ class Object
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
HERE
|
HERE
|
||||||
@output = [[Virtual::MethodEnter] , [Virtual::MethodReturn]]
|
@output = [[Virtual::MethodEnter] , [Virtual::MethodReturn]]
|
||||||
check
|
check
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_function_if
|
def test_function_if
|
||||||
@string_input = <<HERE
|
@string_input = <<HERE
|
||||||
class Object
|
class Object
|
||||||
int ofthen(int n)
|
int main()
|
||||||
if(0)
|
if(0)
|
||||||
int isit = 42
|
return 42
|
||||||
else
|
else
|
||||||
int maybenot = 667
|
return 667
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
HERE
|
HERE
|
||||||
@output = [[Virtual::MethodEnter] , [Virtual::MethodReturn]]
|
@output = [[MethodEnter,Set,Register::IsZeroBranch] , [Set,Register::AlwaysBranch],
|
||||||
check
|
[Set],[],[MethodReturn]]
|
||||||
end
|
check
|
||||||
|
end
|
||||||
|
|
||||||
def test_while
|
def test_while
|
||||||
@string_input = <<HERE
|
@string_input = <<HERE
|
||||||
class Object
|
class Object
|
||||||
int foo()
|
int foo()
|
||||||
while(1)
|
while(1)
|
||||||
@ -109,12 +100,12 @@ class Object
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
HERE
|
HERE
|
||||||
@output = [[Virtual::MethodEnter],[Virtual::MethodReturn]]
|
@output = [[Virtual::MethodEnter],[Virtual::MethodReturn]]
|
||||||
check
|
check
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_function_while
|
def test_function_while
|
||||||
@string_input = <<HERE
|
@string_input = <<HERE
|
||||||
class Object
|
class Object
|
||||||
int fibonaccit(int n)
|
int fibonaccit(int n)
|
||||||
int a = 0
|
int a = 0
|
||||||
@ -125,12 +116,12 @@ class Object
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
HERE
|
HERE
|
||||||
@output = [[Virtual::MethodEnter],[Virtual::MethodReturn]]
|
@output = [[Virtual::MethodEnter],[Virtual::MethodReturn]]
|
||||||
check
|
check
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_function_return
|
def test_function_return
|
||||||
@string_input = <<HERE
|
@string_input = <<HERE
|
||||||
class Object
|
class Object
|
||||||
int retvar(int n)
|
int retvar(int n)
|
||||||
int i = 5
|
int i = 5
|
||||||
@ -138,14 +129,15 @@ class Object
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
HERE
|
HERE
|
||||||
@output = [[Virtual::MethodEnter],[Virtual::MethodReturn]]
|
@output = [[Virtual::MethodEnter],[Virtual::MethodReturn]]
|
||||||
check
|
check
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_function_return_if
|
def test_function_return_if
|
||||||
@string_input = <<HERE
|
@string_input = <<HERE
|
||||||
class Object
|
class Object
|
||||||
int retvar(int n)
|
int main()
|
||||||
|
int n = 10
|
||||||
if( n > 5)
|
if( n > 5)
|
||||||
return 10
|
return 10
|
||||||
else
|
else
|
||||||
@ -154,46 +146,30 @@ class Object
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
HERE
|
HERE
|
||||||
@output = [[Virtual::MethodEnter],[Virtual::MethodReturn]]
|
@output = [[MethodEnter,Set,Set,Register::GetSlot,Register::GetSlot,
|
||||||
check
|
Register::OperatorInstruction,Register::IsZeroBranch],
|
||||||
end
|
[Set,Register::AlwaysBranch],[Set],[],[MethodReturn]]
|
||||||
|
check
|
||||||
|
end
|
||||||
|
|
||||||
def test_function_return_while
|
def test_function_return_while
|
||||||
@string_input = <<HERE
|
@string_input = <<HERE
|
||||||
class Object
|
class Object
|
||||||
int retvar(int n)
|
int main()
|
||||||
while( n > 5) do
|
int n = 10
|
||||||
|
while( n > 5)
|
||||||
n = n + 1
|
n = n + 1
|
||||||
return n
|
return n
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
HERE
|
HERE
|
||||||
@output = [[Virtual::MethodEnter],[Virtual::MethodReturn]]
|
@output = [[MethodEnter,Set],
|
||||||
check
|
[Set,Register::GetSlot,Register::GetSlot,Register::OperatorInstruction,
|
||||||
end
|
Register::IsZeroBranch,Set,Register::GetSlot,Register::GetSlot,
|
||||||
|
Register::OperatorInstruction,Set,Register::AlwaysBranch] ,
|
||||||
def test_function_big_while
|
[],[MethodReturn]]
|
||||||
@string_input = <<HERE
|
check
|
||||||
class Object
|
|
||||||
int puts(int i)
|
|
||||||
return 0
|
|
||||||
end
|
|
||||||
int fibonaccit(int n)
|
|
||||||
int a = 0
|
|
||||||
int b = 1
|
|
||||||
while( n > 1 )
|
|
||||||
int tmp = a
|
|
||||||
a = b
|
|
||||||
b = tmp + b
|
|
||||||
puts(b)
|
|
||||||
n = n - 1
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
HERE
|
|
||||||
@output = [[Virtual::MethodEnter],[Virtual::MethodReturn]]
|
|
||||||
check
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user