@@ -81,17 +81,239 @@ def test_String
8181 Kernel , :String , ToS . new
8282 end
8383
84+ TOPLEVEL___callee__ = __callee__ # outside of a method
85+ def test___callee__
86+ assert_send_type '() -> Symbol' ,
87+ Kernel , :__callee__
88+ assert_type 'nil' , TOPLEVEL___callee__
89+ end
90+
91+ TOPLEVEL___method__ = __method__ # outside of a method
92+ def test___method__
93+ assert_send_type '() -> Symbol' ,
94+ Kernel , :__method__
95+ assert_type 'nil' , TOPLEVEL___method__
96+ end
97+
98+ def test___dir__
99+ assert_send_type '() -> String' ,
100+ Kernel , :__dir__
101+
102+ # Make sure it can return `nil`; this can't go through `assert_send_type`,
103+ # as it's only `nil` thru `eval`s
104+ assert_equal nil , eval ( '__dir__' )
105+ end
106+
107+ def test_autoload
108+ with_interned :TestModuleForAutoload do |const |
109+ with_path '/does/not/exist' do |path |
110+ assert_send_type '(interned, path) -> nil' ,
111+ Kernel , :autoload , const , path
112+ end
113+ end
114+ end
115+
84116 def test_autoload?
85- with_interned :TestModuleForAutoload do |interned |
86- assert_send_type "(::interned) -> String?" ,
87- Kernel , :autoload? , interned
117+ with_interned :TestModuleForAutoloadP do |const |
118+ assert_send_type '(interned) -> nil' ,
119+ Kernel , :autoload? , const
120+
121+ with_boolish do |inherit |
122+ assert_send_type '(interned, boolish) -> nil' ,
123+ Kernel , :autoload? , const , inherit
124+ end
125+ end
126+
127+ # Unfortunately, `autoload` doesn't play well with `assert_send_type`
128+ Kernel . autoload :TestModuleForAutoloadP , '/does/not/exist'
129+
130+ with_interned :TestModuleForAutoloadP do |const |
131+ assert_type 'String' , Kernel . autoload? ( const )
132+
133+ with_boolish do |inherit |
134+ assert_type 'String' , Kernel . autoload? ( const , inherit )
135+ end
136+ end
137+ end
138+
139+ def test_binding
140+ assert_send_type '() -> Binding' ,
141+ Kernel , :binding
142+ end
143+
144+ def test_block_given? ( method : :block_given? )
145+ assert_send_type '() -> bool' ,
146+ Kernel , method
147+ end
148+
149+ def test_iterator?
150+ silence_warning :deprecated do
151+ test_block_given? ( method : :iterator? )
152+ end
153+ end
154+
155+ def test_caller
156+ assert_send_type '() -> Array[String]' ,
157+ Kernel , :caller
158+
159+ with_int 1 do |start |
160+ assert_send_type '(int) -> Array[String]' ,
161+ Kernel , :caller , start
162+
163+ with_int ( 2 ) . and_nil do |length |
164+ assert_send_type '(int, int?) -> Array[String]' ,
165+ Kernel , :caller , start , length
166+ end
167+ end
168+
169+ with_int 100000 do |start |
170+ assert_send_type '(int) -> nil' ,
171+ Kernel , :caller , start
172+
173+ with_int ( 2 ) . and_nil do |length |
174+ assert_send_type '(int, int?) -> nil' ,
175+ Kernel , :caller , start , length
176+ end
177+ end
178+
179+ with_range with_int ( 1 ) , with_int ( 2 ) do |range |
180+ assert_send_type '(range[int]) -> Array[String]' ,
181+ Kernel , :caller , range
182+ end
183+
184+ with_range with_int ( 100000 ) , with_int ( 100001 ) do |range |
185+ assert_send_type '(range[int]) -> nil' ,
186+ Kernel , :caller , range
88187 end
188+ end
189+
190+ def test_caller_locations
191+ assert_send_type '() -> Array[Thread::Backtrace::Location]' ,
192+ Kernel , :caller_locations
193+
194+ with_int 1 do |start |
195+ assert_send_type '(int) -> Array[Thread::Backtrace::Location]' ,
196+ Kernel , :caller_locations , start
197+
198+ with_int ( 2 ) . and_nil do |length |
199+ assert_send_type '(int, int?) -> Array[Thread::Backtrace::Location]' ,
200+ Kernel , :caller_locations , start , length
201+ end
202+ end
203+
204+ with_int 100000 do |start |
205+ assert_send_type '(int) -> nil' ,
206+ Kernel , :caller_locations , start
207+
208+ with_int ( 2 ) . and_nil do |length |
209+ assert_send_type '(int, int?) -> nil' ,
210+ Kernel , :caller_locations , start , length
211+ end
212+ end
213+
214+ with_range with_int ( 1 ) , with_int ( 2 ) do |range |
215+ assert_send_type '(range[int]) -> Array[Thread::Backtrace::Location]' ,
216+ Kernel , :caller_locations , range
217+ end
218+
219+ with_range with_int ( 100000 ) , with_int ( 100001 ) do |range |
220+ assert_send_type '(range[int]) -> nil' ,
221+ Kernel , :caller_locations , range
222+ end
223+ end
224+
225+ def test_global_variables
226+ assert_send_type '() -> Array[Symbol]' ,
227+ Kernel , :global_variables
228+ end
229+
230+ def test_local_variables
231+ assert_send_type '() -> Array[Symbol]' ,
232+ Kernel , :local_variables
233+ end
234+
235+ def test_test
236+ # true/false tests
237+ with_path do |filepath |
238+ %w[ b c d e f g G k l o O p r R S u w W x X z ] . each do |test_char |
239+ test_ord = test_char . ord
89240
90- autoload :TestModuleForAutoload , '/shouldnt/be/executed'
241+ with test_char , test_ord do |test_literal |
242+ assert_send_type "('b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'G' | 'k' | 'l' | 'o' | 'O' | 'p' | 'r' | 'R' | 'S' | 'u' | 'w' | 'W' | 'x' | 'X' | 'z' |
243+ 98 | 99 | 100 | 101 | 102 | 103 | 71 | 107 | 108 | 111 | 79 | 112 | 114 | 82 | 83 | 117 | 119 | 87 | 120 | 88 | 122, path) -> bool" ,
244+ Kernel , :test , test_literal , filepath
245+ end
91246
92- with_interned :TestModuleForAutoload do |interned |
93- assert_send_type "(::interned) -> String?" ,
94- Kernel , :autoload? , interned
247+ with_int ( test_ord ) . and test_char do |test_nonliteral |
248+ assert_send_type "(String | int, path, ?path) -> (bool | Time | Integer | nil)" ,
249+ Kernel , :test , test_nonliteral , filepath
250+ end
251+ end
252+ end
253+
254+ # Integer? tests
255+ %w[ s ] . each do |test_char |
256+ test_ord = test_char . ord
257+
258+ with_path __FILE__ do |filepath |
259+ with test_char , test_ord do |test_literal |
260+ assert_send_type "('s' | 115, path) -> Integer" ,
261+ Kernel , :test , test_literal , filepath
262+ end
263+
264+ with_int ( test_ord ) . and test_char do |test_nonliteral |
265+ assert_send_type "(String | int, path, ?path) -> (bool | Time | Integer | nil)" ,
266+ Kernel , :test , test_nonliteral , filepath
267+ end
268+ end
269+
270+ with_path '/not/a/file' do |filepath |
271+ with test_char , test_ord do |test_literal |
272+ assert_send_type "('s' | 115, path) -> nil" ,
273+ Kernel , :test , test_literal , filepath
274+ end
275+
276+ with_int ( test_ord ) . and test_char do |test_nonliteral |
277+ assert_send_type "(String | int, path, ?path) -> (bool | Time | Integer | nil)" ,
278+ Kernel , :test , test_nonliteral , filepath
279+ end
280+ end
281+ end
282+
283+ # Time tests
284+ with_path __FILE__ do |filepath |
285+ %w[ A M C ] . each do |test_char |
286+ test_ord = test_char . ord
287+
288+ with test_char , test_ord do |test_literal |
289+ assert_send_type "('A' | 'M' | 'C' | 65 | 77 | 67, path) -> Time" ,
290+ Kernel , :test , test_literal , filepath
291+ end
292+
293+ with_int ( test_ord ) . and test_char do |test_nonliteral |
294+ assert_send_type "(String | int, path, ?path) -> (bool | Time | Integer | nil)" ,
295+ Kernel , :test , test_nonliteral , filepath
296+ end
297+ end
298+ end
299+
300+ # Comparison Tests
301+ with_path __dir__ + '/Integer_test.rb' do |filepath1 |
302+ with_path __FILE__ do |filepath2 |
303+ %w[ < = > - ] . each do |test_char |
304+ test_ord = test_char . ord
305+
306+ with test_char , test_ord do |test_literal |
307+ assert_send_type "('<' | '=' | '>' | '-' | 60 | 61 | 62 | 45, path, path) -> bool" ,
308+ Kernel , :test , test_literal , filepath1 , filepath2
309+ end
310+
311+ with_int ( test_ord ) . and test_char do |test_nonliteral |
312+ assert_send_type "(String | int, path, ?path) -> (bool | Time | Integer | nil)" ,
313+ Kernel , :test , test_nonliteral , filepath1 , filepath2
314+ end
315+ end
316+ end
95317 end
96318 end
97319
0 commit comments