2019-08-06 17:33:27 +02:00
|
|
|
|
|
|
|
require_relative "helper"
|
|
|
|
|
2019-10-03 23:36:49 +02:00
|
|
|
module Sol
|
2019-09-24 16:25:19 +02:00
|
|
|
class TestClassStatement < MiniTest::Test
|
2019-08-08 11:18:36 +02:00
|
|
|
include ScopeHelper
|
|
|
|
def setup
|
2019-08-17 14:58:27 +02:00
|
|
|
Parfait.boot!(Parfait.default_test_options)
|
2019-09-12 21:27:10 +02:00
|
|
|
ruby_tree = Ruby::RubyCompiler.compile( as_test_main("@a = 5") )
|
2019-10-03 23:36:49 +02:00
|
|
|
@sol = ruby_tree.to_sol
|
2019-08-08 11:18:36 +02:00
|
|
|
end
|
|
|
|
def test_class
|
2019-10-03 23:36:49 +02:00
|
|
|
assert_equal ClassExpression , @sol.class
|
|
|
|
assert_equal :Test , @sol.name
|
2019-08-08 11:18:36 +02:00
|
|
|
end
|
|
|
|
def test_method
|
2019-10-03 23:36:49 +02:00
|
|
|
assert_equal MethodExpression , @sol.body.first.class
|
2019-08-08 11:18:36 +02:00
|
|
|
end
|
|
|
|
def test_create_class
|
2019-10-03 23:36:49 +02:00
|
|
|
assert_equal Parfait::Class , @sol.create_class_object.class
|
2019-08-08 11:18:36 +02:00
|
|
|
end
|
|
|
|
def test_create_class
|
2019-10-03 23:36:49 +02:00
|
|
|
assert_equal :Test , @sol.to_parfait.name
|
2019-08-08 11:18:36 +02:00
|
|
|
end
|
2019-08-17 14:58:27 +02:00
|
|
|
def test_class_instance
|
2019-10-03 23:36:49 +02:00
|
|
|
assert_equal :a , @sol.to_parfait.instance_type.names[1]
|
2019-08-17 14:58:27 +02:00
|
|
|
end
|
2019-10-02 16:42:24 +02:00
|
|
|
def test_to_s
|
2019-10-03 23:36:49 +02:00
|
|
|
assert_tos "class Test < Object;def main(arg);@a = 5;return @a;end;end" , @sol
|
2019-10-02 16:42:24 +02:00
|
|
|
end
|
2019-08-17 14:58:27 +02:00
|
|
|
end
|
2019-09-24 16:25:19 +02:00
|
|
|
class TestClassStatementTypeCreation < MiniTest::Test
|
2019-08-17 14:58:27 +02:00
|
|
|
include ScopeHelper
|
|
|
|
def setup
|
|
|
|
Parfait.boot!(Parfait.default_test_options)
|
|
|
|
end
|
2019-09-12 21:27:10 +02:00
|
|
|
def check_type_for(input)
|
|
|
|
ruby_tree = Ruby::RubyCompiler.compile( as_test_main(input) )
|
2019-10-03 23:36:49 +02:00
|
|
|
sol = ruby_tree.to_sol
|
|
|
|
assert_equal ClassExpression , sol.class
|
|
|
|
clazz = sol.to_parfait
|
2019-08-17 14:58:27 +02:00
|
|
|
assert_equal Parfait::Class , clazz.class
|
|
|
|
assert_equal :a , clazz.instance_type.names[1]
|
|
|
|
end
|
|
|
|
def test_while_cond
|
2019-09-12 21:27:10 +02:00
|
|
|
check_type_for("while(@a) ; 1 == 1 ; end")
|
2019-08-17 14:58:27 +02:00
|
|
|
end
|
|
|
|
def test_while_cond_eq
|
2019-09-12 21:27:10 +02:00
|
|
|
check_type_for("while(@a==1); 1 == 1 ; end")
|
2019-08-17 14:58:27 +02:00
|
|
|
end
|
|
|
|
def test_if_cond
|
2019-09-12 21:27:10 +02:00
|
|
|
check_type_for("if(@a); 1 == 1 ; end")
|
2019-08-17 14:58:27 +02:00
|
|
|
end
|
|
|
|
def test_send_1
|
2019-09-12 21:27:10 +02:00
|
|
|
check_type_for("@a.call")
|
2019-08-17 14:58:27 +02:00
|
|
|
end
|
|
|
|
def test_send_arg
|
2019-09-12 21:27:10 +02:00
|
|
|
check_type_for("call(@a)")
|
2019-08-17 14:58:27 +02:00
|
|
|
end
|
|
|
|
def test_return
|
2019-09-12 21:27:10 +02:00
|
|
|
check_type_for("return @a")
|
2019-08-17 14:58:27 +02:00
|
|
|
end
|
|
|
|
def test_return_call
|
2019-09-12 21:27:10 +02:00
|
|
|
check_type_for("return call(@a)")
|
2019-08-17 14:58:27 +02:00
|
|
|
end
|
|
|
|
def test_return_rec
|
2019-09-12 21:27:10 +02:00
|
|
|
check_type_for("return @a.call()")
|
2019-08-17 14:58:27 +02:00
|
|
|
end
|
2019-08-08 11:18:36 +02:00
|
|
|
end
|
2019-09-24 14:44:33 +02:00
|
|
|
class TestClassSuperMismatch < MiniTest::Test
|
|
|
|
include ScopeHelper
|
2019-08-06 17:33:27 +02:00
|
|
|
def setup
|
2019-09-24 14:44:33 +02:00
|
|
|
Parfait.boot!(Parfait.default_test_options)
|
2019-08-06 17:33:27 +02:00
|
|
|
end
|
2019-09-24 14:44:33 +02:00
|
|
|
def space_test
|
|
|
|
as_test_main("return 1") + ";class Test < Space ; def main();return 1;end;end"
|
2019-08-06 17:33:27 +02:00
|
|
|
end
|
2019-09-24 14:44:33 +02:00
|
|
|
def test_mismatch
|
2019-10-03 23:36:49 +02:00
|
|
|
sol_tree = Ruby::RubyCompiler.compile( space_test).to_sol
|
|
|
|
assert_raises {sol_tree.to_parfait}
|
2019-08-06 17:33:27 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|