diff --git a/lib/rbi/rbs_printer.rb b/lib/rbi/rbs_printer.rb index 076a6909..f3fc41d4 100644 --- a/lib/rbi/rbs_printer.rb +++ b/lib/rbi/rbs_printer.rb @@ -842,7 +842,7 @@ def visit(node) sig { params(type: Type::Simple).void } def visit_simple(type) - @string << translate_t_type(type.name) + @string << translate_t_type(type.name.gsub(/\s/, "")) end sig { params(type: Type::Boolean).void } @@ -852,7 +852,7 @@ def visit_boolean(type) sig { params(type: Type::Generic).void } def visit_generic(type) - @string << translate_t_type(type.name) + @string << translate_t_type(type.name.gsub(/\s/, "")) @string << "[" type.params.each_with_index do |arg, index| visit(arg) diff --git a/test/rbi/parser_test.rb b/test/rbi/parser_test.rb index e2288228..66b516a8 100644 --- a/test/rbi/parser_test.rb +++ b/test/rbi/parser_test.rb @@ -88,6 +88,16 @@ def test_parse_constants assert_equal(rbi, tree.string) end + def test_parse_constants_with_newlines + rbi = <<~RBI + sig { returns(Foo:: + Bar) } + RBI + + tree = parse_rbi(rbi) + assert_equal(rbi, tree.string) + end + def test_parse_attributes rbi = <<~RBI attr_reader :a diff --git a/test/rbi/rbs_printer_test.rb b/test/rbi/rbs_printer_test.rb index 66349b8d..7c5f36ad 100644 --- a/test/rbi/rbs_printer_test.rb +++ b/test/rbi/rbs_printer_test.rb @@ -268,6 +268,18 @@ def test_print_attr_sig RBI end + def test_print_signature_with_newlines + rbi = parse_rbi(<<~RBI) + sig { returns(T.class_of(Foo:: + Bar)) } + def foo; end + RBI + + assert_equal(<<~RBI, rbi.rbs_string) + def foo: -> singleton(Foo::Bar) + RBI + end + def test_print_methods_without_signature rbi = parse_rbi(<<~RBI) def foo; end