2019-08-08 11:18:36 +02:00
|
|
|
require_relative "helper"
|
|
|
|
|
2019-10-03 23:36:49 +02:00
|
|
|
module Sol
|
2019-09-24 16:25:19 +02:00
|
|
|
class TestMethodExpression < MiniTest::Test
|
2019-10-03 23:36:49 +02:00
|
|
|
include SolCompile
|
2019-08-08 11:18:36 +02:00
|
|
|
|
|
|
|
def setup
|
|
|
|
Parfait.boot!(Parfait.default_test_options)
|
2019-09-12 12:10:31 +02:00
|
|
|
ruby_tree = Ruby::RubyCompiler.compile( as_main("a = 5") )
|
2019-10-03 23:36:49 +02:00
|
|
|
@clazz = ruby_tree.to_sol
|
2019-08-08 11:18:36 +02:00
|
|
|
end
|
|
|
|
def method
|
|
|
|
@clazz.body.first
|
|
|
|
end
|
|
|
|
def test_setup
|
2019-08-19 13:33:02 +02:00
|
|
|
assert_equal ClassExpression , @clazz.class
|
2019-08-08 11:18:36 +02:00
|
|
|
assert_equal Statements , @clazz.body.class
|
2019-08-19 13:33:02 +02:00
|
|
|
assert_equal MethodExpression , method.class
|
2019-08-08 11:18:36 +02:00
|
|
|
end
|
2019-09-24 14:44:33 +02:00
|
|
|
def test_fail
|
|
|
|
assert_raises{ method.to_parfait }
|
2019-08-08 11:18:36 +02:00
|
|
|
end
|
|
|
|
def test_method
|
2019-09-24 20:20:12 +02:00
|
|
|
assert_equal Parfait::Class , @clazz.to_parfait.class
|
2019-09-24 16:25:19 +02:00
|
|
|
end
|
2019-09-29 21:37:28 +02:00
|
|
|
def test_creates_instance_method
|
2019-09-24 20:20:12 +02:00
|
|
|
main = @clazz.to_parfait.get_instance_method(:main)
|
2019-10-03 23:36:49 +02:00
|
|
|
assert_equal Parfait::SolMethod , main.class
|
2019-09-24 20:20:12 +02:00
|
|
|
assert_equal :main , main.name
|
2019-08-08 11:18:36 +02:00
|
|
|
end
|
2019-09-29 21:37:28 +02:00
|
|
|
def test_creates_type_method
|
|
|
|
clazz = @clazz.to_parfait
|
|
|
|
m = clazz.instance_type.get_method(:main)
|
|
|
|
assert m , "no type method :main"
|
|
|
|
end
|
2019-08-08 11:18:36 +02:00
|
|
|
|
|
|
|
end
|
2019-09-24 20:20:12 +02:00
|
|
|
class TestMethodExpressionDoubleDef < MiniTest::Test
|
2019-10-03 23:36:49 +02:00
|
|
|
include SolCompile
|
2019-09-24 20:20:12 +02:00
|
|
|
|
|
|
|
def setup
|
|
|
|
Parfait.boot!(Parfait.default_test_options)
|
|
|
|
ruby_tree = Ruby::RubyCompiler.compile( as_main("a = 5") + ";" + as_main("a = 5") )
|
2019-10-03 23:36:49 +02:00
|
|
|
@clazz = ruby_tree.to_sol
|
2019-09-24 20:20:12 +02:00
|
|
|
end
|
|
|
|
def method
|
|
|
|
@clazz.body.first
|
|
|
|
end
|
|
|
|
def test_no_double
|
|
|
|
assert_raises {@clazz.to_parfait}
|
|
|
|
end
|
|
|
|
end
|
2019-08-08 11:18:36 +02:00
|
|
|
end
|