Skip to content

Commit

Permalink
Merge pull request #1103 from ruby/dedup-comments
Browse files Browse the repository at this point in the history
Dedup method comments
  • Loading branch information
soutaro authored Sep 2, 2022
2 parents 6250b97 + 933c681 commit 963de8c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rbs/definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def method_types
end

def comments
@comments ||= _ = defs.map(&:comment).compact
@comments ||= defs.map(&:comment).compact.uniq
end

def annotations
Expand Down
21 changes: 21 additions & 0 deletions test/rbs/definition_builder_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,27 @@ def foo: (String) -> String | ...
end
end

def test_build_comment_dedup
SignatureManager.new do |manager|
manager.files.merge!(Pathname("foo.rbs") => <<-EOF)
class Hello
# doc1
def foo: () -> String
| (Integer) -> String
end
EOF
manager.build do |env|
builder = DefinitionBuilder.new(env: env)

builder.build_instance(type_name("::Hello")).tap do |definition|
foo = definition.methods[:foo]

assert_equal 1, foo.comments.size
end
end
end
end

def test_build_instance_method_variance
SignatureManager.new do |manager|
manager.files.merge!(Pathname("foo.rbs") => <<-EOF)
Expand Down

0 comments on commit 963de8c

Please sign in to comment.