Skip to content

Commit 3f4b788

Browse files
Merge pull request #754 from Shopify/test-type-simplify-normalize
Tests for simplifying and normalizing types in sigs during translation
2 parents 0c1edb8 + a5c6390 commit 3f4b788

2 files changed

Lines changed: 49 additions & 2 deletions

File tree

Gemfile.lock

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,9 @@ GEM
5252
racc (1.8.1)
5353
rainbow (3.1.1)
5454
rake (13.3.0)
55-
rbi (0.3.3)
55+
rbi (0.3.5)
5656
prism (~> 1.0)
5757
rbs (>= 3.4.4)
58-
sorbet-runtime (>= 0.5.9204)
5958
rbs (4.0.0.dev.4)
6059
logger
6160
prism (>= 1.3.0)

test/spoom/sorbet/translate/sorbet_sigs_to_rbs_comments_test.rb

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,54 @@ def foo
336336
RBS
337337
end
338338

339+
def test_translate_to_rbs_with_nested_nilable_param
340+
contents = <<~RB
341+
Class.new do
342+
sig { params(x: T.nilable(T.nilable(Integer))).void }
343+
def foo(x); end
344+
end
345+
RB
346+
347+
assert_equal(<<~RBS, sorbet_sigs_to_rbs_comments(contents))
348+
Class.new do
349+
#: (Integer? x) -> void
350+
def foo(x); end
351+
end
352+
RBS
353+
end
354+
355+
def test_translate_to_rbs_with_nested_any_param
356+
contents = <<~RB
357+
Class.new do
358+
sig { params(x: T.any(T.any(Integer, String), Float, Integer)).void }
359+
def foo(x); end
360+
end
361+
RB
362+
363+
assert_equal(<<~RBS, sorbet_sigs_to_rbs_comments(contents))
364+
Class.new do
365+
#: ((Integer | String | Float) x) -> void
366+
def foo(x); end
367+
end
368+
RBS
369+
end
370+
371+
def test_translate_to_rbs_with_nested_all_param
372+
contents = <<~RB
373+
Class.new do
374+
sig { params(x: T.all(T.all(Enumerable, Comparable), Numeric, Enumerable)).void }
375+
def foo(x); end
376+
end
377+
RB
378+
379+
assert_equal(<<~RBS, sorbet_sigs_to_rbs_comments(contents))
380+
Class.new do
381+
#: ((Enumerable & Comparable & Numeric) x) -> void
382+
def foo(x); end
383+
end
384+
RBS
385+
end
386+
339387
private
340388

341389
#: (String, ?positional_names: bool) -> String

0 commit comments

Comments
 (0)