change test framework to use files for in and out (s-exp)
This commit is contained in:
5
test/cases/function_definition/class_function.tst
Normal file
5
test/cases/function_definition/class_function.tst
Normal file
@ -0,0 +1,5 @@
|
||||
int String.length( ref x )
|
||||
length
|
||||
end
|
||||
-- -- --
|
||||
{:expression_list=>[{:type=>"int", :receiver=>s(:module, "String"), :function_name=>s(:name, "length"), :parameter_list=>[s(:field, :ref, :x)], :expressions=>[s(:name, "length")], :end=>"end"}]}
|
49
test/cases/function_definition/function_big_while.tst
Normal file
49
test/cases/function_definition/function_big_while.tst
Normal file
@ -0,0 +1,49 @@
|
||||
int fibonaccit(int n)
|
||||
a = 0
|
||||
b = 1
|
||||
while( n > 1 )
|
||||
tmp = a
|
||||
a = b
|
||||
b = tmp + b
|
||||
puts(b)
|
||||
n = n - 1
|
||||
end
|
||||
end
|
||||
-- -- --
|
||||
s(:list, [s(:function, :int,
|
||||
s(:name, "fibonaccit"),
|
||||
s(:parameters,
|
||||
s(:field, :int, :n)),
|
||||
s(:expressions,
|
||||
s(:assign,
|
||||
s(:name, "a"),
|
||||
s(:int, 0)),
|
||||
s(:assign,
|
||||
s(:name, "b"),
|
||||
s(:int, 1)),
|
||||
s(:while,
|
||||
s(:condition,
|
||||
s(:operator, ">",
|
||||
s(:name, "n"),
|
||||
s(:int, 1))),
|
||||
s(:expressions,
|
||||
s(:assign,
|
||||
s(:name, "tmp"),
|
||||
s(:name, "a")),
|
||||
s(:assign,
|
||||
s(:name, "a"),
|
||||
s(:name, "b")),
|
||||
s(:assign,
|
||||
s(:name, "b"),
|
||||
s(:operator, "+",
|
||||
s(:name, "tmp"),
|
||||
s(:name, "b"))),
|
||||
s(:call,
|
||||
s(:name, "puts"),
|
||||
s(:arguments,
|
||||
s(:name, "b"))),
|
||||
s(:assign,
|
||||
s(:name, "n"),
|
||||
s(:operator, "-",
|
||||
s(:name, "n"),
|
||||
s(:int, 1)))))))])
|
23
test/cases/function_definition/function_if.tst
Normal file
23
test/cases/function_definition/function_if.tst
Normal file
@ -0,0 +1,23 @@
|
||||
ref ofthen(int n)
|
||||
if(0)
|
||||
isit = 42
|
||||
else
|
||||
maybenot = 667
|
||||
end
|
||||
end
|
||||
-- -- --
|
||||
s(:list, [s(:function, :ref,
|
||||
s(:name, "ofthen"),
|
||||
s(:parameters,
|
||||
s(:field, :int, :n)),
|
||||
s(:expressions,
|
||||
s(:if,
|
||||
s(:condition,
|
||||
s(:int, 0)),
|
||||
s(:if_true,
|
||||
s(:assign,
|
||||
s(:name, "isit"),
|
||||
s(:int, 42))),
|
||||
s(:if_false, [s(:assign,
|
||||
s(:name, "maybenot"),
|
||||
s(:int, 667))]))))])
|
9
test/cases/function_definition/function_no_arg.tst
Normal file
9
test/cases/function_definition/function_no_arg.tst
Normal file
@ -0,0 +1,9 @@
|
||||
int foo()
|
||||
5
|
||||
end
|
||||
-- -- --
|
||||
s(:list, [s(:function, :int,
|
||||
s(:name, "foo"),
|
||||
s(:parameters),
|
||||
s(:expressions,
|
||||
s(:int, 5)))])
|
17
test/cases/function_definition/function_ops.tst
Normal file
17
test/cases/function_definition/function_ops.tst
Normal file
@ -0,0 +1,17 @@
|
||||
int foo(int x)
|
||||
int abba = 5
|
||||
abba + 5
|
||||
end
|
||||
-- -- --
|
||||
s(:list, [s(:function, :int,
|
||||
s(:name, "foo"),
|
||||
s(:parameters,
|
||||
s(:field, :int, :x)),
|
||||
s(:expressions,
|
||||
s(:name, "int"),
|
||||
s(:assign,
|
||||
s(:name, "abba"),
|
||||
s(:int, 5)),
|
||||
s(:operator, "+",
|
||||
s(:name, "abba"),
|
||||
s(:int, 5))))])
|
16
test/cases/function_definition/function_return.tst
Normal file
16
test/cases/function_definition/function_return.tst
Normal file
@ -0,0 +1,16 @@
|
||||
int retvar(ref n)
|
||||
int i = 5
|
||||
return i
|
||||
end
|
||||
-- -- --
|
||||
s(:list, [s(:function, :int,
|
||||
s(:name, "retvar"),
|
||||
s(:parameters,
|
||||
s(:field, :ref, :n)),
|
||||
s(:expressions,
|
||||
s(:name, "int"),
|
||||
s(:assign,
|
||||
s(:name, "i"),
|
||||
s(:int, 5)),
|
||||
s(:return,
|
||||
s(:name, "i"))))])
|
23
test/cases/function_definition/function_return_if.tst
Normal file
23
test/cases/function_definition/function_return_if.tst
Normal file
@ -0,0 +1,23 @@
|
||||
int retvar(int n)
|
||||
if( n > 5)
|
||||
return 10
|
||||
else
|
||||
return 20
|
||||
end
|
||||
end
|
||||
-- -- --
|
||||
s(:list, [s(:function, :int,
|
||||
s(:name, "retvar"),
|
||||
s(:parameters,
|
||||
s(:field, :int, :n)),
|
||||
s(:expressions,
|
||||
s(:if,
|
||||
s(:condition,
|
||||
s(:operator, ">",
|
||||
s(:name, "n"),
|
||||
s(:int, 5))),
|
||||
s(:if_true,
|
||||
s(:return,
|
||||
s(:int, 10))),
|
||||
s(:if_false, [s(:return,
|
||||
s(:int, 20))]))))])
|
25
test/cases/function_definition/function_return_while.tst
Normal file
25
test/cases/function_definition/function_return_while.tst
Normal file
@ -0,0 +1,25 @@
|
||||
int retvar(int n )
|
||||
while( n > 5)
|
||||
n = n + 1
|
||||
return n
|
||||
end
|
||||
end
|
||||
-- -- --
|
||||
s(:list, [s(:function, :int,
|
||||
s(:name, "retvar"),
|
||||
s(:parameters,
|
||||
s(:field, :int, :n)),
|
||||
s(:expressions,
|
||||
s(:while,
|
||||
s(:condition,
|
||||
s(:operator, ">",
|
||||
s(:name, "n"),
|
||||
s(:int, 5))),
|
||||
s(:expressions,
|
||||
s(:assign,
|
||||
s(:name, "n"),
|
||||
s(:operator, "+",
|
||||
s(:name, "n"),
|
||||
s(:int, 1))),
|
||||
s(:return,
|
||||
s(:name, "n"))))))])
|
11
test/cases/function_definition/function_two_args.tst
Normal file
11
test/cases/function_definition/function_two_args.tst
Normal file
@ -0,0 +1,11 @@
|
||||
int foo( int n ,ref m)
|
||||
n
|
||||
end
|
||||
-- -- --
|
||||
s(:list, [s(:function, :int,
|
||||
s(:name, "foo"),
|
||||
s(:parameters,
|
||||
s(:field, :int, :n),
|
||||
s(:field, :ref, :m)),
|
||||
s(:expressions,
|
||||
s(:name, "n")))])
|
28
test/cases/function_definition/function_while.tst
Normal file
28
test/cases/function_definition/function_while.tst
Normal file
@ -0,0 +1,28 @@
|
||||
ref fibonaccit(int n)
|
||||
a = 0
|
||||
while(n)
|
||||
some = 43
|
||||
other = some * 4
|
||||
end
|
||||
end
|
||||
-- -- --
|
||||
s(:list, [s(:function, :ref,
|
||||
s(:name, "fibonaccit"),
|
||||
s(:parameters,
|
||||
s(:field, :int, :n)),
|
||||
s(:expressions,
|
||||
s(:assign,
|
||||
s(:name, "a"),
|
||||
s(:int, 0)),
|
||||
s(:while,
|
||||
s(:condition,
|
||||
s(:name, "n")),
|
||||
s(:expressions,
|
||||
s(:assign,
|
||||
s(:name, "some"),
|
||||
s(:int, 43)),
|
||||
s(:assign,
|
||||
s(:name, "other"),
|
||||
s(:operator, "*",
|
||||
s(:name, "some"),
|
||||
s(:int, 4)))))))])
|
10
test/cases/function_definition/simplest_function.tst
Normal file
10
test/cases/function_definition/simplest_function.tst
Normal file
@ -0,0 +1,10 @@
|
||||
int foo(ref x)
|
||||
5
|
||||
end
|
||||
-- -- --
|
||||
s(:list, [s(:function, :int,
|
||||
s(:name, "foo"),
|
||||
s(:parameters,
|
||||
s(:field, :ref, :x)),
|
||||
s(:expressions,
|
||||
s(:int, 5)))])
|
Reference in New Issue
Block a user