# File lib/ruby_indexer/test/rbs_indexer_test.rb, line 79deftest_attaches_correct_owner_to_singleton_methodsentries = @index["basename"]
refute_nil(entries)
owner = entries.first.ownerassert_instance_of(Entry::SingletonClass, owner)
assert_equal("File::<Class:File>", owner.name)
end
test_index_core_classes()
# File lib/ruby_indexer/test/rbs_indexer_test.rb, line 8deftest_index_core_classesentries = @index["Array"]
refute_nil(entries)
# Array is a class but also an instance method on Kernelassert_equal(2, entries.length)
entry = entries.find { |entry|entry.is_a?(RubyIndexer::Entry::Class) }
assert_match(%r{/gems/rbs-.*/core/array.rbs}, entry.file_path)
assert_equal("array.rbs", entry.file_name)
assert_equal("Object", entry.parent_class)
assert_equal(1, entry.mixin_operations.length)
enumerable_include = entry.mixin_operations.firstassert_equal("Enumerable", enumerable_include.module_name)
# Using fixed positions would be fragile, so let's just check some basics.assert_operator(entry.location.start_line, :>, 0)
assert_operator(entry.location.end_line, :>, entry.location.start_line)
assert_equal(0, entry.location.start_column)
assert_operator(entry.location.end_column, :>, 0)
end
test_index_core_constants()
# File lib/ruby_indexer/test/rbs_indexer_test.rb, line 43deftest_index_core_constantsentries = @index["RUBY_VERSION"]
refute_nil(entries)
assert_equal(1, entries.length)
# Complex::I is defined as `Complex::I = ...`entries = @index["Complex::I"]
refute_nil(entries)
assert_equal(1, entries.length)
# Encoding::US_ASCII is defined as# ```# module Encoding# US_ASCII = ...# ...# ````entries = @index["Encoding::US_ASCII"]
refute_nil(entries)
assert_equal(1, entries.length)
end
test_index_core_modules()
# File lib/ruby_indexer/test/rbs_indexer_test.rb, line 28deftest_index_core_modulesentries = @index["Kernel"]
refute_nil(entries)
assert_equal(1, entries.length)
entry = entries.firstassert_match(%r{/gems/rbs-.*/core/kernel.rbs}, entry.file_path)
assert_equal("kernel.rbs", entry.file_name)
# Using fixed positions would be fragile, so let's just check some basics.assert_operator(entry.location.start_line, :>, 0)
assert_operator(entry.location.end_line, :>, entry.location.start_line)
assert_equal(0, entry.location.start_column)
assert_operator(entry.location.end_column, :>, 0)
end
test_index_methods()
# File lib/ruby_indexer/test/rbs_indexer_test.rb, line 64deftest_index_methodsentries = @index["initialize"]
refute_nil(entries)
entry = entries.find { |entry|entry.owner.name=="Array" }
assert_match(%r{/gems/rbs-.*/core/array.rbs}, entry.file_path)
assert_equal("array.rbs", entry.file_name)
assert_equal(Entry::Visibility::PUBLIC, entry.visibility)
# Using fixed positions would be fragile, so let's just check some basics.assert_operator(entry.location.start_line, :>, 0)
assert_operator(entry.location.end_line, :>, entry.location.start_line)
assert_equal(2, entry.location.start_column)
assert_operator(entry.location.end_column, :>, 0)
end
test_location_and_name_location_are_the_same()
# File lib/ruby_indexer/test/rbs_indexer_test.rb, line 88deftest_location_and_name_location_are_the_same# NOTE: RBS does not store the name location for classes, modules or methods. This behaviour is not exactly what# we would like, but for now we assign the same location to bothentries = @index["Array"]
refute_nil(entries)
entry = entries.find { |entry|entry.is_a?(Entry::Class) }
assert_same(entry.location, entry.name_location)
end
# File lib/ruby_indexer/test/rbs_indexer_test.rb, line 280deftest_rbs_method_with_required_keywords# There are no methods in Core that have required keyword arguments,# so we test against RBS directlyrbs = <<~RBS class File
def foo: (a: ::Numeric sz, b: ::Numeric) -> void
end
RBSsignatures = parse_rbs_methods(rbs, "foo")
parameters = signatures[0].parametersassert_equal([:a, :b], parameters.map(&:name))
assert_kind_of(Entry::KeywordParameter, parameters[0])
assert_kind_of(Entry::KeywordParameter, parameters[1])
end
# File lib/ruby_indexer/test/rbs_indexer_test.rb, line 116deftest_rbs_method_with_unnamed_required_positionalsentries = @index["try_convert"]
entry = entries.find { |entry|entry.owner.name=="Array::<Class:Array>" }
parameters = entry.signatures[0].parametersassert_equal([:arg0], parameters.map(&:name))
assert_kind_of(Entry::RequiredParameter, parameters[0])
end
test_signature_alias()
# File lib/ruby_indexer/test/rbs_indexer_test.rb, line 334deftest_signature_alias# In RBS, an alias means that two methods have the same signature.# It does not mean the same thing as a Ruby alias.any_entries = @index["any?"]
assert_equal(["Array", "Enumerable", "Hash"], any_entries.map { _1.owner.name })
entry = any_entries.find { |entry|entry.owner.name=="Array" }
assert_kind_of(RubyIndexer::Entry::UnresolvedMethodAlias, entry)
assert_equal("any?", entry.name)
assert_equal("all?", entry.old_name)
assert_equal("Array", entry.owner.name)
assert(entry.file_path.end_with?("core/array.rbs"))
assert_includes(entry.comments[0], "Returns `true` if any element of `self` meets a given criterion.")
end