Sha256: 583ef38fe607fec4d6688dd2b0f9d5389617da65ca966dc5fe581bf6df9962fe

Contents?: true

Size: 1.69 KB

Versions: 10

Compression:

Stored size: 1.69 KB

Contents

# typed: true
# frozen_string_literal: true

require_relative "test_case"

module RubyIndexer
  class MethodTest < TestCase
    def test_method_with_no_parameters
      index(<<~RUBY)
        class Foo
          def bar
          end
        end
      RUBY

      assert_entry("bar", Entry::InstanceMethod, "/fake/path/foo.rb:1-2:2-5")
    end

    def test_singleton_method_using_self_receiver
      index(<<~RUBY)
        class Foo
          def self.bar
          end
        end
      RUBY

      assert_entry("bar", Entry::SingletonMethod, "/fake/path/foo.rb:1-2:2-5")
    end

    def test_singleton_method_using_other_receiver_is_not_indexed
      index(<<~RUBY)
        class Foo
          def String.bar
          end
        end
      RUBY

      assert_no_entry("bar")
    end

    def test_method_with_parameters
      index(<<~RUBY)
        class Foo
          def bar(a)
          end
        end
      RUBY

      assert_entry("bar", Entry::InstanceMethod, "/fake/path/foo.rb:1-2:2-5")
      entry = T.must(@index["bar"].first)
      assert_equal(1, entry.parameters.length)
      parameter = entry.parameters.first
      assert_equal(:a, parameter.name)
      assert_instance_of(Entry::RequiredParameter, parameter)
    end

    def test_method_with_destructed_parameters
      index(<<~RUBY)
        class Foo
          def bar((a, (b, )))
          end
        end
      RUBY

      assert_entry("bar", Entry::InstanceMethod, "/fake/path/foo.rb:1-2:2-5")
      entry = T.must(@index["bar"].first)
      assert_equal(1, entry.parameters.length)
      parameter = entry.parameters.first
      assert_equal(:"(a, (b, ))", parameter.name)
      assert_instance_of(Entry::RequiredParameter, parameter)
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
study_line-0.1.6 vendor/bundle/ruby/3.2.0/gems/ruby-lsp-0.12.1/lib/ruby_indexer/test/method_test.rb
study_line-0.1.5 vendor/bundle/ruby/3.2.0/gems/ruby-lsp-0.12.1/lib/ruby_indexer/test/method_test.rb
study_line-0.1.4 vendor/bundle/ruby/3.2.0/gems/ruby-lsp-0.12.1/lib/ruby_indexer/test/method_test.rb
study_line-0.1.3 vendor/bundle/ruby/3.2.0/gems/ruby-lsp-0.12.1/lib/ruby_indexer/test/method_test.rb
study_line-0.1.2 vendor/bundle/ruby/3.2.0/gems/ruby-lsp-0.12.1/lib/ruby_indexer/test/method_test.rb
study_line-0.1.1 vendor/bundle/ruby/3.2.0/gems/ruby-lsp-0.12.1/lib/ruby_indexer/test/method_test.rb
ruby-lsp-0.12.3 lib/ruby_indexer/test/method_test.rb
ruby-lsp-0.12.2 lib/ruby_indexer/test/method_test.rb
ruby-lsp-0.12.1 lib/ruby_indexer/test/method_test.rb
ruby-lsp-0.12.0 lib/ruby_indexer/test/method_test.rb