test/test_rubype.rb in rubype-0.2.1 vs test/test_rubype.rb in rubype-0.2.2
- old
+ new
@@ -11,11 +11,11 @@
@symbol = :test
@array = [1, 2, 3]
@hash = { test: :hash }
end
- def test_correct_type
+ def test_correct_type_by_class
assert_correct_type [Numeric => Numeric], [@numeric], @numeric
assert_correct_type [Numeric => Array ], [@numeric], @array
assert_correct_type [Numeric => String ], [@numeric], @string
assert_correct_type [Numeric => Hash ], [@numeric], @hash
assert_correct_type [Numeric => Symbol ], [@numeric], @symbol
@@ -27,10 +27,21 @@
assert_correct_type [Boolean, String => String ], [true, @string ], @string
assert_correct_type [Boolean, Hash => Hash ], [true, @hash ], @hash
assert_correct_type [Boolean, Symbol => Symbol ], [true, @symbol ], @symbol
end
+ def test_correct_type_by_sym
+ assert_correct_type [Numeric => :to_i], [@numeric], @numeric
+ assert_correct_type [Numeric => :to_i], [@numeric], @string
+
+ assert_correct_type [Numeric => :to_s], [@numeric], @numeric
+ assert_correct_type [Numeric => :to_s], [@numeric], @string
+ assert_correct_type [Numeric => :to_s], [@numeric], @symbol
+ assert_correct_type [Numeric => :to_s], [@numeric], @array
+ assert_correct_type [Numeric => :to_s], [@numeric], @hash
+ end
+
def test_wrong_return_type
assert_wrong_rtn [Numeric => Numeric], [@numeric], @array
assert_wrong_rtn [Numeric => Numeric], [@numeric], @string
assert_wrong_rtn [Numeric => Numeric], [@numeric], @hash
assert_wrong_rtn [Numeric => Numeric], [@numeric], @symbol
@@ -39,10 +50,14 @@
assert_wrong_rtn [Numeric, Numeric => Numeric], [@numeric, @numeric], @array
assert_wrong_rtn [Numeric, Numeric => Numeric], [@numeric, @numeric], @string
assert_wrong_rtn [Numeric, Numeric => Numeric], [@numeric, @numeric], @hash
assert_wrong_rtn [Numeric, Numeric => Numeric], [@numeric, @numeric], @symbol
assert_wrong_rtn [Numeric, Numeric => Numeric], [@numeric, @numeric], true
+
+ assert_wrong_rtn [Numeric => :to_i], [@numeric], @symbol
+ assert_wrong_rtn [Numeric => :to_i], [@numeric], @array
+ assert_wrong_rtn [Numeric => :to_i], [@numeric], @hash
end
def test_wrong_args_type
assert_wrong_arg [Numeric => Numeric], [@array ], @numeric
assert_wrong_arg [Numeric => Numeric], [@string], @numeric
@@ -53,10 +68,15 @@
assert_wrong_arg [Numeric, Numeric => Numeric], [@numeric, @array ], @numeric
assert_wrong_arg [Numeric, Numeric => Numeric], [@numeric, @string], @numeric
assert_wrong_arg [Numeric, Numeric => Numeric], [@numeric, @hash ], @numeric
assert_wrong_arg [Numeric, Numeric => Numeric], [@numeric, @symbol], @numeric
assert_wrong_arg [Numeric, Numeric => Numeric], [@numeric, true ], @numeric
+
+ assert_wrong_arg [Numeric => :to_i], [@array ], @numeric
+ assert_wrong_arg [Numeric => :to_i], [@hash ], @numeric
+ assert_wrong_arg [Numeric => :to_i], [@symbol], @numeric
+ assert_wrong_arg [Numeric => :to_i], [true ], @numeric
end
def test_any
assert_correct_type [Any => Any], [@array ], @numeric
assert_correct_type [Any => Any], [@string], @numeric
@@ -77,14 +97,14 @@
def assert_correct_type(type_list, args, val)
assert_equal val, define_test_method(type_list, args, val).call(*args)
end
def assert_wrong_arg(type_list, args, val)
- assert_raises(ArgumentError) { define_test_method(type_list, args, val).call(*args) }
+ assert_raises(Rubype::ArgumentTypeError) { define_test_method(type_list, args, val).call(*args) }
end
def assert_wrong_rtn(type_list, args, val)
- assert_raises(TypeError) { define_test_method(type_list, args, val).call(*args) }
+ assert_raises(Rubype::ReturnTypeError) { define_test_method(type_list, args, val).call(*args) }
end
def define_test_method(type_list, args, val)
klass = Class.new.class_eval <<-RUBY_CODE
def call(#{arg_literal(args.count)})