@@ -286,6 +286,53 @@ def test_method_select
286286 assert_call ( '2.times{}.' , include : Integer , exclude : Enumerator )
287287 end
288288
289+ def test_accessor_method
290+ a = Object . new
291+ b = Object . new
292+ c = Object . new
293+ d = Object . new
294+ bo = Object . new
295+ def a . foo ; end
296+ def b . foo ; end
297+ def c . foo ; end
298+ def d . foo ; end
299+ def d . bar! ; end
300+ def d . baz? ; end
301+ def bo . foo ; @foo ||= { } ; end
302+ bo . foo
303+ a . instance_variable_set ( :@foo , 1 )
304+ b . instance_variable_set ( :@foo , 'a' )
305+ c . instance_variable_set ( :@foo , nil )
306+ d . instance_variable_set ( :@bar , :a )
307+ d . instance_variable_set ( :@baz , [ ] )
308+ d . instance_variable_set ( :@blah , 1 )
309+ assert_call ( 'a.foo.' , include : Integer , binding :)
310+ assert_call ( 'b.foo.' , include : String , binding :)
311+ assert_call ( 'bo.foo.' , include : Hash , binding :)
312+ assert_call ( '[a, b, bo].sample.foo.' , include : [ Integer , String , Hash ] , binding :)
313+ assert_call ( '[a, b, c].sample.foo.' , include : [ Integer , String , NilClass ] , binding :)
314+ assert_call ( '[a, b, d].sample.foo.' , include : [ Integer , String ] , exclude : NilClass , binding :)
315+ assert_call ( 'd.bar!.' , include : Symbol , binding :)
316+ assert_call ( 'd.baz?.' , include : Array , binding :)
317+ # Even if method does not exist, it might return @blah in method_missing
318+ assert_call ( 'd.blah.' , include : Integer , binding :)
319+ end
320+
321+ def test_accessor_method_with_class_module
322+ AnalyzeTest . instance_variable_set ( :@foo , 1 )
323+ AnalyzeTest . instance_variable_set ( :@bar , Symbol )
324+ o = Object . new
325+ o . instance_variable_set ( :@foo , String )
326+ o . instance_variable_set ( :@bar , Math )
327+ assert_call ( 'AnalyzeTest.foo.' , include : Integer , binding :)
328+ assert_call ( 'AnalyzeTest.bar.all_symbols.' , include : Array , binding :)
329+ assert_call ( 'o.foo.new.' , include : String , binding :)
330+ assert_call ( 'o.bar.sin(1).' , include : Float , binding :)
331+ ensure
332+ AnalyzeTest . remove_instance_variable ( :@foo )
333+ AnalyzeTest . remove_instance_variable ( :@bar )
334+ end
335+
289336 def test_interface_match_var
290337 assert_call ( '([1]+[:a]+["a"]).sample.' , include : [ Integer , String , Symbol ] )
291338 end
0 commit comments