# File lib/ruby_indexer/test/classes_and_modules_test.rb, line 17deftest_class_with_statementsindex(<<~RUBY)
class Foo
def something; end
end
RUBYassert_entry("Foo", Entry::Class, "/fake/path/foo.rb:0-0:2-3")
end
test_colon_colon_class()
# File lib/ruby_indexer/test/classes_and_modules_test.rb, line 27deftest_colon_colon_classindex(<<~RUBY)
class ::Foo
end
RUBYassert_entry("Foo", Entry::Class, "/fake/path/foo.rb:0-0:1-3")
end
test_colon_colon_class_inside_class()
# File lib/ruby_indexer/test/classes_and_modules_test.rb, line 36deftest_colon_colon_class_inside_classindex(<<~RUBY)
class Bar
class ::Foo
end
end
RUBYassert_entry("Bar", Entry::Class, "/fake/path/foo.rb:0-0:3-3")
assert_entry("Foo", Entry::Class, "/fake/path/foo.rb:1-2:2-5")
end
test_colon_colon_module()
# File lib/ruby_indexer/test/classes_and_modules_test.rb, line 85deftest_colon_colon_moduleindex(<<~RUBY)
module ::Foo
end
RUBYassert_entry("Foo", Entry::Module, "/fake/path/foo.rb:0-0:1-3")
end
test_comments_can_be_attached_to_a_class()
# File lib/ruby_indexer/test/classes_and_modules_test.rb, line 147deftest_comments_can_be_attached_to_a_classindex(<<~RUBY)
# This is method comment
def foo; end
# This is a Foo comment
# This is another Foo comment
class Foo
# This should not be attached
end
# Ignore me
# This Bar comment has 1 line padding
class Bar; end
RUBYfoo_entry = @index["Foo"].firstassert_equal("This is a Foo comment\nThis is another Foo comment", foo_entry.comments.join("\n"))
bar_entry = @index["Bar"].firstassert_equal("This Bar comment has 1 line padding", bar_entry.comments.join("\n"))
end
# File lib/ruby_indexer/test/classes_and_modules_test.rb, line 180deftest_comments_can_be_attached_to_a_namespaced_classindex(<<~RUBY)
# This is a Foo comment
# This is another Foo comment
class Foo
# This is a Bar comment
class Bar; end
end
RUBYfoo_entry = @index["Foo"].firstassert_equal("This is a Foo comment\nThis is another Foo comment", foo_entry.comments.join("\n"))
bar_entry = @index["Foo::Bar"].firstassert_equal("This is a Bar comment", bar_entry.comments.join("\n"))
end
# File lib/ruby_indexer/test/classes_and_modules_test.rb, line 197deftest_comments_can_be_attached_to_a_reopened_classindex(<<~RUBY)
# This is a Foo comment
class Foo; end
# This is another Foo comment
class Foo; end
RUBYfirst_foo_entry = @index["Foo"][0]
assert_equal("This is a Foo comment", first_foo_entry.comments.join("\n"))
second_foo_entry = @index["Foo"][1]
assert_equal("This is another Foo comment", second_foo_entry.comments.join("\n"))
end
# File lib/ruby_indexer/test/classes_and_modules_test.rb, line 213deftest_comments_removes_the_leading_pound_and_spaceindex(<<~RUBY)
# This is a Foo comment
class Foo; end
#This is a Bar comment
class Bar; end
RUBYfirst_foo_entry = @index["Foo"][0]
assert_equal("This is a Foo comment", first_foo_entry.comments.join("\n"))
second_foo_entry = @index["Bar"][0]
assert_equal("This is a Bar comment", second_foo_entry.comments.join("\n"))
end
test_deleting_from_index_based_on_file_path()
# File lib/ruby_indexer/test/classes_and_modules_test.rb, line 134deftest_deleting_from_index_based_on_file_pathindex(<<~RUBY)
class Foo
end
RUBYassert_entry("Foo", Entry::Class, "/fake/path/foo.rb:0-0:1-3")
@index.delete(IndexablePath.new(nil, "/fake/path/foo.rb"))
refute_entry("Foo")
assert_empty(@index.instance_variable_get(:@files_to_entries))
end
test_dynamically_namespaced_class()
# File lib/ruby_indexer/test/classes_and_modules_test.rb, line 57deftest_dynamically_namespaced_classindex(<<~RUBY)
class self::Bar
end
RUBYrefute_entry("self::Bar")
end
test_dynamically_namespaced_module()
# File lib/ruby_indexer/test/classes_and_modules_test.rb, line 103deftest_dynamically_namespaced_moduleindex(<<~RUBY)
module self::Bar
end
RUBYrefute_entry("self::Bar")
end
test_empty_statements_class()
# File lib/ruby_indexer/test/classes_and_modules_test.rb, line 8deftest_empty_statements_classindex(<<~RUBY)
class Foo
end
RUBYassert_entry("Foo", Entry::Class, "/fake/path/foo.rb:0-0:1-3")
end
test_empty_statements_module()
# File lib/ruby_indexer/test/classes_and_modules_test.rb, line 66deftest_empty_statements_moduleindex(<<~RUBY)
module Foo
end
RUBYassert_entry("Foo", Entry::Module, "/fake/path/foo.rb:0-0:1-3")
end
test_keeping_track_of_included_modules()
# File lib/ruby_indexer/test/classes_and_modules_test.rb, line 285deftest_keeping_track_of_included_modulesindex(<<~RUBY)
class Foo
# valid syntaxes that we can index
include A1
self.include A2
include A3, A4
self.include A5, A6
# valid syntaxes that we cannot index because of their dynamic nature
include some_variable_or_method_call
self.include some_variable_or_method_call
def something
include A7 # We should not index this because of this dynamic nature
end
# Valid inner class syntax definition with its own modules included
class Qux
include Corge
self.include Corge
include Baz
include some_variable_or_method_call
end
end
class ConstantPathReferences
include Foo::Bar
self.include Foo::Bar2
include dynamic::Bar
include Foo::
end
RUBYfoo = T.must(@index["Foo"][0])
assert_equal(["A1", "A2", "A3", "A4", "A5", "A6"], foo.included_modules)
qux = T.must(@index["Foo::Qux"][0])
assert_equal(["Corge", "Corge", "Baz"], qux.included_modules)
constant_path_references = T.must(@index["ConstantPathReferences"][0])
assert_equal(["Foo::Bar", "Foo::Bar2"], constant_path_references.included_modules)
end
test_keeping_track_of_prepended_modules()
# File lib/ruby_indexer/test/classes_and_modules_test.rb, line 331deftest_keeping_track_of_prepended_modulesindex(<<~RUBY)
class Foo
# valid syntaxes that we can index
prepend A1
self.prepend A2
prepend A3, A4
self.prepend A5, A6
# valid syntaxes that we cannot index because of their dynamic nature
prepend some_variable_or_method_call
self.prepend some_variable_or_method_call
def something
prepend A7 # We should not index this because of this dynamic nature
end
# Valid inner class syntax definition with its own modules prepended
class Qux
prepend Corge
self.prepend Corge
prepend Baz
prepend some_variable_or_method_call
end
end
class ConstantPathReferences
prepend Foo::Bar
self.prepend Foo::Bar2
prepend dynamic::Bar
prepend Foo::
end
RUBYfoo = T.must(@index["Foo"][0])
assert_equal(["A1", "A2", "A3", "A4", "A5", "A6"], foo.prepended_modules)
qux = T.must(@index["Foo::Qux"][0])
assert_equal(["Corge", "Corge", "Baz"], qux.prepended_modules)
constant_path_references = T.must(@index["ConstantPathReferences"][0])
assert_equal(["Foo::Bar", "Foo::Bar2"], constant_path_references.prepended_modules)
end
test_keeping_track_of_super_classes()
# File lib/ruby_indexer/test/classes_and_modules_test.rb, line 252deftest_keeping_track_of_super_classesindex(<<~RUBY)
class Foo < Bar
end
class Baz
end
module Something
class Baz
end
class Qux < ::Baz
end
end
class FinalThing < Something::Baz
end
RUBYfoo = T.must(@index["Foo"].first)
assert_equal("Bar", foo.parent_class)
baz = T.must(@index["Baz"].first)
assert_nil(baz.parent_class)
qux = T.must(@index["Something::Qux"].first)
assert_equal("::Baz", qux.parent_class)
final_thing = T.must(@index["FinalThing"].first)
assert_equal("Something::Baz", final_thing.parent_class)
end
test_module_with_statements()
# File lib/ruby_indexer/test/classes_and_modules_test.rb, line 75deftest_module_with_statementsindex(<<~RUBY)
module Foo
def something; end
end
RUBYassert_entry("Foo", Entry::Module, "/fake/path/foo.rb:0-0:2-3")
end
test_namespaced_class()
# File lib/ruby_indexer/test/classes_and_modules_test.rb, line 48deftest_namespaced_classindex(<<~RUBY)
class Foo::Bar
end
RUBYassert_entry("Foo::Bar", Entry::Class, "/fake/path/foo.rb:0-0:1-3")
end
test_namespaced_module()
# File lib/ruby_indexer/test/classes_and_modules_test.rb, line 94deftest_namespaced_moduleindex(<<~RUBY)
module Foo::Bar
end
RUBYassert_entry("Foo::Bar", Entry::Module, "/fake/path/foo.rb:0-0:1-3")
end
test_nested_modules_and_classes()
# File lib/ruby_indexer/test/classes_and_modules_test.rb, line 112deftest_nested_modules_and_classesindex(<<~RUBY)
module Foo
class Bar
end
module Baz
class Qux
class Something
end
end
end
end
RUBYassert_entry("Foo", Entry::Module, "/fake/path/foo.rb:0-0:10-3")
assert_entry("Foo::Bar", Entry::Class, "/fake/path/foo.rb:1-2:2-5")
assert_entry("Foo::Baz", Entry::Module, "/fake/path/foo.rb:4-2:9-5")
assert_entry("Foo::Baz::Qux", Entry::Class, "/fake/path/foo.rb:5-4:8-7")
assert_entry("Foo::Baz::Qux::Something", Entry::Class, "/fake/path/foo.rb:6-6:7-9")
end
test_private_class_and_module_indexing()
# File lib/ruby_indexer/test/classes_and_modules_test.rb, line 229deftest_private_class_and_module_indexingindex(<<~RUBY)
class A
class B; end
private_constant(:B)
module C; end
private_constant("C")
class D; end
end
RUBYb_const = @index["A::B"].firstassert_equal(:private, b_const.visibility)
c_const = @index["A::C"].firstassert_equal(:private, c_const.visibility)
d_const = @index["A::D"].firstassert_equal(:public, d_const.visibility)
end
# File lib/ruby_indexer/test/classes_and_modules_test.rb, line 171deftest_skips_comments_containing_invalid_encodingsindex(<<~RUBY)
# comment \xBA
class Foo
end
RUBYassert(@index["Foo"].first)
end