Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,9 @@ GEM
racc (1.8.1)
rainbow (3.1.1)
rake (13.3.0)
rbi (0.3.3)
rbi (0.3.5)
prism (~> 1.0)
rbs (>= 3.4.4)
sorbet-runtime (>= 0.5.9204)
rbs (4.0.0.dev.4)
logger
prism (>= 1.3.0)
Expand Down
48 changes: 48 additions & 0 deletions test/spoom/sorbet/translate/sorbet_sigs_to_rbs_comments_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,54 @@ def foo
RBS
end

def test_translate_to_rbs_with_nested_nilable_param
contents = <<~RB
Class.new do
sig { params(x: T.nilable(T.nilable(Integer))).void }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is our logic for this purpose-built for RBS? This kind of normalization would be useful more generally. Would be nice to do: sig -> normalized sig -> RBS

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it's exactly what we did: Shopify/rbi#479

def foo(x); end
end
RB

assert_equal(<<~RBS, sorbet_sigs_to_rbs_comments(contents))
Class.new do
#: (Integer? x) -> void
def foo(x); end
end
RBS
end

def test_translate_to_rbs_with_nested_any_param
contents = <<~RB
Class.new do
sig { params(x: T.any(T.any(Integer, String), Float, Integer)).void }
def foo(x); end
end
RB

assert_equal(<<~RBS, sorbet_sigs_to_rbs_comments(contents))
Class.new do
#: ((Integer | String | Float) x) -> void
def foo(x); end
end
RBS
end

def test_translate_to_rbs_with_nested_all_param
contents = <<~RB
Class.new do
sig { params(x: T.all(T.all(Enumerable, Comparable), Numeric, Enumerable)).void }
def foo(x); end
end
RB

assert_equal(<<~RBS, sorbet_sigs_to_rbs_comments(contents))
Class.new do
#: ((Enumerable & Comparable & Numeric) x) -> void
def foo(x); end
end
RBS
end

private

#: (String, ?positional_names: bool) -> String
Expand Down