2019-09-24 16:25:19 +02:00
|
|
|
require_relative "helper"
|
|
|
|
|
2019-10-03 23:36:49 +02:00
|
|
|
module Sol
|
2019-09-24 16:25:19 +02:00
|
|
|
class TestClassMethodExpression < MiniTest::Test
|
2019-10-03 23:36:49 +02:00
|
|
|
include SolCompile
|
2019-09-24 16:25:19 +02:00
|
|
|
|
|
|
|
def class_code
|
2019-09-30 16:09:13 +02:00
|
|
|
"class Space;def self.meth; return meth(22 + 22) ; end;end"
|
2019-09-24 16:25:19 +02:00
|
|
|
end
|
|
|
|
def setup
|
|
|
|
Parfait.boot!(Parfait.default_test_options)
|
|
|
|
ruby_tree = Ruby::RubyCompiler.compile( class_code )
|
2019-10-03 23:36:49 +02:00
|
|
|
@clazz = ruby_tree.to_sol
|
2019-09-24 16:25:19 +02:00
|
|
|
end
|
|
|
|
def method
|
|
|
|
@clazz.body.first
|
|
|
|
end
|
|
|
|
def test_setup
|
|
|
|
assert_equal ClassExpression , @clazz.class
|
|
|
|
assert_equal Statements , @clazz.body.class
|
|
|
|
assert_equal ClassMethodExpression , method.class
|
|
|
|
end
|
|
|
|
def test_fail
|
|
|
|
assert_raises{ method.to_parfait }
|
|
|
|
end
|
2019-09-29 21:37:28 +02:00
|
|
|
def test_creates_class_method
|
2019-09-24 16:25:19 +02:00
|
|
|
clazz = @clazz.to_parfait
|
|
|
|
m = clazz.single_class.get_instance_method(:meth)
|
|
|
|
assert m , "no method :meth"
|
|
|
|
end
|
2019-09-29 21:37:28 +02:00
|
|
|
def test_creates_type_method
|
|
|
|
clazz = @clazz.to_parfait
|
|
|
|
m = clazz.single_class.instance_type.get_method(:meth)
|
|
|
|
assert m , "no type method :meth"
|
|
|
|
end
|
2019-10-03 19:55:41 +02:00
|
|
|
def as_slot
|
2019-09-30 16:09:13 +02:00
|
|
|
@clazz.to_parfait
|
2019-10-03 19:55:41 +02:00
|
|
|
@clazz.to_slot(nil)
|
2019-09-30 16:09:13 +02:00
|
|
|
end
|
2019-10-03 19:55:41 +02:00
|
|
|
def test_slot
|
|
|
|
assert_equal :meth , as_slot.method_compilers.callable.name
|
2019-09-30 16:09:13 +02:00
|
|
|
end
|
2019-10-03 19:55:41 +02:00
|
|
|
def test_slot_frame
|
|
|
|
callable = as_slot.method_compilers.callable
|
2019-09-30 16:09:13 +02:00
|
|
|
assert callable.frame_type.names.last.to_s.start_with?("tmp_") , "no tmp_ variable #{callable.frame_type.names}"
|
|
|
|
end
|
2019-09-24 16:25:19 +02:00
|
|
|
end
|
|
|
|
end
|