Skip to content

Commit

Permalink
Add test for matching writers
Browse files Browse the repository at this point in the history
  • Loading branch information
andyw8 committed Oct 3, 2024
1 parent 3895bbf commit fed6be1
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion lib/ruby_indexer/test/reference_finder_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit fed6be1

Please sign in to comment.