rubyx/stash/test_rubyx/test_ruby_method.rb

73 lines
1.8 KiB
Ruby
Raw Normal View History

2017-01-12 19:38:04 +01:00
require_relative "helper"
module Rubyx
class TestRubyMethod < MiniTest::Test
2017-01-12 19:38:04 +01:00
include CompilerHelper
def setup
Risc.machine.boot
2017-01-12 19:38:04 +01:00
end
def create_method
2017-08-30 21:35:10 +02:00
Vool::VoolCompiler.compile in_Test("def meth; @ivar ;end")
2017-01-17 20:25:58 +01:00
test = Parfait.object_space.get_class_by_name(:Test)
test.get_method(:meth)
end
2017-08-30 21:27:12 +02:00
def create_method_arg
2017-08-30 21:35:10 +02:00
Vool::VoolCompiler.compile in_Test("def meth_arg(arg); arg ;end")
2017-08-30 21:27:12 +02:00
test = Parfait.object_space.get_class_by_name(:Test)
test.get_method(:meth_arg)
end
def create_method_local
2017-08-30 21:35:10 +02:00
Vool::VoolCompiler.compile in_Test("def meth_local(arg); local = 5 ;end")
2017-08-30 21:27:12 +02:00
test = Parfait.object_space.get_class_by_name(:Test)
2017-08-30 21:35:10 +02:00
test.get_method(:meth_local)
2017-08-30 21:27:12 +02:00
end
def test_creates_method_in_class
method = create_method
2017-01-12 19:38:04 +01:00
assert method , "No method created"
end
def test_method_has_source
method = create_method
2017-08-30 21:35:10 +02:00
assert_equal Vool::ScopeStatement, method.source.class
assert_equal Vool::InstanceVariable, method.source.first.class
end
def test_method_has_no_args
method = create_method
assert_equal 1 , method.args_type.instance_length
end
def test_method_has_no_locals
method = create_method
assert_equal 1 , method.locals_type.instance_length
end
2017-08-30 21:27:12 +02:00
def test_method_has_args
method = create_method_arg
assert_equal 2 , method.args_type.instance_length
end
2017-08-30 21:35:10 +02:00
def test_method_has_locals
2017-08-30 21:27:12 +02:00
method = create_method_local
assert_equal 2 , method.locals_type.instance_length
end
2017-08-30 21:35:10 +02:00
def test_method_create_tmp
name = create_method.create_tmp
2017-08-30 21:54:03 +02:00
assert_equal :tmp_1 , name
2017-08-30 21:35:10 +02:00
end
def test_method_add_tmp
method = create_method_local
method.create_tmp
assert_equal 3 , method.locals_type.instance_length
end
2017-01-12 19:38:04 +01:00
end
end