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
|
2016-12-13 17:47:44 +01:00
|
|
|
|
2018-04-26 11:31:37 +02:00
|
|
|
def test_class_for
|
2018-07-06 19:01:17 +02:00
|
|
|
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
|
2018-05-14 15:13:50 +02:00
|
|
|
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
|
2018-05-14 15:13:50 +02:00
|
|
|
assert_equal :bar , @method.arguments_type.name_at(1)
|
2018-04-26 11:31:37 +02:00
|
|
|
end
|
2016-12-13 17:47:44 +01:00
|
|
|
|
2018-04-26 11:31:37 +02:00
|
|
|
def test_has_argument
|
2018-05-14 15:13:50 +02:00
|
|
|
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
|
2016-12-13 17:47:44 +01:00
|
|
|
|
2018-04-26 11:31:37 +02:00
|
|
|
def test_add_arg
|
2018-05-14 15:13:50 +02:00
|
|
|
@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
|
2016-12-13 17:47:44 +01:00
|
|
|
|
2018-04-26 11:31:37 +02:00
|
|
|
def test_get_arg_name1
|
2018-05-14 15:13:50 +02:00
|
|
|
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
|
2018-05-14 15:13:50 +02:00
|
|
|
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
|
2018-05-14 15:13:50 +02:00
|
|
|
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
|
2018-05-14 15:13:50 +02:00
|
|
|
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
|
2016-12-13 18:18:17 +01:00
|
|
|
|
2018-04-26 11:31:37 +02:00
|
|
|
def test_local1
|
2018-05-14 19:50:52 +02:00
|
|
|
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
|
2018-05-14 19:50:52 +02:00
|
|
|
assert_equal :local_bar , @method.frame_type.name_at(1)
|
2018-04-26 11:31:37 +02:00
|
|
|
end
|
2016-12-13 18:18:17 +01:00
|
|
|
|
2018-04-26 11:31:37 +02:00
|
|
|
def test_has_local
|
2018-05-14 19:50:52 +02:00
|
|
|
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
|
2016-12-13 18:18:17 +01:00
|
|
|
|
2018-04-26 11:31:37 +02:00
|
|
|
def test_add_local
|
|
|
|
@method.add_local(:foo2 , :Object)
|
2018-05-14 19:50:52 +02:00
|
|
|
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
|
2016-12-13 18:18:17 +01:00
|
|
|
|
2018-04-26 11:31:37 +02:00
|
|
|
def test_get_locals_name1
|
|
|
|
index = @method.has_local(:local_bar)
|
2018-05-14 19:50:52 +02:00
|
|
|
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)
|
2018-05-14 19:50:52 +02:00
|
|
|
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)
|
2018-05-14 19:50:52 +02:00
|
|
|
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)
|
2018-05-14 19:50:52 +02:00
|
|
|
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
|
2018-07-04 07:28:05 +02:00
|
|
|
def test_equal
|
|
|
|
assert_equal @method , @method
|
|
|
|
end
|
|
|
|
def test_not_equal
|
2018-07-30 09:21:43 +02:00
|
|
|
method = Parfait::CallableMethod.new( :other , @obj , @args , @frame)
|
2018-07-04 07:28:05 +02:00
|
|
|
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
|
2018-07-30 09:21:43 +02:00
|
|
|
def test_has_name
|
|
|
|
assert_equal 6 , @method.get_type.variable_index( :name )
|
|
|
|
end
|
2018-03-28 11:49:17 +02:00
|
|
|
end
|
2015-09-27 15:06:48 +02:00
|
|
|
end
|