@@ -99,10 +99,12 @@ TEST_CASE("t_rb_generator uses suffixed field id constants to avoid FIELDS colli
9999 std::remove (thrift_path.c_str ());
100100}
101101
102- TEST_CASE (" t_rb_generator emits service arguments as a positional hash " , " [functional]" )
102+ TEST_CASE (" t_rb_generator formats service classes and positional arguments " , " [functional]" )
103103{
104104 const string thrift_path = " test_service_arguments.thrift" ;
105105 const string thrift_source =
106+ " service EmptyService {\n "
107+ " }\n "
106108 " service PingService {\n "
107109 " oneway void ping(1: i32 n)\n "
108110 " }\n " ;
@@ -123,7 +125,18 @@ TEST_CASE("t_rb_generator emits service arguments as a positional hash", "[funct
123125 REQUIRE_NOTHROW (gen->generate_program ());
124126
125127 const string service = read_file (" gen-rb/ping_service.rb" );
128+ const string expected_empty_result =
129+ " class Ping_result\n "
130+ " include ::Thrift::Struct, ::Thrift::Struct_Union\n "
131+ " \n "
132+ " FIELDS" ;
126133 REQUIRE (service.find (" send_oneway_message(\" ping\" , Ping_args, {n: n})" ) != string::npos);
134+ REQUIRE (service.find (expected_empty_result) != string::npos);
135+ REQUIRE (service.find (" \n\n end\n " ) == string::npos);
136+
137+ const string empty_service = read_file (" gen-rb/empty_service.rb" );
138+ REQUIRE (!empty_service.empty ());
139+ REQUIRE (empty_service.find (" \n\n end\n " ) == string::npos);
127140
128141 std::remove (thrift_path.c_str ());
129142}
@@ -135,6 +148,9 @@ TEST_CASE("t_rb_generator formats multiline Ruby literals, calls, and field meta
135148 " struct Item {\n "
136149 " 1: string value\n "
137150 " }\n "
151+ " union Choice {\n "
152+ " 1: string value\n "
153+ " }\n "
138154 " const Item ITEM = {\" value\" : \" one\" }\n "
139155 " const set<i32> IDS = [1, 2]\n "
140156 " struct Defaults {\n "
@@ -157,14 +173,39 @@ TEST_CASE("t_rb_generator formats multiline Ruby literals, calls, and field meta
157173 REQUIRE_NOTHROW (gen->generate_program ());
158174
159175 const string constants = read_file (" gen-rb/test_multiline_layout_constants.rb" );
160- REQUIRE (constants.find (" ITEM = ::Item.new({\n %q\" value\" => %q\" one\" ,\n })" )
161- != string::npos);
162- REQUIRE (constants.find (" IDS = Set.new([\n 1,\n 2,\n ])" ) != string::npos);
176+ const string expected_item_constant =
177+ " ITEM = ::Item.new({\n "
178+ " %q\" value\" => %q\" one\" ,\n "
179+ " })" ;
180+ const string expected_set_constant =
181+ " IDS = Set.new([\n "
182+ " 1,\n "
183+ " 2,\n "
184+ " ])" ;
185+ REQUIRE (constants.find (expected_item_constant) != string::npos);
186+ REQUIRE (constants.find (expected_set_constant) != string::npos);
163187
164188 const string types = read_file (" gen-rb/test_multiline_layout_types.rb" );
165- REQUIRE (types.find (" VALUES_FIELD_ID => {\n type: ::Thrift::Types::LIST,\n " )
166- != string::npos);
167- REQUIRE (types.find (" default: [\n 1,\n 2,\n ],\n " ) != string::npos);
189+ const string expected_struct =
190+ " class Item\n "
191+ " include ::Thrift::Struct, ::Thrift::Struct_Union\n "
192+ " \n " ;
193+ const string expected_union =
194+ " class Choice < ::Thrift::Union\n "
195+ " include ::Thrift::Struct_Union\n "
196+ " \n " ;
197+ const string expected_field_metadata =
198+ " VALUES_FIELD_ID => {\n "
199+ " type: ::Thrift::Types::LIST,\n " ;
200+ const string expected_default =
201+ " default: [\n "
202+ " 1,\n "
203+ " 2,\n "
204+ " ],\n " ;
205+ REQUIRE (types.find (expected_struct) != string::npos);
206+ REQUIRE (types.find (expected_union) != string::npos);
207+ REQUIRE (types.find (expected_field_metadata) != string::npos);
208+ REQUIRE (types.find (expected_default) != string::npos);
168209
169210 std::remove (thrift_path.c_str ());
170211}
0 commit comments