diff --git a/lib/ruby_indexer/test/reference_finder_test.rb b/lib/ruby_indexer/test/reference_finder_test.rb index 01957e19e..c2e25f655 100644 --- a/lib/ruby_indexer/test/reference_finder_test.rb +++ b/lib/ruby_indexer/test/reference_finder_test.rb @@ -91,7 +91,7 @@ def baz assert_equal(6, refs[1].location.start_line) end - def test_does_not_mismatch_on_attrs_readers_and_writers + def test_does_not_mismatch_on_readers_and_writers refs = find_method_references("foo", <<~RUBY) class Bar def foo @@ -117,6 +117,32 @@ def baz assert_equal(10, refs[1].location.start_line) end + def test_matches_writers + refs = find_method_references("foo=", <<~RUBY) + class Bar + def foo + end + + def foo=(value) + end + + def baz + self.foo = 1 + self.foo + end + end + RUBY + + # We want to match `foo=` but not `foo` + assert_equal(2, refs.size) + + assert_equal("foo=", refs[0].name) + assert_equal(5, refs[0].location.start_line) + + assert_equal("foo=", refs[1].name) + assert_equal(9, refs[1].location.start_line) + end + private def find_const_references(const_name, source)