From 8a768d0cdfc0e810e69538b41c580a0a10d75e86 Mon Sep 17 00:00:00 2001 From: Andy Waite <13400+andyw8@users.noreply.github.com> Date: Fri, 4 Oct 2024 10:41:27 -0400 Subject: [PATCH] More tests --- .../test/reference_finder_test.rb | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/lib/ruby_indexer/test/reference_finder_test.rb b/lib/ruby_indexer/test/reference_finder_test.rb index c2e25f655..0d4627a8f 100644 --- a/lib/ruby_indexer/test/reference_finder_test.rb +++ b/lib/ruby_indexer/test/reference_finder_test.rb @@ -143,6 +143,79 @@ def baz assert_equal(9, refs[1].location.start_line) end + def test_find_inherited_methods + refs = find_method_references("foo", <<~RUBY) + class Bar + def foo + end + end + + class Baz < Bar + super.foo + end + RUBY + + assert_equal(2, refs.size) + + assert_equal("foo", refs[0].name) + assert_equal(2, refs[0].location.start_line) + + assert_equal("foo", refs[1].name) + assert_equal(7, refs[1].location.start_line) + end + + def test_finds_methods_created_in_mixins + refs = find_method_references("foo", <<~RUBY) + module Mixin + def foo + end + end + + class Bar + include Mixin + end + + Bar.foo + RUBY + + assert_equal(2, refs.size) + + assert_equal("foo", refs[0].name) + assert_equal(2, refs[0].location.start_line) + + assert_equal("foo", refs[1].name) + assert_equal(10, refs[1].location.start_line) + end + + def test_finds_singleton_methods + # The current implementation matches on both `Bar.foo` and `Bar#foo` even though they are different + + refs = find_method_references("foo", <<~RUBY) + class Bar + class << self + def foo + end + end + + def foo + end + end + + Bar.foo + RUBY + + assert_equal(3, refs.size) + + assert_equal("foo", refs[0].name) + assert_equal(3, refs[0].location.start_line) + + assert_equal("foo", refs[1].name) + assert_equal(7, refs[1].location.start_line) + + assert_equal("foo", refs[2].name) + assert_equal(11, refs[2].location.start_line) + end + private def find_const_references(const_name, source)