@@ -217,7 +217,30 @@ def test_op_rsh
217217 end
218218
219219 def test_op_aref
220- # omit 'todo'
220+ with_int 3 do |offset |
221+ assert_send_type '(int) -> (0 | 1)' ,
222+ 38 , :[] , offset
223+
224+ with_int 5 do |size |
225+ assert_send_type '(int, int) -> Integer' ,
226+ 38 , :[] , offset , size
227+ end
228+ end
229+
230+ assert_send_type '(range[int?]) -> Integer' ,
231+ 38 , :[] , 3 ..nil
232+ assert_send_type '(range[int?]) -> Integer' ,
233+ 38 , :[] , nil ..0
234+ assert_send_type '(range[int?]) -> Integer' ,
235+ 38 , :[] , 1 r..3 r
236+ assert_send_type '(range[int?]) -> Integer' ,
237+ 38 , :[] , 1.0 ..3.0
238+
239+ start = ToInt . new ( 1 )
240+ def start . <=>( other ) = to_int <=> other . to_int
241+ def start . coerce ( other ) = [ other . to_int , to_int ]
242+ assert_send_type '(range[int?]) -> Integer' ,
243+ 38 , :[] , CustomRange . new ( start , ToInt . new ( 3 ) )
221244 end
222245
223246 def test_op_xor
@@ -346,7 +369,26 @@ def test_divmod
346369 end
347370
348371 def test_downto
349- # omit 'todo'
372+ assert_send_type '(Integer) { (Integer) -> void } -> 38' ,
373+ 38 , :downto , 35 do end
374+ assert_send_type '(Integer) -> Enumerator[Integer, 38]' ,
375+ 38 , :downto , 35
376+ assert_send_type '(Rational) { (Integer) -> void } -> 38' ,
377+ 38 , :downto , 35 r do end
378+ assert_send_type '(Rational) -> Enumerator[Integer, 38]' ,
379+ 38 , :downto , 35 r
380+ assert_send_type '(Float) { (Integer) -> void } -> 38' ,
381+ 38 , :downto , 35.0 do end
382+ assert_send_type '(Float) -> Enumerator[Integer, 38]' ,
383+ 38 , :downto , 35.0
384+
385+ assert_send_type '(Coercable) { (Integer) -> void } -> 38' ,
386+ 38 , :downto , Coercable . for_op ( :< ) { it . __value__ < 35 } do end
387+
388+ coercable = Coercable . for_op ( :< ) { it . __value__ < 35 }
389+ def coercable . -( rhs ) = 35 - rhs # Required by `Enumerator#size`, which the unit test harness uses
390+ assert_send_type '(Coercable) -> Enumerator[Integer, 38]' ,
391+ 38 , :downto , coercable
350392 end
351393
352394 def test_even?
@@ -568,7 +610,26 @@ def test_truncate
568610 end
569611
570612 def test_upto
571- # omit 'todo'
613+ assert_send_type '(Integer) { (Integer) -> void } -> 38' ,
614+ 38 , :upto , 40 do end
615+ assert_send_type '(Integer) -> Enumerator[Integer, 38]' ,
616+ 38 , :upto , 40
617+ assert_send_type '(Rational) { (Integer) -> void } -> 38' ,
618+ 38 , :upto , 40 r do end
619+ assert_send_type '(Rational) -> Enumerator[Integer, 38]' ,
620+ 38 , :upto , 40 r
621+ assert_send_type '(Float) { (Integer) -> void } -> 38' ,
622+ 38 , :upto , 40.0 do end
623+ assert_send_type '(Float) -> Enumerator[Integer, 38]' ,
624+ 38 , :upto , 40.0
625+
626+ assert_send_type '(Coercable) { (Integer) -> void } -> 38' ,
627+ 38 , :upto , Coercable . for_op ( :> ) { it . __value__ > 40 } do end
628+
629+ coercable = Coercable . for_op ( :> ) { it . __value__ > 40 }
630+ def coercable . -( rhs ) = 40 - rhs # Required by `Enumerator#size`, which the unit test harness uses
631+ assert_send_type '(Coercable) -> Enumerator[Integer, 38]' ,
632+ 38 , :upto , coercable
572633 end
573634
574635 def test_zero?
0 commit comments