@@ -73,6 +73,10 @@ def hash = @key.hash
7373 def eql? ( other ) = HashKey === other && @key . eql? ( other . key )
7474 end
7575
76+ def with_each ( *eles )
77+ yield Each . new ( *eles )
78+ end
79+
7680 def test_op_and
7781 with_array [ 1 r, 1 i] do |other |
7882 assert_send_type '(array[untyped]) -> Array[Rational]' ,
@@ -897,7 +901,26 @@ def test_shuffle!
897901 end
898902
899903 def test_slice!
900- omit 'todo -- non-enumerable'
904+ with_int 1 do |index |
905+ assert_send_type '(int) -> Rational' ,
906+ [ 1 r, 2 r] , :slice! , index
907+ assert_send_type '(int) -> nil' ,
908+ [ 1 r] , :slice! , index
909+ end
910+
911+ with_int 2 do |start |
912+ with_int 1 do |length |
913+ assert_send_type '(int, int) -> Array[Rational]' ,
914+ [ 1 r, 2 r, 3 r] , :slice! , start , length
915+ assert_send_type '(int, int) -> nil' ,
916+ [ 1 r] , :slice! , start , length
917+ end
918+ end
919+
920+ with_range with_int ( 2 ) . and_nil , with_int ( 1 ) . and_nil do |range |
921+ assert_send_type '(range[int?]) -> Array[Rational]?' ,
922+ [ 1 r, 2 r, 3 r] , :slice! , range
923+ end
901924 end
902925
903926 def test_sort
@@ -923,7 +946,33 @@ def test_sort_by!
923946 end
924947
925948 def test_sum
926- omit 'todo -- non-enumerable'
949+ assert_send_type '() -> untyped' ,
950+ [ 1 , 2 r, 3.0 , 4 i] , :sum
951+
952+ with 5 , 6 r, 7.0 , 8 i do |init |
953+ assert_send_type '(untyped) -> untyped' ,
954+ [ 1 , 2 r, 3.0 , 4 i] , :sum , init
955+ end
956+
957+ assert_send_type '() { (Rational) -> untyped } -> untyped' ,
958+ [ 1 r, 2 r, 3 r] , :sum do |ele | ele . i end
959+
960+ with 5 , 6 r, 7.0 , 8 i do |init |
961+ assert_send_type '(untyped) { (Rational) -> untyped } -> untyped' ,
962+ [ 1 r, 2 r, 3 r] , :sum , init do |ele | ele . i end
963+ end
964+
965+ # Test an extremely esoteric edgecase, which any updates to the signature will have to allow for
966+ outer = BlankSlate . new
967+ def outer . +( rhs )
968+ inner = BlankSlate . new
969+ ::Kernel . instance_method ( :instance_variable_set ) . bind_call ( inner , :@rhs , rhs )
970+ def inner . +( rhs ) = [ :innermost , @rhs , rhs ]
971+ inner
972+ end
973+
974+ assert_send_type '(untyped) -> [:innermost, 1, 2]' ,
975+ [ 1 , 2 ] , :sum , outer
927976 end
928977
929978 def test_take
@@ -1031,7 +1080,31 @@ def test_values_at
10311080 end
10321081
10331082 def test_zip
1034- omit 'todo -- non-enumerable'
1083+ assert_send_type '() -> Array[[Rational]]' ,
1084+ [ 1 r, 2 r, 3 r] , :zip
1085+ assert_send_type '() { ([Rational]) -> void } -> nil' ,
1086+ [ 1 r, 2 r, 3 r] , :zip do end
1087+
1088+ with_each 1 , 2 do |iter1 |
1089+ assert_send_type '(_Each[Integer]) -> Array[[Rational, Integer?]]' ,
1090+ [ 1 r, 2 r, 3 r] , :zip , iter1
1091+ assert_send_type '(_Each[Integer]) { ([Rational, Integer?]) -> void } -> nil' ,
1092+ [ 1 r, 2 r, 3 r] , :zip , iter1 do end
1093+
1094+ with_each 1 i, 2 i do |iter2 |
1095+ assert_send_type '(_Each[Integer], _Each[Complex]) -> Array[[Rational, Integer?, Complex?]]' ,
1096+ [ 1 r, 2 r, 3 r] , :zip , iter1 , iter2
1097+ assert_send_type '(_Each[Integer], _Each[Complex]) { ([Rational, Integer?, Complex?]) -> void } -> nil' ,
1098+ [ 1 r, 2 r, 3 r] , :zip , iter1 , iter2 do end
1099+
1100+ with_each 1.0 , 2.0 do |iter3 |
1101+ assert_send_type '(*_Each[Integer | Complex | Float]) -> Array[Array[Rational | Integer | Complex | Float | nil]]' ,
1102+ [ 1 r, 2 r, 3 r] , :zip , iter1 , iter2 , iter3
1103+ assert_send_type '(*_Each[Integer | Complex | Float]) { (Array[Rational | Integer | Complex | Float | nil]) -> void } -> nil' ,
1104+ [ 1 r, 2 r, 3 r] , :zip , iter1 , iter2 , iter3 do end
1105+ end
1106+ end
1107+ end
10351108 end
10361109
10371110 def test_op_or
0 commit comments