Skip to content

Commit

Permalink
Improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
st0012 committed Aug 1, 2024
1 parent a504908 commit 4f81f6d
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions test/requests/definition_expectations_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -358,27 +358,40 @@ def test_jumping_to_autoload_definition_when_declaration_exists
class Foo
autoload :Bar, "bar"
class Bar; end
end
RUBY

with_server(source) do |server, uri|
server.global_state.index.index_single(
RubyIndexer::IndexablePath.new(nil, "/fake/path/bar.rb"), <<~RUBY
class Foo::Bar; end
RUBY
)
server.global_state.index.index_single(
RubyIndexer::IndexablePath.new(nil, "/fake/path/baz.rb"), <<~RUBY
class Foo::Bar; end
RUBY
)
server.process_message(
id: 1,
method: "textDocument/definition",
params: { textDocument: { uri: uri }, position: { character: 12, line: 3 } },
)

response = server.pop_response.response
assert_equal(1, response.size)
assert_equal("file:///fake.rb", response.first.attributes[:targetUri])
# This feature simply does a constant lookup on the symbol passed to autoload, instead of jumping into the
# autoloaded path
# This is because there's no guarantee that the autoloaded file actually defines the constant. But if it does,
# then it will be listed in the result anyway
assert_equal(2, response.size)
assert_equal("file:///fake/path/bar.rb", response.first.attributes[:targetUri])
assert_equal("file:///fake/path/baz.rb", response.last.attributes[:targetUri])
end
end

def test_does_nothing_when_autoload_declaration_does_not_exist
source = <<~RUBY
# typed: false
# typed: ignore
class Foo
autoload :Bar, "bar"
Expand Down

0 comments on commit 4f81f6d

Please sign in to comment.