stark 0.6.1 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +10 -0
- data/Manifest.txt +3 -0
- data/README.txt +5 -1
- data/Rakefile +0 -2
- data/bin/stark +12 -6
- data/lib/stark/converters.rb +151 -0
- data/lib/stark/parser.rb +28 -0
- data/lib/stark/raw_parser.rb +7 -2
- data/lib/stark/ruby.rb +82 -91
- data/lib/stark/struct.rb +17 -0
- data/lib/stark/thrift.kpeg +1 -1
- data/lib/stark.rb +6 -9
- data/test/blah.thrift +5 -0
- data/test/gen-rb/profile_types.rb +67 -0
- data/test/gen-rb/user_storage.rb +315 -0
- data/test/include_blah.thrift +1 -0
- data/test/legacy_profile/profile_types.rb +67 -0
- data/test/legacy_profile/user_storage.rb +315 -0
- data/test/profile.thrift +30 -1
- data/test/test_client.rb +131 -1
- data/test/test_parser.rb +64 -0
- data/test/test_ruby.rb +27 -0
- data/test/test_server.rb +105 -1
- metadata +6 -2
@@ -165,6 +165,93 @@ module UserStorage
|
|
165
165
|
raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'add failed: unknown result')
|
166
166
|
end
|
167
167
|
|
168
|
+
def user_status()
|
169
|
+
send_user_status()
|
170
|
+
return recv_user_status()
|
171
|
+
end
|
172
|
+
|
173
|
+
def send_user_status()
|
174
|
+
send_message('user_status', User_status_args)
|
175
|
+
end
|
176
|
+
|
177
|
+
def recv_user_status()
|
178
|
+
result = receive_message(User_status_result)
|
179
|
+
return result.success unless result.success.nil?
|
180
|
+
raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'user_status failed: unknown result')
|
181
|
+
end
|
182
|
+
|
183
|
+
def set_user_status(stat)
|
184
|
+
send_set_user_status(stat)
|
185
|
+
recv_set_user_status()
|
186
|
+
end
|
187
|
+
|
188
|
+
def send_set_user_status(stat)
|
189
|
+
send_message('set_user_status', Set_user_status_args, :stat => stat)
|
190
|
+
end
|
191
|
+
|
192
|
+
def recv_set_user_status()
|
193
|
+
result = receive_message(Set_user_status_result)
|
194
|
+
return
|
195
|
+
end
|
196
|
+
|
197
|
+
def user_relationship()
|
198
|
+
send_user_relationship()
|
199
|
+
return recv_user_relationship()
|
200
|
+
end
|
201
|
+
|
202
|
+
def send_user_relationship()
|
203
|
+
send_message('user_relationship', User_relationship_args)
|
204
|
+
end
|
205
|
+
|
206
|
+
def recv_user_relationship()
|
207
|
+
result = receive_message(User_relationship_result)
|
208
|
+
return result.success unless result.success.nil?
|
209
|
+
raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'user_relationship failed: unknown result')
|
210
|
+
end
|
211
|
+
|
212
|
+
def set_user_relationship(rel)
|
213
|
+
send_set_user_relationship(rel)
|
214
|
+
recv_set_user_relationship()
|
215
|
+
end
|
216
|
+
|
217
|
+
def send_set_user_relationship(rel)
|
218
|
+
send_message('set_user_relationship', Set_user_relationship_args, :rel => rel)
|
219
|
+
end
|
220
|
+
|
221
|
+
def recv_set_user_relationship()
|
222
|
+
result = receive_message(Set_user_relationship_result)
|
223
|
+
return
|
224
|
+
end
|
225
|
+
|
226
|
+
def user_friends()
|
227
|
+
send_user_friends()
|
228
|
+
return recv_user_friends()
|
229
|
+
end
|
230
|
+
|
231
|
+
def send_user_friends()
|
232
|
+
send_message('user_friends', User_friends_args)
|
233
|
+
end
|
234
|
+
|
235
|
+
def recv_user_friends()
|
236
|
+
result = receive_message(User_friends_result)
|
237
|
+
return result.success unless result.success.nil?
|
238
|
+
raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'user_friends failed: unknown result')
|
239
|
+
end
|
240
|
+
|
241
|
+
def set_user_friends(fr)
|
242
|
+
send_set_user_friends(fr)
|
243
|
+
recv_set_user_friends()
|
244
|
+
end
|
245
|
+
|
246
|
+
def send_set_user_friends(fr)
|
247
|
+
send_message('set_user_friends', Set_user_friends_args, :fr => fr)
|
248
|
+
end
|
249
|
+
|
250
|
+
def recv_set_user_friends()
|
251
|
+
result = receive_message(Set_user_friends_result)
|
252
|
+
return
|
253
|
+
end
|
254
|
+
|
168
255
|
end
|
169
256
|
|
170
257
|
class Processor
|
@@ -250,6 +337,48 @@ module UserStorage
|
|
250
337
|
write_result(result, oprot, 'add', seqid)
|
251
338
|
end
|
252
339
|
|
340
|
+
def process_user_status(seqid, iprot, oprot)
|
341
|
+
args = read_args(iprot, User_status_args)
|
342
|
+
result = User_status_result.new()
|
343
|
+
result.success = @handler.user_status()
|
344
|
+
write_result(result, oprot, 'user_status', seqid)
|
345
|
+
end
|
346
|
+
|
347
|
+
def process_set_user_status(seqid, iprot, oprot)
|
348
|
+
args = read_args(iprot, Set_user_status_args)
|
349
|
+
result = Set_user_status_result.new()
|
350
|
+
@handler.set_user_status(args.stat)
|
351
|
+
write_result(result, oprot, 'set_user_status', seqid)
|
352
|
+
end
|
353
|
+
|
354
|
+
def process_user_relationship(seqid, iprot, oprot)
|
355
|
+
args = read_args(iprot, User_relationship_args)
|
356
|
+
result = User_relationship_result.new()
|
357
|
+
result.success = @handler.user_relationship()
|
358
|
+
write_result(result, oprot, 'user_relationship', seqid)
|
359
|
+
end
|
360
|
+
|
361
|
+
def process_set_user_relationship(seqid, iprot, oprot)
|
362
|
+
args = read_args(iprot, Set_user_relationship_args)
|
363
|
+
result = Set_user_relationship_result.new()
|
364
|
+
@handler.set_user_relationship(args.rel)
|
365
|
+
write_result(result, oprot, 'set_user_relationship', seqid)
|
366
|
+
end
|
367
|
+
|
368
|
+
def process_user_friends(seqid, iprot, oprot)
|
369
|
+
args = read_args(iprot, User_friends_args)
|
370
|
+
result = User_friends_result.new()
|
371
|
+
result.success = @handler.user_friends()
|
372
|
+
write_result(result, oprot, 'user_friends', seqid)
|
373
|
+
end
|
374
|
+
|
375
|
+
def process_set_user_friends(seqid, iprot, oprot)
|
376
|
+
args = read_args(iprot, Set_user_friends_args)
|
377
|
+
result = Set_user_friends_result.new()
|
378
|
+
@handler.set_user_friends(args.fr)
|
379
|
+
write_result(result, oprot, 'set_user_friends', seqid)
|
380
|
+
end
|
381
|
+
|
253
382
|
end
|
254
383
|
|
255
384
|
# HELPER FUNCTIONS AND STRUCTURES
|
@@ -606,5 +735,191 @@ module UserStorage
|
|
606
735
|
::Thrift::Struct.generate_accessors self
|
607
736
|
end
|
608
737
|
|
738
|
+
class User_status_args
|
739
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
740
|
+
|
741
|
+
FIELDS = {
|
742
|
+
|
743
|
+
}
|
744
|
+
|
745
|
+
def struct_fields; FIELDS; end
|
746
|
+
|
747
|
+
def validate
|
748
|
+
end
|
749
|
+
|
750
|
+
::Thrift::Struct.generate_accessors self
|
751
|
+
end
|
752
|
+
|
753
|
+
class User_status_result
|
754
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
755
|
+
SUCCESS = 0
|
756
|
+
|
757
|
+
FIELDS = {
|
758
|
+
SUCCESS => {:type => ::Thrift::Types::STRUCT, :name => 'success', :class => UserStatus}
|
759
|
+
}
|
760
|
+
|
761
|
+
def struct_fields; FIELDS; end
|
762
|
+
|
763
|
+
def validate
|
764
|
+
end
|
765
|
+
|
766
|
+
::Thrift::Struct.generate_accessors self
|
767
|
+
end
|
768
|
+
|
769
|
+
class Set_user_status_args
|
770
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
771
|
+
STAT = 1
|
772
|
+
|
773
|
+
FIELDS = {
|
774
|
+
STAT => {:type => ::Thrift::Types::STRUCT, :name => 'stat', :class => UserStatus}
|
775
|
+
}
|
776
|
+
|
777
|
+
def struct_fields; FIELDS; end
|
778
|
+
|
779
|
+
def validate
|
780
|
+
end
|
781
|
+
|
782
|
+
::Thrift::Struct.generate_accessors self
|
783
|
+
end
|
784
|
+
|
785
|
+
class Set_user_status_result
|
786
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
787
|
+
|
788
|
+
FIELDS = {
|
789
|
+
|
790
|
+
}
|
791
|
+
|
792
|
+
def struct_fields; FIELDS; end
|
793
|
+
|
794
|
+
def validate
|
795
|
+
end
|
796
|
+
|
797
|
+
::Thrift::Struct.generate_accessors self
|
798
|
+
end
|
799
|
+
|
800
|
+
class User_relationship_args
|
801
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
802
|
+
|
803
|
+
FIELDS = {
|
804
|
+
|
805
|
+
}
|
806
|
+
|
807
|
+
def struct_fields; FIELDS; end
|
808
|
+
|
809
|
+
def validate
|
810
|
+
end
|
811
|
+
|
812
|
+
::Thrift::Struct.generate_accessors self
|
813
|
+
end
|
814
|
+
|
815
|
+
class User_relationship_result
|
816
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
817
|
+
SUCCESS = 0
|
818
|
+
|
819
|
+
FIELDS = {
|
820
|
+
SUCCESS => {:type => ::Thrift::Types::STRUCT, :name => 'success', :class => UserRelationship}
|
821
|
+
}
|
822
|
+
|
823
|
+
def struct_fields; FIELDS; end
|
824
|
+
|
825
|
+
def validate
|
826
|
+
end
|
827
|
+
|
828
|
+
::Thrift::Struct.generate_accessors self
|
829
|
+
end
|
830
|
+
|
831
|
+
class Set_user_relationship_args
|
832
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
833
|
+
REL = 1
|
834
|
+
|
835
|
+
FIELDS = {
|
836
|
+
REL => {:type => ::Thrift::Types::STRUCT, :name => 'rel', :class => UserRelationship}
|
837
|
+
}
|
838
|
+
|
839
|
+
def struct_fields; FIELDS; end
|
840
|
+
|
841
|
+
def validate
|
842
|
+
end
|
843
|
+
|
844
|
+
::Thrift::Struct.generate_accessors self
|
845
|
+
end
|
846
|
+
|
847
|
+
class Set_user_relationship_result
|
848
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
849
|
+
|
850
|
+
FIELDS = {
|
851
|
+
|
852
|
+
}
|
853
|
+
|
854
|
+
def struct_fields; FIELDS; end
|
855
|
+
|
856
|
+
def validate
|
857
|
+
end
|
858
|
+
|
859
|
+
::Thrift::Struct.generate_accessors self
|
860
|
+
end
|
861
|
+
|
862
|
+
class User_friends_args
|
863
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
864
|
+
|
865
|
+
FIELDS = {
|
866
|
+
|
867
|
+
}
|
868
|
+
|
869
|
+
def struct_fields; FIELDS; end
|
870
|
+
|
871
|
+
def validate
|
872
|
+
end
|
873
|
+
|
874
|
+
::Thrift::Struct.generate_accessors self
|
875
|
+
end
|
876
|
+
|
877
|
+
class User_friends_result
|
878
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
879
|
+
SUCCESS = 0
|
880
|
+
|
881
|
+
FIELDS = {
|
882
|
+
SUCCESS => {:type => ::Thrift::Types::STRUCT, :name => 'success', :class => UserFriends}
|
883
|
+
}
|
884
|
+
|
885
|
+
def struct_fields; FIELDS; end
|
886
|
+
|
887
|
+
def validate
|
888
|
+
end
|
889
|
+
|
890
|
+
::Thrift::Struct.generate_accessors self
|
891
|
+
end
|
892
|
+
|
893
|
+
class Set_user_friends_args
|
894
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
895
|
+
FR = 1
|
896
|
+
|
897
|
+
FIELDS = {
|
898
|
+
FR => {:type => ::Thrift::Types::STRUCT, :name => 'fr', :class => UserFriends}
|
899
|
+
}
|
900
|
+
|
901
|
+
def struct_fields; FIELDS; end
|
902
|
+
|
903
|
+
def validate
|
904
|
+
end
|
905
|
+
|
906
|
+
::Thrift::Struct.generate_accessors self
|
907
|
+
end
|
908
|
+
|
909
|
+
class Set_user_friends_result
|
910
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
911
|
+
|
912
|
+
FIELDS = {
|
913
|
+
|
914
|
+
}
|
915
|
+
|
916
|
+
def struct_fields; FIELDS; end
|
917
|
+
|
918
|
+
def validate
|
919
|
+
end
|
920
|
+
|
921
|
+
::Thrift::Struct.generate_accessors self
|
922
|
+
end
|
923
|
+
|
609
924
|
end
|
610
925
|
|
data/test/profile.thrift
CHANGED
@@ -4,6 +4,24 @@ struct UserProfile {
|
|
4
4
|
3: string blurb
|
5
5
|
}
|
6
6
|
|
7
|
+
enum MaritalStatus {
|
8
|
+
SINGLE
|
9
|
+
MARRIED
|
10
|
+
DIVORCED
|
11
|
+
UPSIDEDOWN
|
12
|
+
ITS_COMPLICATED
|
13
|
+
}
|
14
|
+
|
15
|
+
struct UserStatus {
|
16
|
+
1: UserProfile profile,
|
17
|
+
2: bool active
|
18
|
+
}
|
19
|
+
|
20
|
+
struct UserRelationship {
|
21
|
+
1: i32 user,
|
22
|
+
2: MaritalStatus status
|
23
|
+
}
|
24
|
+
|
7
25
|
enum Status {
|
8
26
|
ON
|
9
27
|
OFF
|
@@ -11,6 +29,11 @@ enum Status {
|
|
11
29
|
ALIVE
|
12
30
|
}
|
13
31
|
|
32
|
+
struct UserFriends {
|
33
|
+
1: i32 user,
|
34
|
+
2: list<i32> friends
|
35
|
+
}
|
36
|
+
|
14
37
|
exception RockTooHard {
|
15
38
|
1: i32 volume
|
16
39
|
}
|
@@ -26,6 +49,12 @@ service UserStorage {
|
|
26
49
|
Status last_status(),
|
27
50
|
i32 volume_up() throws (1: RockTooHard exc),
|
28
51
|
oneway void make_bitcoins(),
|
29
|
-
i32 add(1: i32 a, 2: i32 b)
|
52
|
+
i32 add(1: i32 a, 2: i32 b),
|
53
|
+
UserStatus user_status(),
|
54
|
+
void set_user_status(1: UserStatus stat),
|
55
|
+
UserRelationship user_relationship(),
|
56
|
+
void set_user_relationship(1: UserRelationship rel)
|
57
|
+
UserFriends user_friends(),
|
58
|
+
void set_user_friends(1: UserFriends fr)
|
30
59
|
}
|
31
60
|
|
data/test/test_client.rb
CHANGED
@@ -35,9 +35,11 @@ class TestClient < Test::Unit::TestCase
|
|
35
35
|
@last_list = nil
|
36
36
|
@last_status = nil
|
37
37
|
@n = n
|
38
|
+
@user_status = nil
|
39
|
+
@user_relationship = nil
|
38
40
|
end
|
39
41
|
|
40
|
-
attr_accessor :last_map, :last_list, :last_status
|
42
|
+
attr_accessor :last_map, :last_list, :last_status, :user_status
|
41
43
|
|
42
44
|
def store(obj)
|
43
45
|
@users[obj.uid] = obj
|
@@ -70,6 +72,20 @@ class TestClient < Test::Unit::TestCase
|
|
70
72
|
def add(a,b)
|
71
73
|
a + b
|
72
74
|
end
|
75
|
+
|
76
|
+
def set_user_status(s)
|
77
|
+
@user_status = s
|
78
|
+
end
|
79
|
+
|
80
|
+
attr_accessor :user_relationship
|
81
|
+
def set_user_relationship(rel)
|
82
|
+
@user_relationship = rel
|
83
|
+
end
|
84
|
+
|
85
|
+
attr_accessor :user_friends
|
86
|
+
def set_user_friends(fr)
|
87
|
+
@user_friends = fr
|
88
|
+
end
|
73
89
|
end
|
74
90
|
|
75
91
|
def test_store_and_retrieve
|
@@ -236,4 +252,118 @@ class TestClient < Test::Unit::TestCase
|
|
236
252
|
|
237
253
|
st.join
|
238
254
|
end
|
255
|
+
|
256
|
+
def test_read_struct_in_a_struct
|
257
|
+
st = Thread.new do
|
258
|
+
@server.process @server_p, @server_p
|
259
|
+
end
|
260
|
+
|
261
|
+
prof = UserProfile.new 'uid' => 0, 'name' => 'root', 'blurb' => 'god'
|
262
|
+
stat = UserStatus.new 'profile' => prof, 'active' => true
|
263
|
+
|
264
|
+
@handler.user_status = stat
|
265
|
+
|
266
|
+
status = @client.user_status
|
267
|
+
|
268
|
+
assert_equal true, status.active
|
269
|
+
|
270
|
+
prof = status.profile
|
271
|
+
|
272
|
+
assert_equal 0, prof.uid
|
273
|
+
assert_equal "root", prof.name
|
274
|
+
assert_equal "god", prof.blurb
|
275
|
+
|
276
|
+
st.join
|
277
|
+
end
|
278
|
+
|
279
|
+
def test_write_struct_in_a_struct
|
280
|
+
st = Thread.new do
|
281
|
+
@server.process @server_p, @server_p
|
282
|
+
end
|
283
|
+
|
284
|
+
prof = @n::UserProfile.new 'uid' => 0, 'name' => 'root', 'blurb' => 'god'
|
285
|
+
stat = @n::UserStatus.new 'profile' => prof, 'active' => true
|
286
|
+
|
287
|
+
@client.set_user_status stat
|
288
|
+
|
289
|
+
status = @handler.user_status
|
290
|
+
|
291
|
+
assert_equal true, status.active
|
292
|
+
|
293
|
+
prof = status.profile
|
294
|
+
|
295
|
+
assert_equal 0, prof.uid
|
296
|
+
assert_equal "root", prof.name
|
297
|
+
assert_equal "god", prof.blurb
|
298
|
+
|
299
|
+
st.join
|
300
|
+
end
|
301
|
+
|
302
|
+
def test_read_enum_in_struct
|
303
|
+
st = Thread.new do
|
304
|
+
@server.process @server_p, @server_p
|
305
|
+
end
|
306
|
+
|
307
|
+
stat = UserRelationship.new 'user' => 0, 'status' => 4
|
308
|
+
|
309
|
+
@handler.user_relationship = stat
|
310
|
+
|
311
|
+
rel = @client.user_relationship
|
312
|
+
|
313
|
+
assert_equal 0, rel.user
|
314
|
+
assert_equal :ITS_COMPLICATED, rel.status
|
315
|
+
|
316
|
+
st.join
|
317
|
+
end
|
318
|
+
|
319
|
+
def test_write_enum_in_struct
|
320
|
+
st = Thread.new do
|
321
|
+
@server.process @server_p, @server_p
|
322
|
+
end
|
323
|
+
|
324
|
+
stat = @n::UserRelationship.new 'user' => 0, 'status' => :ITS_COMPLICATED
|
325
|
+
|
326
|
+
@client.set_user_relationship stat
|
327
|
+
|
328
|
+
rel = @handler.user_relationship
|
329
|
+
|
330
|
+
assert_equal 0, rel.user
|
331
|
+
assert_equal 4, rel.status
|
332
|
+
|
333
|
+
st.join
|
334
|
+
end
|
335
|
+
|
336
|
+
def test_read_list_in_struct
|
337
|
+
st = Thread.new do
|
338
|
+
@server.process @server_p, @server_p
|
339
|
+
end
|
340
|
+
|
341
|
+
stat = UserFriends.new 'user' => 0, 'friends' => [4,8,47]
|
342
|
+
|
343
|
+
@handler.user_friends = stat
|
344
|
+
|
345
|
+
rel = @client.user_friends
|
346
|
+
|
347
|
+
assert_equal 0, rel.user
|
348
|
+
assert_equal [4,8,47], rel.friends
|
349
|
+
|
350
|
+
st.join
|
351
|
+
end
|
352
|
+
|
353
|
+
def test_write_list_in_struct
|
354
|
+
st = Thread.new do
|
355
|
+
@server.process @server_p, @server_p
|
356
|
+
end
|
357
|
+
|
358
|
+
stat = @n::UserFriends.new 'user' => 0, 'friends' => [4,8,47]
|
359
|
+
|
360
|
+
@client.set_user_friends stat
|
361
|
+
|
362
|
+
rel = @handler.user_friends
|
363
|
+
|
364
|
+
assert_equal 0, rel.user
|
365
|
+
assert_equal [4,8,47], rel.friends
|
366
|
+
|
367
|
+
st.join
|
368
|
+
end
|
239
369
|
end
|
data/test/test_parser.rb
CHANGED
@@ -138,6 +138,70 @@ service Foo {
|
|
138
138
|
assert_field o.functions[0].throws.first, 1, "i32", "code"
|
139
139
|
end
|
140
140
|
|
141
|
+
def test_include
|
142
|
+
o = parse <<-EOM
|
143
|
+
include "test/blah.thrift"
|
144
|
+
|
145
|
+
EOM
|
146
|
+
|
147
|
+
assert_equal "test/blah.thrift", o.first.path
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_include_expanded
|
151
|
+
o = parse <<-EOM
|
152
|
+
include "test/blah.thrift"
|
153
|
+
|
154
|
+
EOM
|
155
|
+
|
156
|
+
o = Stark::Parser.expand o
|
157
|
+
|
158
|
+
assert_equal "Blah", o.first.name
|
159
|
+
assert_equal ["FOO", "BAR", "BAZ"], o.first.values
|
160
|
+
end
|
161
|
+
|
162
|
+
def test_include_to_include
|
163
|
+
o = parse <<-EOM
|
164
|
+
include "test/include_blah.thrift"
|
165
|
+
|
166
|
+
EOM
|
167
|
+
|
168
|
+
o = Stark::Parser.expand o
|
169
|
+
|
170
|
+
assert_equal "Blah", o.first.name
|
171
|
+
assert_equal ["FOO", "BAR", "BAZ"], o.first.values
|
172
|
+
end
|
173
|
+
|
174
|
+
def test_ast
|
175
|
+
parser = Stark::Parser.new <<-EOM
|
176
|
+
include "test/include_blah.thrift"
|
177
|
+
EOM
|
178
|
+
|
179
|
+
o = parser.ast
|
180
|
+
|
181
|
+
assert_equal "Blah", o.first.name
|
182
|
+
assert_equal ["FOO", "BAR", "BAZ"], o.first.values
|
183
|
+
end
|
184
|
+
|
185
|
+
def test_s_ast
|
186
|
+
o = Stark::Parser.ast <<-EOM
|
187
|
+
include "test/include_blah.thrift"
|
188
|
+
EOM
|
189
|
+
|
190
|
+
assert_equal "Blah", o.first.name
|
191
|
+
assert_equal ["FOO", "BAR", "BAZ"], o.first.values
|
192
|
+
end
|
193
|
+
|
194
|
+
def test_namespace
|
195
|
+
o = parse <<-EOM
|
196
|
+
namespace rb Blah
|
197
|
+
EOM
|
198
|
+
|
199
|
+
ns = o.first
|
200
|
+
|
201
|
+
assert_equal "rb", ns.lang
|
202
|
+
assert_equal "Blah", ns.namespace
|
203
|
+
end
|
204
|
+
|
141
205
|
def test_spec
|
142
206
|
data = File.read "test/ThriftSpec.thrift"
|
143
207
|
|
data/test/test_ruby.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'stark'
|
3
|
+
require 'stark/ruby'
|
4
|
+
|
5
|
+
class TestRuby < Test::Unit::TestCase
|
6
|
+
def test_namespace
|
7
|
+
ast = Stark::Parser.ast <<-EOM
|
8
|
+
namespace rb Blah
|
9
|
+
enum Status {
|
10
|
+
DEAD
|
11
|
+
ALIVE
|
12
|
+
}
|
13
|
+
EOM
|
14
|
+
|
15
|
+
stream = StringIO.new
|
16
|
+
ruby = Stark::Ruby.new stream
|
17
|
+
|
18
|
+
ruby.run ast
|
19
|
+
|
20
|
+
ns = Module.new
|
21
|
+
|
22
|
+
ns.module_eval stream.string
|
23
|
+
|
24
|
+
assert ns::Blah
|
25
|
+
assert ns::Blah::Enum_Status
|
26
|
+
end
|
27
|
+
end
|