2015-07-19 10:54:36 +03:00
|
|
|
require_relative "compiler_helper"
|
2015-09-27 11:27:30 +03:00
|
|
|
require_relative "code_checker"
|
|
|
|
|
2015-07-18 15:28:57 +03:00
|
|
|
module Virtual
|
|
|
|
class TestMethods < MiniTest::Test
|
2015-09-27 11:27:30 +03:00
|
|
|
include CodeChecker
|
2015-07-18 15:28:57 +03:00
|
|
|
|
2015-07-19 10:36:06 +03:00
|
|
|
def test_module
|
|
|
|
@string_input = <<HERE
|
|
|
|
class Some
|
2015-09-20 17:33:05 +03:00
|
|
|
int foo()
|
|
|
|
return 5
|
2015-07-19 10:36:06 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
HERE
|
|
|
|
@output = [[MethodEnter] ,[MethodReturn]]
|
|
|
|
check
|
|
|
|
end
|
|
|
|
|
2015-07-18 15:28:57 +03:00
|
|
|
def test_simplest_function
|
|
|
|
@string_input = <<HERE
|
2015-10-06 00:27:13 +03:00
|
|
|
class Object
|
|
|
|
int foo(int x)
|
|
|
|
return x
|
|
|
|
end
|
2014-07-14 11:29:38 +03:00
|
|
|
end
|
2015-07-18 15:28:57 +03:00
|
|
|
HERE
|
|
|
|
@output = [[MethodEnter] ,[MethodReturn]]
|
|
|
|
check
|
|
|
|
end
|
|
|
|
|
2015-09-20 17:33:05 +03:00
|
|
|
def test_second_simplest_function
|
2015-07-18 15:28:57 +03:00
|
|
|
@string_input = <<HERE
|
2015-10-06 00:27:13 +03:00
|
|
|
class Object
|
|
|
|
ref foo(ref x)
|
|
|
|
return x
|
|
|
|
end
|
2015-07-18 15:28:57 +03:00
|
|
|
end
|
2014-07-14 11:29:38 +03:00
|
|
|
HERE
|
2015-09-20 17:33:05 +03:00
|
|
|
@output = [[Virtual::MethodEnter],[Virtual::MethodReturn]]
|
2014-08-20 17:14:52 +03:00
|
|
|
check
|
|
|
|
end
|
|
|
|
|
2015-09-20 17:33:05 +03:00
|
|
|
def test_puts_string
|
2014-08-20 17:14:52 +03:00
|
|
|
@string_input = <<HERE
|
2015-10-06 00:27:13 +03:00
|
|
|
class Object
|
|
|
|
int main()
|
|
|
|
puts("Hello")
|
|
|
|
end
|
2014-08-20 17:14:52 +03:00
|
|
|
end
|
|
|
|
HERE
|
2015-10-06 00:27:13 +03:00
|
|
|
@output = [[MethodEnter , NewMessage, Set, Set , Set, Set, MethodCall],[MethodReturn]]
|
2014-07-14 11:29:38 +03:00
|
|
|
check
|
|
|
|
end
|
|
|
|
|
2015-10-06 00:27:13 +03:00
|
|
|
def test_int_function
|
2014-07-14 11:29:38 +03:00
|
|
|
@string_input = <<HERE
|
2015-10-06 00:27:13 +03:00
|
|
|
class Integer < Object
|
|
|
|
int times(int x)
|
|
|
|
self * x
|
|
|
|
end
|
2014-07-14 11:29:38 +03:00
|
|
|
end
|
|
|
|
HERE
|
2015-10-06 00:27:13 +03:00
|
|
|
@output = [[Virtual::MethodEnter] , [Virtual::MethodReturn]]
|
2014-07-14 14:06:09 +03:00
|
|
|
check
|
2015-10-06 00:27:13 +03:00
|
|
|
cla = Virtual.machine.space.get_class_by_name :Integer
|
|
|
|
assert cla.get_instance_method( :times )
|
2014-07-14 11:29:38 +03:00
|
|
|
end
|
|
|
|
|
2015-07-02 10:26:48 +03:00
|
|
|
def ttest_function_ops
|
2014-07-14 11:29:38 +03:00
|
|
|
@string_input = <<HERE
|
2015-05-06 08:38:29 +03:00
|
|
|
def foo(x)
|
|
|
|
abba = 5
|
2014-07-14 11:29:38 +03:00
|
|
|
2 + 5
|
|
|
|
end
|
|
|
|
HERE
|
2015-07-02 10:26:48 +03:00
|
|
|
@output = nil
|
2014-07-15 18:27:13 +03:00
|
|
|
check
|
|
|
|
end
|
|
|
|
|
2015-09-20 17:33:05 +03:00
|
|
|
def ttest_function_ops_simple
|
2014-07-15 18:27:13 +03:00
|
|
|
@string_input = <<HERE
|
|
|
|
def foo()
|
|
|
|
2 + 5
|
|
|
|
end
|
|
|
|
HERE
|
2015-08-04 21:46:33 +03:00
|
|
|
@output = [[Virtual::MethodEnter],[Virtual::MethodReturn]]
|
|
|
|
check
|
|
|
|
end
|
|
|
|
|
2015-09-20 17:33:05 +03:00
|
|
|
def ttest_ops_simple
|
|
|
|
#TODO ops still botched
|
2015-08-04 21:46:33 +03:00
|
|
|
@string_input = <<HERE
|
|
|
|
2 + 5
|
|
|
|
HERE
|
|
|
|
@output = [[Virtual::MethodEnter , Virtual::Set,Virtual::NewMessage,Virtual::Set,
|
|
|
|
Virtual::Set ,Virtual::Set,Virtual::Set,Virtual::MessageSend] , [Virtual::MethodReturn]]
|
2014-07-14 16:19:47 +03:00
|
|
|
check
|
2014-07-14 11:29:38 +03:00
|
|
|
end
|
|
|
|
|
2015-07-02 10:26:48 +03:00
|
|
|
def ttest_function_if
|
2014-07-14 11:29:38 +03:00
|
|
|
@string_input = <<HERE
|
|
|
|
def ofthen(n)
|
|
|
|
if(0)
|
|
|
|
isit = 42
|
|
|
|
else
|
|
|
|
maybenot = 667
|
|
|
|
end
|
|
|
|
end
|
|
|
|
HERE
|
2015-07-02 10:26:48 +03:00
|
|
|
@output = nil
|
2015-05-06 15:15:53 +03:00
|
|
|
check
|
2014-07-14 11:29:38 +03:00
|
|
|
end
|
|
|
|
|
2015-07-18 19:02:54 +03:00
|
|
|
def test_while
|
|
|
|
@string_input = <<HERE
|
2015-10-06 00:27:13 +03:00
|
|
|
class Object
|
|
|
|
int foo()
|
|
|
|
while(1)
|
|
|
|
3
|
|
|
|
end
|
|
|
|
end
|
2015-07-18 19:02:54 +03:00
|
|
|
end
|
|
|
|
HERE
|
2015-10-06 00:27:13 +03:00
|
|
|
@output = [[Virtual::MethodEnter],[Virtual::MethodReturn]]
|
2015-07-18 19:02:54 +03:00
|
|
|
check
|
|
|
|
end
|
|
|
|
|
2015-07-02 10:26:48 +03:00
|
|
|
def ttest_function_while
|
2014-07-17 16:46:17 +03:00
|
|
|
@string_input = <<HERE
|
|
|
|
def fibonaccit(n)
|
|
|
|
a = 0
|
|
|
|
while (n) do
|
|
|
|
some = 43
|
|
|
|
other = some * 4
|
|
|
|
end
|
|
|
|
end
|
|
|
|
HERE
|
2015-07-02 10:26:48 +03:00
|
|
|
@output = nil
|
2014-07-17 16:46:17 +03:00
|
|
|
check
|
|
|
|
end
|
|
|
|
|
2015-05-06 15:15:53 +03:00
|
|
|
def pest_function_return
|
2014-07-14 11:29:38 +03:00
|
|
|
@string_input = <<HERE
|
|
|
|
def retvar(n)
|
|
|
|
i = 5
|
2015-05-06 08:38:29 +03:00
|
|
|
return i
|
2014-07-14 11:29:38 +03:00
|
|
|
end
|
|
|
|
HERE
|
2014-08-13 11:59:51 +03:00
|
|
|
@output = ""
|
2014-07-14 16:19:47 +03:00
|
|
|
check
|
2014-07-14 11:29:38 +03:00
|
|
|
end
|
|
|
|
|
2015-05-06 15:15:53 +03:00
|
|
|
def pest_function_return_if
|
2014-07-14 11:29:38 +03:00
|
|
|
@string_input = <<HERE
|
|
|
|
def retvar(n)
|
|
|
|
if( n > 5)
|
|
|
|
return 10
|
|
|
|
else
|
|
|
|
return 20
|
2015-05-06 08:38:29 +03:00
|
|
|
end
|
2014-07-14 11:29:38 +03:00
|
|
|
end
|
|
|
|
HERE
|
2014-08-13 11:59:51 +03:00
|
|
|
@output = ""
|
2014-07-14 16:19:47 +03:00
|
|
|
check
|
2014-07-14 11:29:38 +03:00
|
|
|
end
|
|
|
|
|
2015-05-06 15:15:53 +03:00
|
|
|
def est_function_return_while
|
2014-07-14 11:29:38 +03:00
|
|
|
@string_input = <<HERE
|
|
|
|
def retvar(n)
|
|
|
|
while( n > 5) do
|
|
|
|
n = n + 1
|
|
|
|
return n
|
2015-05-06 08:38:29 +03:00
|
|
|
end
|
2014-07-14 11:29:38 +03:00
|
|
|
end
|
|
|
|
HERE
|
2014-08-13 11:59:51 +03:00
|
|
|
@output = ""
|
2014-07-14 16:19:47 +03:00
|
|
|
check
|
2014-07-14 11:29:38 +03:00
|
|
|
end
|
|
|
|
|
2015-05-06 15:15:53 +03:00
|
|
|
def pest_function_big_while
|
2014-07-14 11:29:38 +03:00
|
|
|
@string_input = <<HERE
|
|
|
|
def fibonaccit(n)
|
2015-05-06 08:38:29 +03:00
|
|
|
a = 0
|
2014-07-14 11:29:38 +03:00
|
|
|
b = 1
|
|
|
|
while( n > 1 ) do
|
|
|
|
tmp = a
|
|
|
|
a = b
|
|
|
|
b = tmp + b
|
|
|
|
puts(b)
|
|
|
|
n = n - 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
HERE
|
2014-08-13 11:59:51 +03:00
|
|
|
@output = ""
|
2014-07-14 16:19:47 +03:00
|
|
|
check
|
2015-05-06 08:38:29 +03:00
|
|
|
end
|
|
|
|
end
|
2015-07-18 15:28:57 +03:00
|
|
|
end
|