# File lib/ruby_indexer/test/index_test.rb, line 74deftest_accessing_with_colon_colon_prefix@index.index_single(IndexablePath.new(nil, "/fake/path/foo.rb"), <<~RUBY)
class Bar; end
module Foo
class Bar
end
class Baz
class Something
end
end
end
RUBYentries = @index["::Foo::Baz::Something"]
refute_empty(entries)
assert_equal("Foo::Baz::Something", entries.first.name)
end
test_deleting_all_entries_for_a_class()
# File lib/ruby_indexer/test/index_test.rb, line 26deftest_deleting_all_entries_for_a_class@index.index_single(IndexablePath.new(nil, "/fake/path/foo.rb"), <<~RUBY)
class Foo
end
RUBYentries = @index["Foo"]
assert_equal(1, entries.length)
@index.delete(IndexablePath.new(nil, "/fake/path/foo.rb"))
entries = @index["Foo"]
assert_nil(entries)
end
test_deleting_one_entry_for_a_class()
# File lib/ruby_indexer/test/index_test.rb, line 8deftest_deleting_one_entry_for_a_class@index.index_single(IndexablePath.new(nil, "/fake/path/foo.rb"), <<~RUBY)
class Foo
end
RUBY@index.index_single(IndexablePath.new(nil, "/fake/path/other_foo.rb"), <<~RUBY)
class Foo
end
RUBYentries = @index["Foo"]
assert_equal(2, entries.length)
@index.delete(IndexablePath.new(nil, "/fake/path/other_foo.rb"))
entries = @index["Foo"]
assert_equal(1, entries.length)
end
test_fuzzy_search()
# File lib/ruby_indexer/test/index_test.rb, line 94deftest_fuzzy_search@index.index_single(IndexablePath.new(nil, "/fake/path/foo.rb"), <<~RUBY)
class Bar; end
module Foo
class Bar
end
class Baz
class Something
end
end
end
RUBYresult = @index.fuzzy_search("Bar")
assert_equal(1, result.length)
assert_equal(@index["Bar"].first, result.first)
result = @index.fuzzy_search("foobarsomeking")
assert_equal(5, result.length)
assert_equal(["Foo::Baz::Something", "Foo::Bar", "Foo::Baz", "Foo", "Bar"], result.map(&:name))
result = @index.fuzzy_search("FooBaz")
assert_equal(4, result.length)
assert_equal(["Foo::Baz", "Foo::Bar", "Foo", "Foo::Baz::Something"], result.map(&:name))
end
test_index_resolve()
# File lib/ruby_indexer/test/index_test.rb, line 40deftest_index_resolve@index.index_single(IndexablePath.new(nil, "/fake/path/foo.rb"), <<~RUBY)
class Bar; end
module Foo
class Bar
end
class Baz
class Something
end
end
end
RUBYentries = @index.resolve("Something", ["Foo", "Baz"])
refute_empty(entries)
assert_equal("Foo::Baz::Something", entries.first.name)
entries = @index.resolve("Bar", ["Foo"])
refute_empty(entries)
assert_equal("Foo::Bar", entries.first.name)
entries = @index.resolve("Bar", ["Foo", "Baz"])
refute_empty(entries)
assert_equal("Foo::Bar", entries.first.name)
entries = @index.resolve("Foo::Bar", ["Foo", "Baz"])
refute_empty(entries)
assert_equal("Foo::Bar", entries.first.name)
assert_nil(@index.resolve("DoesNotExist", ["Foo"]))
end
# File lib/ruby_indexer/test/index_test.rb, line 312deftest_index_single_does_not_fail_for_non_existing_file@index.index_single(IndexablePath.new(nil, "/fake/path/foo.rb"))
assert_empty(@index.instance_variable_get(:@entries))
end
test_index_single_ignores_directories()
# File lib/ruby_indexer/test/index_test.rb, line 122deftest_index_single_ignores_directoriesFileUtils.mkdir("lib/this_is_a_dir.rb")
@index.index_single(IndexablePath.new(nil, "lib/this_is_a_dir.rb"))
ensureFileUtils.rm_r("lib/this_is_a_dir.rb")
end
test_indexing_prism_fixtures_succeeds()
# File lib/ruby_indexer/test/index_test.rb, line 301deftest_indexing_prism_fixtures_succeedsfixtures = Dir.glob("test/fixtures/prism/test/prism/fixtures/**/*.txt")
fixtures.eachdo|fixture|indexable_path = IndexablePath.new("", fixture)
@index.index_single(indexable_path)
endrefute_empty(@index.instance_variable_get(:@entries))
end
test_prefix_search_for_methods()
# File lib/ruby_indexer/test/index_test.rb, line 285deftest_prefix_search_for_methodsindex(<<~RUBY)
module Foo
module Bar
def baz; end
end
end
RUBYentries = @index.prefix_search("ba")
refute_empty(entries)
entry = T.must(entries.first).firstassert_equal("baz", entry.name)
end
test_resolve_method_attribute()
# File lib/ruby_indexer/test/index_test.rb, line 249deftest_resolve_method_attributeindex(<<~RUBY)
class Foo
attr_reader :bar
end
RUBYentries = T.must(@index.resolve_method("bar", "Foo"))
assert_equal("bar", entries.first.name)
assert_equal("Foo", T.must(entries.first.owner).name)
end
test_resolve_method_with_class_name_conflict()
# File lib/ruby_indexer/test/index_test.rb, line 234deftest_resolve_method_with_class_name_conflictindex(<<~RUBY)
class Array
end
class Foo
def Array(*args); end
end
RUBYentries = T.must(@index.resolve_method("Array", "Foo"))
assert_equal("Array", entries.first.name)
assert_equal("Foo", T.must(entries.first.owner).name)
end
test_resolve_method_with_known_receiver()
# File lib/ruby_indexer/test/index_test.rb, line 220deftest_resolve_method_with_known_receiverindex(<<~RUBY)
module Foo
module Bar
def baz; end
end
end
RUBYentries = T.must(@index.resolve_method("baz", "Foo::Bar"))
assert_equal("baz", entries.first.name)
assert_equal("Foo::Bar", T.must(entries.first.owner).name)
end
test_resolve_method_with_two_definitions()
# File lib/ruby_indexer/test/index_test.rb, line 261deftest_resolve_method_with_two_definitionsindex(<<~RUBY)
class Foo
# Hello from first `bar`
def bar; end
end
class Foo
# Hello from second `bar`
def bar; end
end
RUBYfirst_entry, second_entry = T.must(@index.resolve_method("bar", "Foo"))
assert_equal("bar", first_entry.name)
assert_equal("Foo", T.must(first_entry.owner).name)
assert_includes(first_entry.comments, "Hello from first `bar`")
assert_equal("bar", second_entry.name)
assert_equal("Foo", T.must(second_entry.owner).name)
assert_includes(second_entry.comments, "Hello from second `bar`")
end
test_resolve_normalizes_top_level_names()
# File lib/ruby_indexer/test/index_test.rb, line 162deftest_resolve_normalizes_top_level_names@index.index_single(IndexablePath.new("/fake", "/fake/path/foo.rb"), <<~RUBY)
class Bar; end
module Foo
class Bar; end
end
RUBYentries = @index.resolve("::Foo::Bar", [])
refute_nil(entries)
assert_equal("Foo::Bar", entries.first.name)
entries = @index.resolve("::Bar", ["Foo"])
refute_nil(entries)
assert_equal("Bar", entries.first.name)
end
# File lib/ruby_indexer/test/index_test.rb, line 182deftest_resolving_aliases_to_non_existing_constants_with_conflicting_names@index.index_single(IndexablePath.new("/fake", "/fake/path/foo.rb"), <<~RUBY)
module Foo
class Float < self
INFINITY = ::Float::INFINITY
end
end
RUBYentry = @index.resolve("INFINITY", ["Foo", "Float"]).firstrefute_nil(entry)
assert_instance_of(Entry::UnresolvedAlias, entry)
end
test_searching_for_entries_based_on_prefix()
# File lib/ruby_indexer/test/index_test.rb, line 142deftest_searching_for_entries_based_on_prefix@index.index_single(IndexablePath.new("/fake", "/fake/path/foo.rb"), <<~RUBY)
class Foo::Bar
end
RUBY@index.index_single(IndexablePath.new("/fake", "/fake/path/other_foo.rb"), <<~RUBY)
class Foo::Bar
end
class Foo::Baz
end
RUBYresults = @index.prefix_search("Foo", []).map { |entries|entries.map(&:name) }
assert_equal([["Foo::Bar", "Foo::Bar"], ["Foo::Baz"]], results)
results = @index.prefix_search("Ba", ["Foo"]).map { |entries|entries.map(&:name) }
assert_equal([["Foo::Bar", "Foo::Bar"], ["Foo::Baz"]], results)
end
test_searching_for_require_paths()
# File lib/ruby_indexer/test/index_test.rb, line 129deftest_searching_for_require_paths@index.index_single(IndexablePath.new("/fake", "/fake/path/foo.rb"), <<~RUBY)
class Foo
end
RUBY@index.index_single(IndexablePath.new("/fake", "/fake/path/other_foo.rb"), <<~RUBY)
class Foo
end
RUBYassert_equal(["path/foo", "path/other_foo"], @index.search_require_paths("path").map(&:require_path))
end