2019-08-06 17:33:27 +02:00
|
|
|
|
|
|
|
require_relative "helper"
|
|
|
|
|
|
|
|
module Vool
|
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-08-08 11:18:36 +02:00
|
|
|
@vool = ruby_tree.to_vool
|
|
|
|
end
|
|
|
|
def test_class
|
2019-08-19 13:33:02 +02:00
|
|
|
assert_equal ClassExpression , @vool.class
|
2019-09-12 21:27:10 +02:00
|
|
|
assert_equal :Test , @vool.name
|
2019-08-08 11:18:36 +02:00
|
|
|
end
|
|
|
|
def test_method
|
2019-08-19 13:33:02 +02:00
|
|
|
assert_equal MethodExpression , @vool.body.first.class
|
2019-08-08 11:18:36 +02:00
|
|
|
end
|
|
|
|
def test_create_class
|
|
|
|
assert_equal Parfait::Class , @vool.create_class_object.class
|
|
|
|
end
|
|
|
|
def test_create_class
|
2019-09-24 14:44:33 +02:00
|
|
|
assert_equal :Test , @vool.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-09-24 14:44:33 +02:00
|
|
|
assert_equal :a , @vool.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
|
|
|
|
assert_tos "class Test < Object;def main(arg);@a = 5;return @a;end;end" , @vool
|
|
|
|
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-08-17 14:58:27 +02:00
|
|
|
vool = ruby_tree.to_vool
|
2019-08-19 13:33:02 +02:00
|
|
|
assert_equal ClassExpression , vool.class
|
2019-09-24 14:44:33 +02:00
|
|
|
clazz = vool.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
|
|
|
|
vool_tree = Ruby::RubyCompiler.compile( space_test).to_vool
|
|
|
|
assert_raises {vool_tree.to_parfait}
|
2019-08-06 17:33:27 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|