change test framework to use files for in and out (s-exp)
This commit is contained in:
parent
396a843a5e
commit
22e3c59674
3
test/cases/basic/module_name.tst
Normal file
3
test/cases/basic/module_name.tst
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
FooBar
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:module, "FooBar")])
|
3
test/cases/basic/name.tst
Normal file
3
test/cases/basic/name.tst
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
foo
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:name, "foo")])
|
3
test/cases/basic/name_underscode_middle.tst
Normal file
3
test/cases/basic/name_underscode_middle.tst
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
foo_bar
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:name, "foo_bar")])
|
3
test/cases/basic/name_underscode_start.tst
Normal file
3
test/cases/basic/name_underscode_start.tst
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
_bar
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:name, "_bar")])
|
3
test/cases/basic/number.tst
Normal file
3
test/cases/basic/number.tst
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
42
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:int, 42)])
|
3
test/cases/basic/string.tst
Normal file
3
test/cases/basic/string.tst
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
"hello"
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:string, "hello")])
|
3
test/cases/basic/string_escapes.tst
Normal file
3
test/cases/basic/string_escapes.tst
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
"hello \nyou"
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:string, "hello \\nyou")])
|
7
test/cases/call_site/call_puts_two.tst
Normal file
7
test/cases/call_site/call_puts_two.tst
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
puts(3 , a )
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:call,
|
||||||
|
s(:name, "puts"),
|
||||||
|
s(:arguments,
|
||||||
|
s(:int, 3),
|
||||||
|
s(:name, "a")))])
|
7
test/cases/call_site/call_site_multi.tst
Normal file
7
test/cases/call_site/call_site_multi.tst
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
baz(42, foo)
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:call,
|
||||||
|
s(:name, "baz"),
|
||||||
|
s(:arguments,
|
||||||
|
s(:int, 42),
|
||||||
|
s(:name, "foo")))])
|
6
test/cases/call_site/call_site_string.tst
Normal file
6
test/cases/call_site/call_site_string.tst
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
puts( "hello")
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:call,
|
||||||
|
s(:name, "puts"),
|
||||||
|
s(:arguments,
|
||||||
|
s(:string, "hello")))])
|
7
test/cases/call_site/int_receiver.tst
Normal file
7
test/cases/call_site/int_receiver.tst
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
42.put()
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:call,
|
||||||
|
s(:name, "put"),
|
||||||
|
s(:arguments),
|
||||||
|
s(:receiver,
|
||||||
|
s(:int, 42)))])
|
6
test/cases/call_site/puts_call.tst
Normal file
6
test/cases/call_site/puts_call.tst
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
puts( 5)
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:call,
|
||||||
|
s(:name, "puts"),
|
||||||
|
s(:arguments,
|
||||||
|
s(:int, 5)))])
|
6
test/cases/call_site/single_argument.tst
Normal file
6
test/cases/call_site/single_argument.tst
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
foo(42)
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:call,
|
||||||
|
s(:name, "foo"),
|
||||||
|
s(:arguments,
|
||||||
|
s(:int, 42)))])
|
8
test/cases/call_site/single_class.tst
Normal file
8
test/cases/call_site/single_class.tst
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
Object.foo(42)
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:call,
|
||||||
|
s(:name, "foo"),
|
||||||
|
s(:arguments,
|
||||||
|
s(:int, 42)),
|
||||||
|
s(:receiver,
|
||||||
|
s(:module, "Object")))])
|
8
test/cases/call_site/single_name.tst
Normal file
8
test/cases/call_site/single_name.tst
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
my_my.foo(42)
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:call,
|
||||||
|
s(:name, "foo"),
|
||||||
|
s(:arguments,
|
||||||
|
s(:int, 42)),
|
||||||
|
s(:receiver,
|
||||||
|
s(:name, "my_my")))])
|
8
test/cases/call_site/single_self.tst
Normal file
8
test/cases/call_site/single_self.tst
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
self.foo(42)
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:call,
|
||||||
|
s(:name, "foo"),
|
||||||
|
s(:arguments,
|
||||||
|
s(:int, 42)),
|
||||||
|
s(:receiver,
|
||||||
|
s(:name, "self")))])
|
7
test/cases/call_site/string_receiver.tst
Normal file
7
test/cases/call_site/string_receiver.tst
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
"hello".puts()
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:call,
|
||||||
|
s(:name, "puts"),
|
||||||
|
s(:arguments),
|
||||||
|
s(:receiver,
|
||||||
|
s(:string, "hello")))])
|
10
test/cases/class_def/class_derived.tst
Normal file
10
test/cases/class_def/class_derived.tst
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
class Foo < Object
|
||||||
|
ofthen(3 , var)
|
||||||
|
end
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:class, "Foo",
|
||||||
|
s(:module, "Object"), [s(:call,
|
||||||
|
s(:name, "ofthen"),
|
||||||
|
s(:arguments,
|
||||||
|
s(:int, 3),
|
||||||
|
s(:name, "var")))])])
|
18
test/cases/class_def/class_function.tst
Normal file
18
test/cases/class_def/class_function.tst
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
class Pifi
|
||||||
|
ofthen(3 , var)
|
||||||
|
int ofthen(int n , ref m)
|
||||||
|
44
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:class, "Pifi", nil, [s(:call,
|
||||||
|
s(:name, "ofthen"),
|
||||||
|
s(:arguments,
|
||||||
|
s(:int, 3),
|
||||||
|
s(:name, "var"))), s(:function, :int,
|
||||||
|
s(:name, "ofthen"),
|
||||||
|
s(:parameters,
|
||||||
|
s(:field, :int, :n),
|
||||||
|
s(:field, :ref, :m)),
|
||||||
|
s(:expressions,
|
||||||
|
s(:int, 44)))])])
|
25
test/cases/class_def/class_if.tst
Normal file
25
test/cases/class_def/class_if.tst
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
class Ifi
|
||||||
|
int ofthen(int n)
|
||||||
|
if(0)
|
||||||
|
isit = 42
|
||||||
|
else
|
||||||
|
maybenot = 667
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:class, "Ifi", nil, [s(:function, :int,
|
||||||
|
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))]))))])])
|
7
test/cases/class_def/class_method.tst
Normal file
7
test/cases/class_def/class_method.tst
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
class Foo < Object
|
||||||
|
int Foo.test()
|
||||||
|
43
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- -- --
|
||||||
|
{:expression_list=>[{:module_name=>"Foo", :derived_name=>s(:module, "Object"), :class_expressions=>[{:type=>"int", :receiver=>s(:module, "Foo"), :function_name=>s(:name, "test"), :parameter_list=>[], :expressions=>[s(:int, 43)], :end=>"end"}], :end=>"end"}]}
|
11
test/cases/class_def/class_module.tst
Normal file
11
test/cases/class_def/class_module.tst
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
class Foo
|
||||||
|
module Boo
|
||||||
|
funcall(3 , var)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:class, "Foo", nil, [s(:module, "Boo", [s(:call,
|
||||||
|
s(:name, "funcall"),
|
||||||
|
s(:arguments,
|
||||||
|
s(:int, 3),
|
||||||
|
s(:name, "var")))])])])
|
19
test/cases/class_def/class_ops.tst
Normal file
19
test/cases/class_def/class_ops.tst
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
class Opers
|
||||||
|
int foo(int x)
|
||||||
|
int abba = 5
|
||||||
|
abba + 5
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:class, "Opers", nil, [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))))])])
|
5
test/cases/class_def/simplest_class.tst
Normal file
5
test/cases/class_def/simplest_class.tst
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
class Foo
|
||||||
|
5
|
||||||
|
end
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:class, "Foo", nil, [s(:int, 5)])])
|
3
test/cases/compound/array_list.tst
Normal file
3
test/cases/compound/array_list.tst
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
[42, foo]
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:array, [s(:int, 42), s(:name, "foo")])])
|
8
test/cases/compound/array_ops.tst
Normal file
8
test/cases/compound/array_ops.tst
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
[ 3 + 4 , foo(22) ]
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:array, [s(:operator, "+",
|
||||||
|
s(:int, 3),
|
||||||
|
s(:int, 4)), s(:call,
|
||||||
|
s(:name, "foo"),
|
||||||
|
s(:arguments,
|
||||||
|
s(:int, 22)))])])
|
5
test/cases/compound/hash.tst
Normal file
5
test/cases/compound/hash.tst
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{ foo => 33 }
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:hash, [s(:assoc,
|
||||||
|
s(:name, "foo"),
|
||||||
|
s(:int, 33))])])
|
5
test/cases/compound/hash2.tst
Normal file
5
test/cases/compound/hash2.tst
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{ foo => true }
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:hash, [s(:assoc,
|
||||||
|
s(:name, "foo"),
|
||||||
|
s(:true))])])
|
7
test/cases/compound/hash_list.tst
Normal file
7
test/cases/compound/hash_list.tst
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
{foo => 33 , bar => 42}
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:hash, [s(:assoc,
|
||||||
|
s(:name, "foo"),
|
||||||
|
s(:int, 33)), s(:assoc,
|
||||||
|
s(:name, "bar"),
|
||||||
|
s(:int, 42))])])
|
3
test/cases/compound/one_array.tst
Normal file
3
test/cases/compound/one_array.tst
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
[42]
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:array, [s(:int, 42)])])
|
12
test/cases/conditional/if_else.tst
Normal file
12
test/cases/conditional/if_else.tst
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
if(0)
|
||||||
|
42
|
||||||
|
else
|
||||||
|
667
|
||||||
|
end
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:if,
|
||||||
|
s(:condition,
|
||||||
|
s(:int, 0)),
|
||||||
|
s(:if_true,
|
||||||
|
s(:int, 42)),
|
||||||
|
s(:if_false, [s(:int, 667)]))])
|
24
test/cases/conditional/if_else_expressions.tst
Normal file
24
test/cases/conditional/if_else_expressions.tst
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
if(3 > var)
|
||||||
|
Object.initialize(3)
|
||||||
|
else
|
||||||
|
var.new(33)
|
||||||
|
end
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:if,
|
||||||
|
s(:condition,
|
||||||
|
s(:operator, ">",
|
||||||
|
s(:int, 3),
|
||||||
|
s(:name, "var"))),
|
||||||
|
s(:if_true,
|
||||||
|
s(:call,
|
||||||
|
s(:name, "initialize"),
|
||||||
|
s(:arguments,
|
||||||
|
s(:int, 3)),
|
||||||
|
s(:receiver,
|
||||||
|
s(:module, "Object")))),
|
||||||
|
s(:if_false, [s(:call,
|
||||||
|
s(:name, "new"),
|
||||||
|
s(:arguments,
|
||||||
|
s(:int, 33)),
|
||||||
|
s(:receiver,
|
||||||
|
s(:name, "var")))]))])
|
10
test/cases/conditional/if_end.tst
Normal file
10
test/cases/conditional/if_end.tst
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
if(0)
|
||||||
|
42
|
||||||
|
end
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:if,
|
||||||
|
s(:condition,
|
||||||
|
s(:int, 0)),
|
||||||
|
s(:if_true,
|
||||||
|
s(:int, 42)),
|
||||||
|
s(:if_false, nil))])
|
17
test/cases/conditional/if_end_expressions.tst
Normal file
17
test/cases/conditional/if_end_expressions.tst
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
if(3 > var)
|
||||||
|
Object.initialize(3)
|
||||||
|
end
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:if,
|
||||||
|
s(:condition,
|
||||||
|
s(:operator, ">",
|
||||||
|
s(:int, 3),
|
||||||
|
s(:name, "var"))),
|
||||||
|
s(:if_true,
|
||||||
|
s(:call,
|
||||||
|
s(:name, "initialize"),
|
||||||
|
s(:arguments,
|
||||||
|
s(:int, 3)),
|
||||||
|
s(:receiver,
|
||||||
|
s(:module, "Object")))),
|
||||||
|
s(:if_false, nil))])
|
5
test/cases/expressions/assignment.tst
Normal file
5
test/cases/expressions/assignment.tst
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
a = 5
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:assign,
|
||||||
|
s(:name, "a"),
|
||||||
|
s(:int, 5))])
|
5
test/cases/expressions/assignment_instance.tst
Normal file
5
test/cases/expressions/assignment_instance.tst
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
a = 5
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:assign,
|
||||||
|
s(:name, "a"),
|
||||||
|
s(:int, 5))])
|
5
test/cases/expressions/op_two_variable.tst
Normal file
5
test/cases/expressions/op_two_variable.tst
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
a - b
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:operator, "-",
|
||||||
|
s(:name, "a"),
|
||||||
|
s(:name, "b"))])
|
5
test/cases/expressions/op_variable.tst
Normal file
5
test/cases/expressions/op_variable.tst
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
a - 5
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:operator, "-",
|
||||||
|
s(:name, "a"),
|
||||||
|
s(:int, 5))])
|
5
test/cases/expressions/op_variable_string.tst
Normal file
5
test/cases/expressions/op_variable_string.tst
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
a - "st"
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:operator, "-",
|
||||||
|
s(:name, "a"),
|
||||||
|
s(:string, "st"))])
|
5
test/cases/expressions/op_variable_true.tst
Normal file
5
test/cases/expressions/op_variable_true.tst
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
a == true
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:operator, "==",
|
||||||
|
s(:name, "a"),
|
||||||
|
s(:true))])
|
5
test/cases/expressions/simple_devide.tst
Normal file
5
test/cases/expressions/simple_devide.tst
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
5 / 3
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:operator, "/",
|
||||||
|
s(:int, 5),
|
||||||
|
s(:int, 3))])
|
5
test/cases/expressions/simple_greater.tst
Normal file
5
test/cases/expressions/simple_greater.tst
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
5 > 3
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:operator, ">",
|
||||||
|
s(:int, 5),
|
||||||
|
s(:int, 3))])
|
5
test/cases/expressions/simple_minus.tst
Normal file
5
test/cases/expressions/simple_minus.tst
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
5 - 3
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:operator, "-",
|
||||||
|
s(:int, 5),
|
||||||
|
s(:int, 3))])
|
5
test/cases/expressions/simple_multiply.tst
Normal file
5
test/cases/expressions/simple_multiply.tst
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
5 * 3
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:operator, "*",
|
||||||
|
s(:int, 5),
|
||||||
|
s(:int, 3))])
|
5
test/cases/expressions/simple_plus.tst
Normal file
5
test/cases/expressions/simple_plus.tst
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
5 + 3
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:operator, "+",
|
||||||
|
s(:int, 5),
|
||||||
|
s(:int, 3))])
|
5
test/cases/expressions/simple_smaller.tst
Normal file
5
test/cases/expressions/simple_smaller.tst
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
5 < 3
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:operator, "<",
|
||||||
|
s(:int, 5),
|
||||||
|
s(:int, 3))])
|
7
test/cases/expressions/two_different_ops.tst
Normal file
7
test/cases/expressions/two_different_ops.tst
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
2 + 3 * 4
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:operator, "+",
|
||||||
|
s(:int, 2),
|
||||||
|
s(:operator, "*",
|
||||||
|
s(:int, 3),
|
||||||
|
s(:int, 4)))])
|
7
test/cases/expressions/two_different_ops_order.tst
Normal file
7
test/cases/expressions/two_different_ops_order.tst
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
2 * 3 + 4
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:operator, "+",
|
||||||
|
s(:operator, "*",
|
||||||
|
s(:int, 2),
|
||||||
|
s(:int, 3)),
|
||||||
|
s(:int, 4))])
|
7
test/cases/expressions/two_same_ops.tst
Normal file
7
test/cases/expressions/two_same_ops.tst
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
2 + 3 + 4
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:operator, "+",
|
||||||
|
s(:operator, "+",
|
||||||
|
s(:int, 2),
|
||||||
|
s(:int, 3)),
|
||||||
|
s(:int, 4))])
|
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)))])
|
7
test/cases/module_def/module_assign_var.tst
Normal file
7
test/cases/module_def/module_assign_var.tst
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
module Opers
|
||||||
|
abba = 5
|
||||||
|
end
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:module, "Opers", [s(:assign,
|
||||||
|
s(:name, "abba"),
|
||||||
|
s(:int, 5))])])
|
11
test/cases/module_def/module_class.tst
Normal file
11
test/cases/module_def/module_class.tst
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
module Foo
|
||||||
|
class Bar
|
||||||
|
funcall(3 , var)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:module, "Foo", [s(:class, "Bar", nil, [s(:call,
|
||||||
|
s(:name, "funcall"),
|
||||||
|
s(:arguments,
|
||||||
|
s(:int, 3),
|
||||||
|
s(:name, "var")))])])])
|
19
test/cases/module_def/module_function.tst
Normal file
19
test/cases/module_def/module_function.tst
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
module Soho
|
||||||
|
ofthen(3 , var)
|
||||||
|
int ofthen(int n,ref m )
|
||||||
|
return 44
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:module, "Soho", [s(:call,
|
||||||
|
s(:name, "ofthen"),
|
||||||
|
s(:arguments,
|
||||||
|
s(:int, 3),
|
||||||
|
s(:name, "var"))), s(:function, :int,
|
||||||
|
s(:name, "ofthen"),
|
||||||
|
s(:parameters,
|
||||||
|
s(:field, :int, :n),
|
||||||
|
s(:field, :ref, :m)),
|
||||||
|
s(:expressions,
|
||||||
|
s(:return,
|
||||||
|
s(:int, 44))))])])
|
25
test/cases/module_def/module_if.tst
Normal file
25
test/cases/module_def/module_if.tst
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
module Foo
|
||||||
|
ref ofthen(int n)
|
||||||
|
if(0)
|
||||||
|
isit = 42
|
||||||
|
else
|
||||||
|
maybenot = 667
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:module, "Foo", [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))]))))])])
|
20
test/cases/module_def/module_ops.tst
Normal file
20
test/cases/module_def/module_ops.tst
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
module Opers
|
||||||
|
int foo(int x)
|
||||||
|
int abba = 5
|
||||||
|
return abba + 5
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:module, "Opers", [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(:return,
|
||||||
|
s(:operator, "+",
|
||||||
|
s(:name, "abba"),
|
||||||
|
s(:int, 5)))))])])
|
5
test/cases/module_def/simplest_module.tst
Normal file
5
test/cases/module_def/simplest_module.tst
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
module Simple
|
||||||
|
5
|
||||||
|
end
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:module, "Simple", [s(:int, 5)])])
|
4
test/cases/return/return_int.tst
Normal file
4
test/cases/return/return_int.tst
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
return 42
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:return,
|
||||||
|
s(:int, 42))])
|
4
test/cases/return/return_string.tst
Normal file
4
test/cases/return/return_string.tst
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
return "hello"
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:return,
|
||||||
|
s(:string, "hello"))])
|
4
test/cases/return/return_variable.tst
Normal file
4
test/cases/return/return_variable.tst
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
return foo
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:return,
|
||||||
|
s(:name, "foo"))])
|
11
test/cases/root/class_method.tst
Normal file
11
test/cases/root/class_method.tst
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
class FooBo
|
||||||
|
Bar.call(35)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:class, "FooBo", nil, [s(:call,
|
||||||
|
s(:name, "call"),
|
||||||
|
s(:arguments,
|
||||||
|
s(:int, 35)),
|
||||||
|
s(:receiver,
|
||||||
|
s(:module, "Bar")))])])
|
17
test/cases/root/double_root.tst
Normal file
17
test/cases/root/double_root.tst
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
int foo(ref x)
|
||||||
|
a = 5
|
||||||
|
end
|
||||||
|
|
||||||
|
foo( 3 )
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:function, :int,
|
||||||
|
s(:name, "foo"),
|
||||||
|
s(:parameters,
|
||||||
|
s(:field, :ref, :x)),
|
||||||
|
s(:expressions,
|
||||||
|
s(:assign,
|
||||||
|
s(:name, "a"),
|
||||||
|
s(:int, 5)))), s(:call,
|
||||||
|
s(:name, "foo"),
|
||||||
|
s(:arguments,
|
||||||
|
s(:int, 3)))])
|
54
test/cases/root/fibo1.tst
Normal file
54
test/cases/root/fibo1.tst
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
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
|
||||||
|
|
||||||
|
fibonaccit( 10 )
|
||||||
|
-- -- --
|
||||||
|
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))))))), s(:call,
|
||||||
|
s(:name, "fibonaccit"),
|
||||||
|
s(:arguments,
|
||||||
|
s(:int, 10)))])
|
16
test/cases/root/module_assignment.tst
Normal file
16
test/cases/root/module_assignment.tst
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
module Fibo
|
||||||
|
a = 5 + foo
|
||||||
|
bar( b , a , r)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:module, "Fibo", [s(:assign,
|
||||||
|
s(:name, "a"),
|
||||||
|
s(:operator, "+",
|
||||||
|
s(:int, 5),
|
||||||
|
s(:name, "foo"))), s(:call,
|
||||||
|
s(:name, "bar"),
|
||||||
|
s(:arguments,
|
||||||
|
s(:name, "b"),
|
||||||
|
s(:name, "a"),
|
||||||
|
s(:name, "r")))])])
|
24
test/cases/root/module_method.tst
Normal file
24
test/cases/root/module_method.tst
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
module Fibo
|
||||||
|
int fibonaccit(int n)
|
||||||
|
int a = 0
|
||||||
|
return a
|
||||||
|
end
|
||||||
|
|
||||||
|
fibonaccit( 10 )
|
||||||
|
end
|
||||||
|
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:module, "Fibo", [s(:function, :int,
|
||||||
|
s(:name, "fibonaccit"),
|
||||||
|
s(:parameters,
|
||||||
|
s(:field, :int, :n)),
|
||||||
|
s(:expressions,
|
||||||
|
s(:name, "int"),
|
||||||
|
s(:assign,
|
||||||
|
s(:name, "a"),
|
||||||
|
s(:int, 0)),
|
||||||
|
s(:return,
|
||||||
|
s(:name, "a")))), s(:call,
|
||||||
|
s(:name, "fibonaccit"),
|
||||||
|
s(:arguments,
|
||||||
|
s(:int, 10)))])])
|
12
test/cases/root/root_module_class.tst
Normal file
12
test/cases/root/root_module_class.tst
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
module FooBo
|
||||||
|
class Bar
|
||||||
|
a = 5 + foo
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:module, "FooBo", [s(:class, "Bar", nil, [s(:assign,
|
||||||
|
s(:name, "a"),
|
||||||
|
s(:operator, "+",
|
||||||
|
s(:int, 5),
|
||||||
|
s(:name, "foo")))])])])
|
34
test/cases/while/big_while.tst
Normal file
34
test/cases/while/big_while.tst
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
while( n > 1)
|
||||||
|
tmp = a
|
||||||
|
a = b
|
||||||
|
b = tmp + b
|
||||||
|
puts(b)
|
||||||
|
n = n - 1
|
||||||
|
end
|
||||||
|
-- -- --
|
||||||
|
s(:list, [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)))))])
|
16
test/cases/while/while.tst
Normal file
16
test/cases/while/while.tst
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
while(1)
|
||||||
|
tmp = a
|
||||||
|
puts(b)
|
||||||
|
end
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:while,
|
||||||
|
s(:condition,
|
||||||
|
s(:int, 1)),
|
||||||
|
s(:expressions,
|
||||||
|
s(:assign,
|
||||||
|
s(:name, "tmp"),
|
||||||
|
s(:name, "a")),
|
||||||
|
s(:call,
|
||||||
|
s(:name, "puts"),
|
||||||
|
s(:arguments,
|
||||||
|
s(:name, "b")))))])
|
22
test/cases/while/while_method.tst
Normal file
22
test/cases/while/while_method.tst
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
while(1)
|
||||||
|
tmp = String.new()
|
||||||
|
tmp.puts(i)
|
||||||
|
end
|
||||||
|
-- -- --
|
||||||
|
s(:list, [s(:while,
|
||||||
|
s(:condition,
|
||||||
|
s(:int, 1)),
|
||||||
|
s(:expressions,
|
||||||
|
s(:assign,
|
||||||
|
s(:name, "tmp"),
|
||||||
|
s(:call,
|
||||||
|
s(:name, "new"),
|
||||||
|
s(:arguments),
|
||||||
|
s(:receiver,
|
||||||
|
s(:module, "String")))),
|
||||||
|
s(:call,
|
||||||
|
s(:name, "puts"),
|
||||||
|
s(:arguments,
|
||||||
|
s(:name, "i")),
|
||||||
|
s(:receiver,
|
||||||
|
s(:name, "tmp")))))])
|
@ -1,18 +1,14 @@
|
|||||||
require_relative "setup"
|
require_relative "setup"
|
||||||
require "parslet/convenience"
|
require "parslet/convenience"
|
||||||
|
|
||||||
# remove the line numbers on assert fails, so it's easy to copy paste the result as the expected result
|
|
||||||
Parslet::Slice.class_eval do
|
|
||||||
def inspect
|
# Older test harness
|
||||||
'"' + to_s + '"'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
# Included in parser test will create tests methods
|
|
||||||
module ParserHelper
|
module ParserHelper
|
||||||
|
|
||||||
def self.included(base)
|
def self.included(base)
|
||||||
base.send :include, InstanceMethods #provides helpers and setup
|
base.send :include, InstanceMethods #provides helpers and setup
|
||||||
base.send :include, AST::Sexp
|
base.send :include, AST::if_true
|
||||||
base.send :extend, ClassMethods #gets the method creation going
|
base.send :extend, ClassMethods #gets the method creation going
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -39,11 +35,36 @@ module ParserHelper
|
|||||||
def check_ast
|
def check_ast
|
||||||
syntax = @parser.parse(@string_input)
|
syntax = @parser.parse(@string_input)
|
||||||
is = @transform.apply(syntax)
|
is = @transform.apply(syntax)
|
||||||
#puts is.inspect
|
puts is.inspect
|
||||||
assert_equal @transform_output , is
|
assert_equal @transform_output , is
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def check_write test
|
||||||
|
dirname = decamelize(self.class.name)[10 .. -1]
|
||||||
|
test = test[5 .. -1]
|
||||||
|
syntax = @parser.parse_with_debug(@string_input)
|
||||||
|
out = Parser::Transform.new.apply(syntax).inspect
|
||||||
|
dir = File.dirname(__FILE__) + "/" + dirname
|
||||||
|
FileUtils.mkdir_p(dir) unless File.exists?(dir)
|
||||||
|
out_file = File.new(dir + "/" + test + ".tst", "w")
|
||||||
|
out_file.puts @string_input
|
||||||
|
out_file.puts "-- -- --"
|
||||||
|
out_file.puts out
|
||||||
|
out_file.close
|
||||||
|
end
|
||||||
|
|
||||||
|
def decamelize str
|
||||||
|
str.gsub(/(^|[a-z])([A-Z])/) do
|
||||||
|
($1.empty?)? $2 : "#{$1}_#{$2}"
|
||||||
|
end.downcase
|
||||||
|
end
|
||||||
|
|
||||||
|
def camelize str
|
||||||
|
str.gsub(/(^|_)([a-z])/) { $2.upcase }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
module ClassMethods
|
module ClassMethods
|
||||||
# this creates test methods dynamically. For each test_* method we create
|
# this creates test methods dynamically. For each test_* method we create
|
||||||
# three test_*[ast/parse/transf] methods that in turn check the three phases.
|
# three test_*[ast/parse/transf] methods that in turn check the three phases.
|
||||||
@ -51,12 +72,12 @@ module ParserHelper
|
|||||||
def runnable_methods
|
def runnable_methods
|
||||||
tests = []
|
tests = []
|
||||||
public_instance_methods(true).grep(/^test_/).map(&:to_s).each do |test|
|
public_instance_methods(true).grep(/^test_/).map(&:to_s).each do |test|
|
||||||
["ast" , "transform" , "parse"].each do |what|
|
["write"].each do |what|
|
||||||
name = "#{test}_#{what}"
|
name = "#{test}_#{what}"
|
||||||
tests << name
|
tests << name
|
||||||
self.send(:define_method, name ) do
|
self.send(:define_method, name ) do
|
||||||
send(test)
|
send(test)
|
||||||
send("check_#{what}")
|
send("check_#{what}" , test)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,2 +1,32 @@
|
|||||||
require_relative "unit/test_all"
|
require_relative "setup"
|
||||||
require_relative "roots/test_all"
|
require "parslet/convenience"
|
||||||
|
require "ast/sexp"
|
||||||
|
|
||||||
|
class TestAll < MiniTest::Test
|
||||||
|
include AST::Sexp
|
||||||
|
|
||||||
|
def check_file file
|
||||||
|
inn , out = File.new(file).read.split("-- -- --")
|
||||||
|
sexp = eval(out)
|
||||||
|
syntax = Parser::Salama.new.parse_with_debug(inn)
|
||||||
|
result = Parser::Transform.new.apply(syntax)
|
||||||
|
assert_equal sexp , result
|
||||||
|
end
|
||||||
|
# this creates test methods dynamically. For each test_* method we create
|
||||||
|
# three test_*[ast/parse/transf] methods that in turn check the three phases.
|
||||||
|
# runnable_methods is called by minitest to determine which tests to run
|
||||||
|
def self.runnable_methods
|
||||||
|
puts "called"
|
||||||
|
all = Dir["test/cases/*/*.tst"]
|
||||||
|
puts "case #{all.length}"
|
||||||
|
tests =[]
|
||||||
|
all.each do |file|
|
||||||
|
name = file.sub("test/cases/","").sub("/","_").sub(".tst","")
|
||||||
|
tests << name
|
||||||
|
self.send(:define_method, name ) do
|
||||||
|
send("check_file" , file)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
tests
|
||||||
|
end
|
||||||
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user