rubyx/test/parfait/test_callable_method.rb

114 lines
3.5 KiB
Ruby
Raw Normal View History

2018-04-26 11:31:37 +02:00
require_relative "helper"
2015-09-27 15:06:48 +02:00
2018-04-26 11:31:37 +02:00
module Parfait
class TestMethod < ParfaitTest
2015-09-27 15:06:48 +02:00
2018-04-26 11:31:37 +02:00
def setup
super
2018-07-07 14:50:43 +02:00
make_method
2018-04-26 11:31:37 +02:00
end
2015-09-27 15:06:48 +02:00
2018-04-26 11:31:37 +02:00
def test_method_name
assert_equal :meth , @method.name
end
2018-04-26 11:31:37 +02:00
def test_class_for
assert_equal :Object , @method.self_type.object_class.name
2018-04-26 11:31:37 +02:00
end
2015-09-27 15:06:48 +02:00
2018-04-26 11:31:37 +02:00
def test_arg1
assert_equal 3 , @method.arguments_type.get_length , @method.arguments_type.inspect
2018-04-26 11:31:37 +02:00
assert_equal Symbol , @method.arguments_type.names.first.class
assert_equal :bar , @method.arguments_type.name_at(1)
2018-04-26 11:31:37 +02:00
end
2018-04-26 11:31:37 +02:00
def test_has_argument
assert_equal 1 , @method.arguments_type.variable_index(:bar)
assert_equal 2 , @method.arguments_type.variable_index(:foo)
2018-04-26 11:31:37 +02:00
end
2018-04-26 11:31:37 +02:00
def test_add_arg
@method.arguments_type.send( :private_add_instance_variable, :foo2 , :Object)
assert_equal 4 , @method.arguments_type.get_length
assert_equal :foo2 , @method.arguments_type.name_at(3)
assert_equal :Object , @method.arguments_type.type_at(3)
2018-04-26 11:31:37 +02:00
end
2018-04-26 11:31:37 +02:00
def test_get_arg_name1
index = @method.arguments_type.variable_index(:bar)
assert_equal 1 , index
assert_equal :bar , @method.arguments_type.name_at(index)
2018-04-26 11:31:37 +02:00
end
def test_get_arg_type1
index = @method.arguments_type.variable_index(:bar)
assert_equal :Integer , @method.arguments_type.type_at(index)
2018-04-26 11:31:37 +02:00
end
def test_get_arg_name2
index = @method.arguments_type.variable_index(:foo)
assert_equal 2 , index
assert_equal :foo , @method.arguments_type.name_at(index)
2018-04-26 11:31:37 +02:00
end
def test_get_arg_type2
index = @method.arguments_type.variable_index(:foo)
assert_equal :Type , @method.arguments_type.type_at(index)
2018-04-26 11:31:37 +02:00
end
2018-04-26 11:31:37 +02:00
def test_local1
assert_equal 3 , @method.frame_type.get_length , @method.frame_type.inspect
2018-04-26 11:31:37 +02:00
assert_equal Symbol , @method.frame_type.names.first.class
assert_equal :local_bar , @method.frame_type.name_at(1)
2018-04-26 11:31:37 +02:00
end
2018-04-26 11:31:37 +02:00
def test_has_local
assert_equal 1 , @method.has_local(:local_bar)
assert_equal 2 , @method.has_local(:local_foo)
2018-04-26 11:31:37 +02:00
end
2018-04-26 11:31:37 +02:00
def test_add_local
@method.add_local(:foo2 , :Object)
assert_equal 4 , @method.frame_type.get_length
assert_equal :foo2 , @method.frame_type.name_at(3)
assert_equal :Object , @method.frame_type.type_at(3)
2018-04-26 11:31:37 +02:00
end
2018-04-26 11:31:37 +02:00
def test_get_locals_name1
index = @method.has_local(:local_bar)
assert_equal 1 , index
assert_equal :local_bar , @method.frame_type.name_at(index)
2018-04-26 11:31:37 +02:00
end
def test_get_frame_type1
index = @method.has_local(:local_bar)
assert_equal :Integer , @method.frame_type.type_at(index)
2018-04-26 11:31:37 +02:00
end
def test_get_locals_name2
index = @method.has_local(:local_foo)
assert_equal 2 , index
assert_equal :local_foo , @method.frame_type.name_at(index)
2018-04-26 11:31:37 +02:00
end
def test_get_frame_type2
index = @method.has_local(:local_bar)
assert_equal :Integer , @method.frame_type.type_at(index)
2018-04-26 11:31:37 +02:00
end
def test_created_with_binary
assert @method.binary
end
def test_equal
assert_equal @method , @method
end
def test_not_equal
method = Parfait::CallableMethod.new( :other , @obj , @args , @frame)
assert @method != method
end
2018-07-27 09:48:45 +02:00
def test_create_block
@block = @method.create_block(@args , @frame)
assert_equal Block , @block.class
end
def test_has_block
assert_equal 7 , @method.get_type.variable_index( :blocks )
end
def test_has_name
assert_equal 6 , @method.get_type.variable_index( :name )
end
end
2015-09-27 15:06:48 +02:00
end