@@ -7,20 +7,6 @@ class KernelSingletonTest < Test::Unit::TestCase
77
88 testing "singleton(::Kernel)"
99
10- def test_caller_locations
11- assert_send_type "() -> Array[Thread::Backtrace::Location]" ,
12- Kernel , :caller_locations
13-
14- assert_send_type "(Integer) -> Array[Thread::Backtrace::Location]?" ,
15- Kernel , :caller_locations , 1
16-
17- assert_send_type "(Integer, Integer) -> Array[Thread::Backtrace::Location]?" ,
18- Kernel , :caller_locations , 1 , 2
19-
20- assert_send_type "(::Range[Integer]) -> Array[Thread::Backtrace::Location]?" ,
21- Kernel , :caller_locations , ( 1 ..3 )
22- end
23-
2410 def test_Array
2511 assert_send_type "(nil) -> []" ,
2612 Kernel , :Array , nil
@@ -180,6 +166,38 @@ def test_throw
180166 end
181167 end
182168
169+ TOPLEVEL___callee__ = __callee__ # outside of a method
170+ def test___callee__
171+ assert_send_type '() -> Symbol' ,
172+ Kernel , :__callee__
173+ assert_type 'nil' , TOPLEVEL___callee__
174+ end
175+
176+ TOPLEVEL___method__ = __method__ # outside of a method
177+ def test___method__
178+ assert_send_type '() -> Symbol' ,
179+ Kernel , :__method__
180+ assert_type 'nil' , TOPLEVEL___method__
181+ end
182+
183+ def test___dir__
184+ assert_send_type '() -> String' ,
185+ Kernel , :__dir__
186+
187+ # Make sure it can return `nil`; this can't go through `assert_send_type`,
188+ # as it's only `nil` thru `eval`s
189+ assert_equal nil , eval ( '__dir__' )
190+ end
191+
192+ def test_autoload
193+ with_interned :TestModuleForAutoload do |const |
194+ with_path '/does/not/exist' do |path |
195+ assert_send_type '(interned, path) -> nil' ,
196+ Kernel , :autoload , const , path
197+ end
198+ end
199+ end
200+
183201 TestException = Class . new ( Exception )
184202
185203 def test_raise ( method : :raise )
@@ -239,17 +257,208 @@ def test_fail
239257 test_raise method : :fail
240258 end
241259
260+
242261 def test_autoload?
243- with_interned :TestModuleForAutoload do |interned |
244- assert_send_type "(::interned) -> String?" ,
245- Kernel , :autoload? , interned
262+ with_interned :TestModuleForAutoloadP do |const |
263+ assert_send_type '(interned) -> nil' ,
264+ Kernel , :autoload? , const
265+
266+ with_boolish do |inherit |
267+ assert_send_type '(interned, boolish) -> nil' ,
268+ Kernel , :autoload? , const , inherit
269+ end
270+ end
271+
272+ # Unfortunately, `autoload` doesn't play well with `assert_send_type`
273+ Kernel . autoload :TestModuleForAutoloadP , '/does/not/exist'
274+
275+ with_interned :TestModuleForAutoloadP do |const |
276+ assert_type 'String' , Kernel . autoload? ( const )
277+
278+ with_boolish do |inherit |
279+ assert_type 'String' , Kernel . autoload? ( const , inherit )
280+ end
281+ end
282+ end
283+
284+ def test_binding
285+ assert_send_type '() -> Binding' ,
286+ Kernel , :binding
287+ end
288+
289+ def test_block_given? ( method : :block_given? )
290+ assert_send_type '() -> bool' ,
291+ Kernel , method
292+ end
293+
294+ def test_iterator?
295+ silence_warning :deprecated do
296+ test_block_given? ( method : :iterator? )
297+ end
298+ end
299+
300+ def test_caller
301+ assert_send_type '() -> Array[String]' ,
302+ Kernel , :caller
303+
304+ with_int 1 do |start |
305+ assert_send_type '(int) -> Array[String]' ,
306+ Kernel , :caller , start
307+
308+ with_int ( 2 ) . and_nil do |length |
309+ assert_send_type '(int, int?) -> Array[String]' ,
310+ Kernel , :caller , start , length
311+ end
312+ end
313+
314+ with_int 100000 do |start |
315+ assert_send_type '(int) -> nil' ,
316+ Kernel , :caller , start
317+
318+ with_int ( 2 ) . and_nil do |length |
319+ assert_send_type '(int, int?) -> nil' ,
320+ Kernel , :caller , start , length
321+ end
322+ end
323+
324+ with_range with_int ( 1 ) , with_int ( 2 ) do |range |
325+ assert_send_type '(range[int]) -> Array[String]' ,
326+ Kernel , :caller , range
246327 end
247328
248- autoload :TestModuleForAutoload , '/shouldnt/be/executed'
329+ with_range with_int ( 100000 ) , with_int ( 100001 ) do |range |
330+ assert_send_type '(range[int]) -> nil' ,
331+ Kernel , :caller , range
332+ end
333+ end
249334
250- with_interned :TestModuleForAutoload do |interned |
251- assert_send_type "(::interned) -> String?" ,
252- Kernel , :autoload? , interned
335+ def test_caller_locations
336+ assert_send_type '() -> Array[Thread::Backtrace::Location]' ,
337+ Kernel , :caller_locations
338+
339+ with_int 1 do |start |
340+ assert_send_type '(int) -> Array[Thread::Backtrace::Location]' ,
341+ Kernel , :caller_locations , start
342+
343+ with_int ( 2 ) . and_nil do |length |
344+ assert_send_type '(int, int?) -> Array[Thread::Backtrace::Location]' ,
345+ Kernel , :caller_locations , start , length
346+ end
347+ end
348+
349+ with_int 100000 do |start |
350+ assert_send_type '(int) -> nil' ,
351+ Kernel , :caller_locations , start
352+
353+ with_int ( 2 ) . and_nil do |length |
354+ assert_send_type '(int, int?) -> nil' ,
355+ Kernel , :caller_locations , start , length
356+ end
357+ end
358+
359+ with_range with_int ( 1 ) , with_int ( 2 ) do |range |
360+ assert_send_type '(range[int]) -> Array[Thread::Backtrace::Location]' ,
361+ Kernel , :caller_locations , range
362+ end
363+
364+ with_range with_int ( 100000 ) , with_int ( 100001 ) do |range |
365+ assert_send_type '(range[int]) -> nil' ,
366+ Kernel , :caller_locations , range
367+ end
368+ end
369+
370+ def test_global_variables
371+ assert_send_type '() -> Array[Symbol]' ,
372+ Kernel , :global_variables
373+ end
374+
375+ def test_local_variables
376+ assert_send_type '() -> Array[Symbol]' ,
377+ Kernel , :local_variables
378+ end
379+
380+ def test_test
381+ # true/false tests
382+ with_path do |filepath |
383+ %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 |
384+ test_ord = test_char . ord
385+
386+ with test_char , test_ord do |test_literal |
387+ assert_send_type "('b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'G' | 'k' | 'l' | 'o' | 'O' | 'p' | 'r' | 'R' | 'S' | 'u' | 'w' | 'W' | 'x' | 'X' | 'z' |
388+ 98 | 99 | 100 | 101 | 102 | 103 | 71 | 107 | 108 | 111 | 79 | 112 | 114 | 82 | 83 | 117 | 119 | 87 | 120 | 88 | 122, path) -> bool" ,
389+ Kernel , :test , test_literal , filepath
390+ end
391+
392+ with_int ( test_ord ) . and test_char do |test_nonliteral |
393+ assert_send_type "(String | int, path, ?path) -> (bool | Time | Integer | nil)" ,
394+ Kernel , :test , test_nonliteral , filepath
395+ end
396+ end
397+ end
398+
399+ # Integer? tests
400+ %w[ s ] . each do |test_char |
401+ test_ord = test_char . ord
402+
403+ with_path __FILE__ do |filepath |
404+ with test_char , test_ord do |test_literal |
405+ assert_send_type "('s' | 115, path) -> Integer" ,
406+ Kernel , :test , test_literal , filepath
407+ end
408+
409+ with_int ( test_ord ) . and test_char do |test_nonliteral |
410+ assert_send_type "(String | int, path, ?path) -> (bool | Time | Integer | nil)" ,
411+ Kernel , :test , test_nonliteral , filepath
412+ end
413+ end
414+
415+ with_path '/not/a/file' do |filepath |
416+ with test_char , test_ord do |test_literal |
417+ assert_send_type "('s' | 115, path) -> nil" ,
418+ Kernel , :test , test_literal , filepath
419+ end
420+
421+ with_int ( test_ord ) . and test_char do |test_nonliteral |
422+ assert_send_type "(String | int, path, ?path) -> (bool | Time | Integer | nil)" ,
423+ Kernel , :test , test_nonliteral , filepath
424+ end
425+ end
426+ end
427+
428+ # Time tests
429+ with_path __FILE__ do |filepath |
430+ %w[ A M C ] . each do |test_char |
431+ test_ord = test_char . ord
432+
433+ with test_char , test_ord do |test_literal |
434+ assert_send_type "('A' | 'M' | 'C' | 65 | 77 | 67, path) -> Time" ,
435+ Kernel , :test , test_literal , filepath
436+ end
437+
438+ with_int ( test_ord ) . and test_char do |test_nonliteral |
439+ assert_send_type "(String | int, path, ?path) -> (bool | Time | Integer | nil)" ,
440+ Kernel , :test , test_nonliteral , filepath
441+ end
442+ end
443+ end
444+
445+ # Comparison Tests
446+ with_path __dir__ + '/Integer_test.rb' do |filepath1 |
447+ with_path __FILE__ do |filepath2 |
448+ %w[ < = > - ] . each do |test_char |
449+ test_ord = test_char . ord
450+
451+ with test_char , test_ord do |test_literal |
452+ assert_send_type "('<' | '=' | '>' | '-' | 60 | 61 | 62 | 45, path, path) -> bool" ,
453+ Kernel , :test , test_literal , filepath1 , filepath2
454+ end
455+
456+ with_int ( test_ord ) . and test_char do |test_nonliteral |
457+ assert_send_type "(String | int, path, ?path) -> (bool | Time | Integer | nil)" ,
458+ Kernel , :test , test_nonliteral , filepath1 , filepath2
459+ end
460+ end
461+ end
253462 end
254463 end
255464
0 commit comments