@@ -17,7 +17,8 @@ def test_message_with_base_type
1717 translator = RBSProtobuf ::Translator ::ProtobufGem . new (
1818 input ,
1919 upcase_enum : true ,
20- nested_namespace : true
20+ nested_namespace : true ,
21+ extension : false
2122 )
2223 content = translator . rbs_content ( input . proto_file [ 0 ] )
2324
@@ -60,7 +61,8 @@ def test_message_with_bool_predicate
6061 translator = RBSProtobuf ::Translator ::ProtobufGem . new (
6162 input ,
6263 upcase_enum : true ,
63- nested_namespace : true
64+ nested_namespace : true ,
65+ extension : false
6466 )
6567 content = translator . rbs_content ( input . proto_file [ 0 ] )
6668
@@ -100,7 +102,8 @@ def test_message_with_message
100102 translator = RBSProtobuf ::Translator ::ProtobufGem . new (
101103 input ,
102104 upcase_enum : false ,
103- nested_namespace : true
105+ nested_namespace : true ,
106+ extension : false
104107 )
105108 content = translator . rbs_content ( input . proto_file [ 0 ] )
106109
@@ -146,7 +149,8 @@ def test_enum
146149 translator = RBSProtobuf ::Translator ::ProtobufGem . new (
147150 input ,
148151 upcase_enum : false ,
149- nested_namespace : true
152+ nested_namespace : true ,
153+ extension : false
150154 )
151155 content = translator . rbs_content ( input . proto_file [ 0 ] )
152156
@@ -185,7 +189,8 @@ def test_enum_with_alias
185189 translator = RBSProtobuf ::Translator ::ProtobufGem . new (
186190 input ,
187191 upcase_enum : false ,
188- nested_namespace : true
192+ nested_namespace : true ,
193+ extension : false
189194 )
190195 content = translator . rbs_content ( input . proto_file [ 0 ] )
191196
@@ -228,7 +233,8 @@ def test_message_with_enum
228233 translator = RBSProtobuf ::Translator ::ProtobufGem . new (
229234 input ,
230235 upcase_enum : true ,
231- nested_namespace : true
236+ nested_namespace : true ,
237+ extension : false
232238 )
233239 content = translator . rbs_content ( input . proto_file [ 0 ] )
234240
@@ -290,7 +296,8 @@ def test_message_with_package
290296 translator = RBSProtobuf ::Translator ::ProtobufGem . new (
291297 input ,
292298 upcase_enum : true ,
293- nested_namespace : true
299+ nested_namespace : true ,
300+ extension : false
294301 )
295302 content = translator . rbs_content ( input . proto_file [ 0 ] )
296303
@@ -332,7 +339,8 @@ def test_message_with_package_flat_namespace
332339 translator = RBSProtobuf ::Translator ::ProtobufGem . new (
333340 input ,
334341 upcase_enum : true ,
335- nested_namespace : false
342+ nested_namespace : false ,
343+ extension : false
336344 )
337345 content = translator . rbs_content ( input . proto_file [ 0 ] )
338346
@@ -360,7 +368,8 @@ def test_message_with_one_of
360368 translator = RBSProtobuf ::Translator ::ProtobufGem . new (
361369 input ,
362370 upcase_enum : true ,
363- nested_namespace : true
371+ nested_namespace : true ,
372+ extension : false
364373 )
365374 content = translator . rbs_content ( input . proto_file [ 0 ] )
366375
@@ -400,7 +409,8 @@ def test_message_with_map_to_base_and_message
400409 translator = RBSProtobuf ::Translator ::ProtobufGem . new (
401410 input ,
402411 upcase_enum : true ,
403- nested_namespace : true
412+ nested_namespace : true ,
413+ extension : false
404414 )
405415 content = translator . rbs_content ( input . proto_file [ 0 ] )
406416
@@ -442,7 +452,8 @@ def test_message_with_map_to_enum
442452 translator = RBSProtobuf ::Translator ::ProtobufGem . new (
443453 input ,
444454 upcase_enum : true ,
445- nested_namespace : true
455+ nested_namespace : true ,
456+ extension : false
446457 )
447458 content = translator . rbs_content ( input . proto_file [ 0 ] )
448459
@@ -495,7 +506,8 @@ def test_message_with_map_with_package
495506 translator = RBSProtobuf ::Translator ::ProtobufGem . new (
496507 input ,
497508 upcase_enum : true ,
498- nested_namespace : true
509+ nested_namespace : true ,
510+ extension : false
499511 )
500512 content = translator . rbs_content ( input . proto_file [ 0 ] )
501513
@@ -534,7 +546,8 @@ def test_nested_message
534546 translator = RBSProtobuf ::Translator ::ProtobufGem . new (
535547 input ,
536548 upcase_enum : true ,
537- nested_namespace : true
549+ nested_namespace : true ,
550+ extension : false
538551 )
539552 content = translator . rbs_content ( input . proto_file [ 0 ] )
540553
@@ -574,7 +587,8 @@ def test_nested_enum
574587 translator = RBSProtobuf ::Translator ::ProtobufGem . new (
575588 input ,
576589 upcase_enum : true ,
577- nested_namespace : true
590+ nested_namespace : true ,
591+ extension : false
578592 )
579593 content = translator . rbs_content ( input . proto_file [ 0 ] )
580594
@@ -635,7 +649,8 @@ def test_service
635649 translator = RBSProtobuf ::Translator ::ProtobufGem . new (
636650 input ,
637651 upcase_enum : true ,
638- nested_namespace : true
652+ nested_namespace : true ,
653+ extension : false
639654 )
640655 content = translator . rbs_content ( input . proto_file [ 0 ] )
641656
@@ -678,7 +693,8 @@ def test_extension
678693 translator = RBSProtobuf ::Translator ::ProtobufGem . new (
679694 input ,
680695 upcase_enum : true ,
681- nested_namespace : true
696+ nested_namespace : true ,
697+ extension : true
682698 )
683699 content = translator . rbs_content ( input . proto_file [ 0 ] )
684700
@@ -710,6 +726,95 @@ def []: (:parent) -> ::Test::M1?
710726 def []=: (:parent, ::Test::M1?) -> ::Test::M1?
711727 | ...
712728end
729+ RBS
730+ end
731+
732+ def test_extension_ignore
733+ input = read_proto ( <<EOP )
734+ syntax = "proto2";
735+
736+ package test;
737+
738+ message M1 {
739+ extensions 100 to max;
740+ }
741+
742+ extend M1 {
743+ optional string name = 100;
744+ }
745+ EOP
746+ stderr = StringIO . new
747+
748+ translator = RBSProtobuf ::Translator ::ProtobufGem . new (
749+ input ,
750+ upcase_enum : true ,
751+ nested_namespace : true ,
752+ extension : nil ,
753+ stderr : stderr
754+ )
755+ content = translator . rbs_content ( input . proto_file [ 0 ] )
756+
757+ assert_equal <<RBS , content
758+ module Test
759+ class M1 < ::Protobuf::Message
760+ def initialize: () -> void
761+ end
762+ end
763+ RBS
764+ assert_equal <<RBS , stderr . string
765+ Extension for `.test.M1` ignored in `a.proto`; Set RBS_PROTOBUF_EXTENSION env var to generate RBS for extensions.
766+ RBS
767+ end
768+
769+ def test_extension_print
770+ input = read_proto ( <<EOP )
771+ syntax = "proto2";
772+
773+ package test;
774+
775+ message M1 {
776+ extensions 100 to max;
777+ }
778+
779+ extend M1 {
780+ optional string name = 100;
781+ }
782+ EOP
783+ stderr = StringIO . new
784+
785+ translator = RBSProtobuf ::Translator ::ProtobufGem . new (
786+ input ,
787+ upcase_enum : true ,
788+ nested_namespace : true ,
789+ extension : :print ,
790+ stderr : stderr
791+ )
792+ content = translator . rbs_content ( input . proto_file [ 0 ] )
793+
794+ assert_equal <<RBS , content
795+ module Test
796+ class M1 < ::Protobuf::Message
797+ def initialize: () -> void
798+ end
799+ end
800+ RBS
801+
802+ assert_equal <<RBS , stderr . string
803+ #==========================================================
804+ # Printing RBS for extensions from a.proto
805+ #
806+ class ::Test::M1
807+ attr_reader name(): ::String
808+
809+ attr_writer name(): ::String?
810+
811+ def []: (:name) -> ::String
812+ | ...
813+
814+ def []=: (:name, ::String?) -> ::String?
815+ | ...
816+ end
817+
713818RBS
714819 end
715820end
0 commit comments