Skip to content

Commit

Permalink
Fix test references to index_single
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistock committed Aug 29, 2023
1 parent 9d1ee79 commit 2a2f4fe
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 24 deletions.
2 changes: 1 addition & 1 deletion lib/ruby_indexer/test/classes_and_modules_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class Foo

assert_entry("Foo", Index::Entry::Class, "/fake/path/foo.rb:0-0:1-2")

@index.delete("/fake/path/foo.rb")
@index.delete(Indexable.new(nil, "/fake/path/foo.rb"))
refute_entry("Foo")
assert_empty(@index.instance_variable_get(:@files_to_entries))
end
Expand Down
18 changes: 9 additions & 9 deletions lib/ruby_indexer/test/index_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,39 @@
module RubyIndexer
class IndexTest < TestCase
def test_deleting_one_entry_for_a_class
@index.index_single("/fake/path/foo.rb", <<~RUBY)
@index.index_single(Indexable.new(nil, "/fake/path/foo.rb"), <<~RUBY)
class Foo
end
RUBY
@index.index_single("/fake/path/other_foo.rb", <<~RUBY)
@index.index_single(Indexable.new(nil, "/fake/path/other_foo.rb"), <<~RUBY)
class Foo
end
RUBY

entries = @index["Foo"]
assert_equal(2, entries.length)

@index.delete("/fake/path/other_foo.rb")
@index.delete(Indexable.new(nil, "/fake/path/other_foo.rb"))
entries = @index["Foo"]
assert_equal(1, entries.length)
end

def test_deleting_all_entries_for_a_class
@index.index_single("/fake/path/foo.rb", <<~RUBY)
@index.index_single(Indexable.new(nil, "/fake/path/foo.rb"), <<~RUBY)
class Foo
end
RUBY

entries = @index["Foo"]
assert_equal(1, entries.length)

@index.delete("/fake/path/foo.rb")
@index.delete(Indexable.new(nil, "/fake/path/foo.rb"))
entries = @index["Foo"]
assert_nil(entries)
end

def test_index_resolve
@index.index_single("/fake/path/foo.rb", <<~RUBY)
@index.index_single(Indexable.new(nil, "/fake/path/foo.rb"), <<~RUBY)
class Bar; end
module Foo
Expand Down Expand Up @@ -72,7 +72,7 @@ class Something
end

def test_accessing_with_colon_colon_prefix
@index.index_single("/fake/path/foo.rb", <<~RUBY)
@index.index_single(Indexable.new(nil, "/fake/path/foo.rb"), <<~RUBY)
class Bar; end
module Foo
Expand All @@ -92,7 +92,7 @@ class Something
end

def test_fuzzy_search
@index.index_single("/fake/path/foo.rb", <<~RUBY)
@index.index_single(Indexable.new(nil, "/fake/path/foo.rb"), <<~RUBY)
class Bar; end
module Foo
Expand Down Expand Up @@ -121,7 +121,7 @@ class Something

def test_index_single_ignores_directories
FileUtils.mkdir("lib/this_is_a_dir.rb")
@index.index_single("lib/this_is_a_dir.rb")
@index.index_single(Indexable.new(nil, "lib/this_is_a_dir.rb"))
ensure
FileUtils.rm_r("lib/this_is_a_dir.rb")
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ruby_indexer/test/test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def setup
private

def index(source)
@index.index_single("/fake/path/foo.rb", source)
@index.index_single(Indexable.new(nil, "/fake/path/foo.rb"), source)
end

def assert_entry(expected_name, type, expected_location)
Expand Down
20 changes: 15 additions & 5 deletions test/requests/definition_expectations_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,15 @@ def run_expectations(source)
store.set(uri: URI("file:///folder/fake.rb"), source: source, version: 1)
executor = RubyLsp::Executor.new(store, message_queue)

executor.instance_variable_get(:@index).index_single(File.expand_path(
"../../lib/ruby_lsp/event_emitter.rb",
__dir__,
))
executor.instance_variable_get(:@index).index_single(
RubyIndexer::Indexable.new(
nil,
File.expand_path(
"../../lib/ruby_lsp/event_emitter.rb",
__dir__,
),
),
)

begin
# We need to pretend that Sorbet is not a dependency or else we can't properly test
Expand Down Expand Up @@ -62,7 +67,12 @@ def test_jumping_to_default_gems
RUBY

executor = RubyLsp::Executor.new(store, message_queue)
executor.instance_variable_get(:@index).index_single(T.must(uri.to_standardized_path))
executor.instance_variable_get(:@index).index_single(
RubyIndexer::Indexable.new(
nil,
T.must(uri.to_standardized_path),
),
)

response = executor.execute({
method: "textDocument/definition",
Expand Down
7 changes: 5 additions & 2 deletions test/requests/hover_expectations_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def run_expectations(source)

executor = RubyLsp::Executor.new(store, message_queue)
index = executor.instance_variable_get(:@index)
index.index_single(uri.to_standardized_path, source)
index.index_single(RubyIndexer::Indexable.new(nil, T.must(uri.to_standardized_path)), source)

begin
# We need to pretend that Sorbet is not a dependency or else we can't properly test
Expand Down Expand Up @@ -49,7 +49,10 @@ class Post
store.set(uri: uri, source: source, version: 1)

executor = RubyLsp::Executor.new(store, message_queue)
executor.instance_variable_get(:@index).index_single(uri.to_standardized_path, source)
executor.instance_variable_get(:@index).index_single(
RubyIndexer::Indexable.new(nil, T.must(uri.to_standardized_path)),
source,
)

response = executor.execute({
method: "textDocument/hover",
Expand Down
16 changes: 10 additions & 6 deletions test/requests/workspace_symbol_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def teardown
end

def test_returns_index_entries_based_on_query
@index.index_single("/fake.rb", <<~RUBY)
@index.index_single(RubyIndexer::Indexable.new(nil, "/fake.rb"), <<~RUBY)
class Foo; end
module Bar; end
Expand All @@ -35,7 +35,7 @@ module Bar; end
end

def test_fuzzy_matches_symbols
@index.index_single("/fake.rb", <<~RUBY)
@index.index_single(RubyIndexer::Indexable.new(nil, "/fake.rb"), <<~RUBY)
class Foo; end
module Bar; end
Expand All @@ -57,13 +57,17 @@ module Bar; end

def test_matches_only_gem_symbols_if_typechecker_is_present
RubyLsp::DependencyDetector.const_set(:HAS_TYPECHECKER, true)
indexable = RubyIndexer::Indexable.new(
nil,
"#{RubyLsp::WORKSPACE_URI.to_standardized_path}/workspace_symbol_foo.rb",
)

@index.index_single("#{RubyLsp::WORKSPACE_URI.to_standardized_path}/workspace_symbol_foo.rb", <<~RUBY)
@index.index_single(indexable, <<~RUBY)
class Foo; end
RUBY

path = "#{Bundler.bundle_path}/gems/fake-gem-0.1.0/lib/gem_symbol_foo.rb"
@index.index_single(path, <<~RUBY)
@index.index_single(RubyIndexer::Indexable.new(nil, path), <<~RUBY)
class Foo; end
RUBY

Expand All @@ -73,7 +77,7 @@ class Foo; end
end

def test_symbols_include_container_name
@index.index_single("/fake.rb", <<~RUBY)
@index.index_single(RubyIndexer::Indexable.new(nil, "/fake.rb"), <<~RUBY)
module Foo
class Bar; end
end
Expand All @@ -86,7 +90,7 @@ class Bar; end
end

def test_finds_default_gem_symbols
@index.index_single("#{RbConfig::CONFIG["rubylibdir"]}/pathname.rb")
@index.index_single(RubyIndexer::Indexable.new(nil, "#{RbConfig::CONFIG["rubylibdir"]}/pathname.rb"))

result = RubyLsp::Requests::WorkspaceSymbol.new("Pathname", @index).run
refute_empty(result)
Expand Down

0 comments on commit 2a2f4fe

Please sign in to comment.