ruote 2.1.11 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (217) hide show
  1. data/CHANGELOG.txt +60 -0
  2. data/CREDITS.txt +22 -4
  3. data/LICENSE.txt +1 -1
  4. data/README.rdoc +6 -7
  5. data/Rakefile +58 -59
  6. data/TODO.txt +137 -65
  7. data/couch_url.txt +1 -0
  8. data/jruby_issue.txt +32 -0
  9. data/lib/ruote.rb +1 -1
  10. data/lib/ruote/context.rb +12 -10
  11. data/lib/ruote/engine.rb +280 -145
  12. data/lib/ruote/engine/process_error.rb +5 -5
  13. data/lib/ruote/engine/process_status.rb +47 -28
  14. data/lib/ruote/exp/command.rb +7 -10
  15. data/lib/ruote/exp/commanded.rb +2 -2
  16. data/lib/ruote/exp/condition.rb +130 -43
  17. data/lib/ruote/exp/fe_add_branches.rb +2 -2
  18. data/lib/ruote/exp/fe_apply.rb +1 -1
  19. data/lib/ruote/exp/fe_cancel_process.rb +3 -3
  20. data/lib/ruote/exp/fe_command.rb +3 -3
  21. data/lib/ruote/exp/fe_concurrence.rb +4 -4
  22. data/lib/ruote/exp/fe_concurrent_iterator.rb +17 -5
  23. data/lib/ruote/exp/fe_cron.rb +3 -3
  24. data/lib/ruote/exp/fe_cursor.rb +5 -5
  25. data/lib/ruote/exp/fe_define.rb +3 -3
  26. data/lib/ruote/exp/fe_echo.rb +3 -3
  27. data/lib/ruote/exp/fe_equals.rb +2 -2
  28. data/lib/ruote/exp/fe_error.rb +2 -2
  29. data/lib/ruote/exp/fe_filter.rb +519 -0
  30. data/lib/ruote/exp/fe_forget.rb +9 -2
  31. data/lib/ruote/exp/fe_given.rb +154 -0
  32. data/lib/ruote/exp/fe_if.rb +16 -13
  33. data/lib/ruote/exp/fe_inc.rb +3 -3
  34. data/lib/ruote/exp/fe_iterator.rb +4 -4
  35. data/lib/ruote/exp/fe_let.rb +75 -0
  36. data/lib/ruote/exp/fe_listen.rb +68 -12
  37. data/lib/ruote/exp/fe_lose.rb +110 -0
  38. data/lib/ruote/exp/fe_noop.rb +1 -1
  39. data/lib/ruote/exp/{fe_when.rb → fe_once.rb} +25 -21
  40. data/lib/ruote/exp/fe_participant.rb +14 -17
  41. data/lib/ruote/exp/fe_redo.rb +10 -6
  42. data/lib/ruote/exp/fe_ref.rb +1 -1
  43. data/lib/ruote/exp/fe_registerp.rb +112 -0
  44. data/lib/ruote/exp/fe_reserve.rb +3 -3
  45. data/lib/ruote/exp/fe_restore.rb +2 -2
  46. data/lib/ruote/exp/fe_save.rb +2 -2
  47. data/lib/ruote/exp/fe_sequence.rb +3 -4
  48. data/lib/ruote/exp/fe_set.rb +16 -7
  49. data/lib/ruote/exp/fe_subprocess.rb +23 -1
  50. data/lib/ruote/exp/fe_that.rb +92 -0
  51. data/lib/ruote/exp/fe_undo.rb +3 -3
  52. data/lib/ruote/exp/fe_unregisterp.rb +71 -0
  53. data/lib/ruote/exp/fe_wait.rb +2 -2
  54. data/lib/ruote/exp/flowexpression.rb +153 -78
  55. data/lib/ruote/exp/iterator.rb +2 -2
  56. data/lib/ruote/exp/merge.rb +2 -2
  57. data/lib/ruote/exp/ro_attributes.rb +14 -12
  58. data/lib/ruote/exp/ro_filters.rb +136 -0
  59. data/lib/ruote/exp/ro_persist.rb +51 -35
  60. data/lib/ruote/exp/ro_variables.rb +18 -27
  61. data/lib/ruote/fei.rb +73 -33
  62. data/lib/ruote/id/mnemo_wfid_generator.rb +1 -1
  63. data/lib/ruote/id/wfid_generator.rb +11 -4
  64. data/lib/ruote/log/default_history.rb +122 -0
  65. data/lib/ruote/log/pretty.rb +36 -8
  66. data/lib/ruote/log/storage_history.rb +37 -5
  67. data/lib/ruote/log/test_logger.rb +26 -24
  68. data/lib/ruote/log/wait_logger.rb +5 -3
  69. data/lib/ruote/part/block_participant.rb +22 -11
  70. data/lib/ruote/part/engine_participant.rb +6 -7
  71. data/lib/ruote/part/local_participant.rb +6 -12
  72. data/lib/ruote/part/no_op_participant.rb +4 -4
  73. data/lib/ruote/part/null_participant.rb +4 -4
  74. data/lib/ruote/part/smtp_participant.rb +4 -4
  75. data/lib/ruote/part/storage_participant.rb +40 -20
  76. data/lib/ruote/part/template.rb +4 -4
  77. data/lib/ruote/participant.rb +0 -1
  78. data/lib/ruote/{parser.rb → reader.rb} +30 -25
  79. data/lib/ruote/{parser → reader}/ruby_dsl.rb +28 -11
  80. data/lib/ruote/{parser → reader}/xml.rb +6 -5
  81. data/lib/ruote/receiver/base.rb +35 -13
  82. data/lib/ruote/storage/base.rb +20 -18
  83. data/lib/ruote/storage/composite_storage.rb +10 -10
  84. data/lib/ruote/storage/fs_storage.rb +17 -10
  85. data/lib/ruote/storage/hash_storage.rb +29 -18
  86. data/lib/ruote/svc/dispatch_pool.rb +41 -14
  87. data/lib/ruote/svc/dollar_sub.rb +50 -17
  88. data/lib/ruote/svc/error_handler.rb +19 -11
  89. data/lib/ruote/svc/expression_map.rb +4 -4
  90. data/lib/ruote/svc/participant_list.rb +105 -100
  91. data/lib/ruote/svc/tracker.rb +58 -18
  92. data/lib/ruote/svc/treechecker.rb +51 -24
  93. data/lib/ruote/tree_dot.rb +4 -4
  94. data/lib/ruote/util/filter.rb +440 -0
  95. data/lib/ruote/util/hashdot.rb +4 -4
  96. data/lib/ruote/util/look.rb +2 -6
  97. data/lib/ruote/util/lookup.rb +9 -7
  98. data/lib/ruote/util/misc.rb +40 -8
  99. data/lib/ruote/util/ometa.rb +1 -1
  100. data/lib/ruote/util/serializer.rb +4 -4
  101. data/lib/ruote/util/subprocess.rb +29 -9
  102. data/lib/ruote/util/time.rb +4 -4
  103. data/lib/ruote/util/tree.rb +3 -3
  104. data/lib/ruote/version.rb +2 -2
  105. data/lib/ruote/worker.rb +55 -32
  106. data/lib/ruote/workitem.rb +64 -11
  107. data/ruote.gemspec +31 -302
  108. data/test/bm/launch_bench.rb +37 -0
  109. data/test/functional/base.rb +60 -18
  110. data/test/functional/concurrent_base.rb +2 -2
  111. data/test/functional/ct_0_concurrence.rb +1 -1
  112. data/test/functional/ct_1_iterator.rb +1 -1
  113. data/test/functional/ct_2_cancel.rb +1 -1
  114. data/test/functional/eft_0_process_definition.rb +2 -2
  115. data/test/functional/eft_10_cancel_process.rb +1 -1
  116. data/test/functional/eft_11_wait.rb +19 -11
  117. data/test/functional/eft_12_listen.rb +79 -13
  118. data/test/functional/eft_13_iterator.rb +13 -10
  119. data/test/functional/eft_14_cursor.rb +98 -9
  120. data/test/functional/eft_15_loop.rb +6 -4
  121. data/test/functional/eft_16_if.rb +12 -0
  122. data/test/functional/eft_18_concurrent_iterator.rb +31 -32
  123. data/test/functional/eft_19_reserve.rb +4 -4
  124. data/test/functional/eft_1_echo.rb +9 -0
  125. data/test/functional/eft_20_save.rb +4 -4
  126. data/test/functional/{eft_28_when.rb → eft_28_once.rb} +33 -7
  127. data/test/functional/eft_30_ref.rb +17 -2
  128. data/test/functional/eft_31_registerp.rb +130 -0
  129. data/test/functional/eft_32_lose.rb +93 -0
  130. data/test/functional/eft_33_let.rb +31 -0
  131. data/test/functional/eft_34_given.rb +123 -0
  132. data/test/functional/eft_35_filter.rb +269 -0
  133. data/test/functional/eft_3_participant.rb +4 -6
  134. data/test/functional/eft_4_set.rb +16 -2
  135. data/test/functional/eft_5_subprocess.rb +2 -4
  136. data/test/functional/eft_6_concurrence.rb +29 -29
  137. data/test/functional/eft_8_undo.rb +39 -3
  138. data/test/functional/eft_9_redo.rb +94 -2
  139. data/test/functional/ft_10_dollar.rb +81 -2
  140. data/test/functional/ft_11_recursion.rb +13 -17
  141. data/test/functional/ft_12_launchitem.rb +9 -5
  142. data/test/functional/ft_13_variables.rb +7 -9
  143. data/test/functional/ft_14_re_apply.rb +6 -9
  144. data/test/functional/ft_15_timeout.rb +18 -18
  145. data/test/functional/ft_16_participant_params.rb +1 -3
  146. data/test/functional/ft_17_conditional.rb +25 -2
  147. data/test/functional/ft_18_kill.rb +65 -12
  148. data/test/functional/ft_1_process_status.rb +147 -71
  149. data/test/functional/ft_20_storage_participant.rb +0 -1
  150. data/test/functional/ft_21_forget.rb +82 -1
  151. data/test/functional/{ft_24_block_participants.rb → ft_24_block_participant.rb} +42 -11
  152. data/test/functional/ft_25_receiver.rb +47 -17
  153. data/test/functional/{ft_26_participant_timeout.rb → ft_26_participant_rtimeout.rb} +56 -19
  154. data/test/functional/ft_29_part_template.rb +6 -5
  155. data/test/functional/ft_2_errors.rb +21 -37
  156. data/test/functional/ft_30_smtp_participant.rb +1 -1
  157. data/test/functional/ft_31_part_blocking.rb +8 -6
  158. data/test/functional/ft_34_cursor_rewind.rb +13 -10
  159. data/test/functional/ft_35_add_service.rb +1 -1
  160. data/test/functional/ft_36_storage_history.rb +24 -1
  161. data/test/functional/ft_37_default_history.rb +109 -0
  162. data/test/functional/ft_38_participant_more.rb +10 -10
  163. data/test/functional/ft_39_wait_for.rb +12 -9
  164. data/test/functional/ft_3_participant_registration.rb +111 -32
  165. data/test/functional/ft_40_wait_logger.rb +2 -1
  166. data/test/functional/ft_41_participants.rb +30 -4
  167. data/test/functional/ft_43_participant_on_reply.rb +6 -23
  168. data/test/functional/ft_45_participant_accept.rb +4 -4
  169. data/test/functional/ft_46_launch_single.rb +36 -2
  170. data/test/functional/ft_47_wfid_generator.rb +54 -0
  171. data/test/functional/ft_48_lose.rb +112 -0
  172. data/test/functional/ft_49_engine_on_error.rb +201 -0
  173. data/test/functional/ft_4_cancel.rb +66 -6
  174. data/test/functional/ft_50_engine_config.rb +22 -0
  175. data/test/functional/ft_51_misc.rb +67 -0
  176. data/test/functional/ft_52_case.rb +134 -0
  177. data/test/functional/ft_53_engine_on_terminate.rb +95 -0
  178. data/test/functional/ft_54_patterns.rb +104 -0
  179. data/test/functional/{ft_37_engine_participant.rb → ft_55_engine_participant.rb} +4 -5
  180. data/test/functional/ft_56_filter_attribute.rb +259 -0
  181. data/test/functional/ft_5_on_error.rb +77 -30
  182. data/test/functional/ft_6_on_cancel.rb +66 -11
  183. data/test/functional/ft_7_tags.rb +94 -5
  184. data/test/functional/ft_8_participant_consumption.rb +36 -5
  185. data/test/functional/ft_9_subprocesses.rb +10 -10
  186. data/test/functional/rt_1_listen.rb +3 -3
  187. data/test/functional/{rt_3_when.rb → rt_3_once.rb} +4 -4
  188. data/test/functional/storage_helper.rb +15 -13
  189. data/test/functional/test.rb +1 -3
  190. data/test/test_helper.rb +0 -8
  191. data/test/unit/storage.rb +154 -10
  192. data/test/unit/{ut_0_ruby_parser.rb → ut_0_ruby_reader.rb} +61 -11
  193. data/test/unit/ut_11_lookup.rb +7 -0
  194. data/test/unit/ut_13_serializer.rb +1 -1
  195. data/test/unit/ut_15_util.rb +23 -0
  196. data/test/unit/{ut_16_parser.rb → ut_16_reader.rb} +11 -13
  197. data/test/unit/ut_1_fei.rb +57 -10
  198. data/test/unit/ut_20_composite_storage.rb +25 -11
  199. data/test/unit/ut_21_participant_list.rb +47 -0
  200. data/test/unit/ut_22_filter.rb +903 -0
  201. data/test/unit/ut_3_wait_logger.rb +2 -6
  202. data/test/unit/ut_6_condition.rb +164 -17
  203. data/test/unit/ut_7_workitem.rb +28 -0
  204. data/test/unit/ut_8_tree_to_dot.rb +1 -1
  205. data/test/unit/{ut_9_xml_parser.rb → ut_9_xml_reader.rb} +5 -5
  206. metadata +108 -84
  207. data/.gitignore +0 -4
  208. data/examples/barley.rb +0 -391
  209. data/examples/flickr_report.rb +0 -107
  210. data/examples/pong.rb +0 -37
  211. data/examples/ruote_quickstart.rb +0 -43
  212. data/examples/web_first_page.rb +0 -68
  213. data/lib/ruote/part/hash_participant.rb +0 -91
  214. data/test/README.rdoc +0 -15
  215. data/test/functional/crunner.sh +0 -19
  216. data/test/pdef.xml +0 -7
  217. data/test/unit/ut_2_wfidgen.rb +0 -21
@@ -13,10 +13,10 @@ def locate_storage_impl (arg)
13
13
 
14
14
  pers = arg[2..-1]
15
15
 
16
- path = File.expand_path(
17
- File.join(File.dirname(__FILE__), %w[ .. .. .. ], "ruote-#{pers}"))
16
+ path = Dir[File.expand_path(
17
+ File.join(File.dirname(__FILE__), %w[ .. .. .. ], "ruote-#{pers}*"))].first
18
18
 
19
- (File.exist?(path) && File.directory?(path)) ? [ pers, path ] : nil
19
+ File.directory?(path) ? [ pers, path ] : nil
20
20
  end
21
21
 
22
22
  #
@@ -37,7 +37,7 @@ else uses the in-memory Ruote::Engine (fastest, but no persistence at all)
37
37
  exit 0
38
38
  end
39
39
 
40
- ps = ARGV.select { |a| a.match(/^--/) }
40
+ ps = ARGV.select { |a| a.match(/^--[a-z]/) }
41
41
  ps.delete('--split')
42
42
 
43
43
  persistent = opts.delete(:persistent)
@@ -56,10 +56,7 @@ else uses the in-memory Ruote::Engine (fastest, but no persistence at all)
56
56
  elsif not ps.empty?
57
57
 
58
58
  pers = nil
59
- ps.each do |a|
60
- pers = locate_storage_impl(a)
61
- break if pers
62
- end
59
+ ps.find { |a| pers = locate_storage_impl(a) }
63
60
 
64
61
  raise "no persistence found (#{ps.inspect})" unless pers
65
62
 
@@ -67,14 +64,19 @@ else uses the in-memory Ruote::Engine (fastest, but no persistence at all)
67
64
  $:.unshift(File.join(path, 'lib'))
68
65
 
69
66
  begin
70
- load File.join(path, %w[ test functional_connection.rb ])
67
+ load 'test/functional_connection.rb'
71
68
  rescue LoadError => le
72
69
  begin
73
- load File.join(path, %w[ test integration_connection.rb ])
70
+ load File.join(path, %w[ test functional_connection.rb ])
74
71
  rescue LoadError => lee
75
- p le
76
- p lee
77
- raise lee
72
+ begin
73
+ load File.join(path, %w[ test integration_connection.rb ])
74
+ rescue LoadError => leee
75
+ p le
76
+ p lee
77
+ p leee
78
+ raise leee
79
+ end
78
80
  end
79
81
  end
80
82
 
@@ -9,11 +9,9 @@ def l (t)
9
9
 
10
10
  if ARGV.include?('--split')
11
11
 
12
- _v = ARGV.include?('-v') ? ' -v' : ' '
13
-
14
12
  puts
15
13
  puts "=== #{t} :"
16
- puts `ruby#{_v} #{t} #{ARGV.join(' ')}`
14
+ puts `ruby -I. #{t} #{ARGV.join(' ')}`
17
15
 
18
16
  es = $?.exitstatus
19
17
  es = es.nil? ? 66 : es.to_s.to_i
data/test/test_helper.rb CHANGED
@@ -19,11 +19,3 @@ def require_json
19
19
  end
20
20
  end
21
21
 
22
- def require_patron
23
- begin
24
- require 'patron'
25
- rescue LoadError => le
26
- # stick with net/http
27
- end
28
- end
29
-
data/test/unit/storage.rb CHANGED
@@ -8,10 +8,13 @@
8
8
  require File.join(File.dirname(__FILE__), %w[ .. test_helper.rb ])
9
9
 
10
10
  require_json
11
- #require_patron
12
11
 
13
12
  require File.join(File.dirname(__FILE__), %w[ .. functional storage_helper.rb ])
14
13
 
14
+ require 'ruote/fei'
15
+ require 'ruote/participant'
16
+
17
+
15
18
  #
16
19
  # note : using the 'errors' type, but this test is about generic storage, not
17
20
  # about errors per se.
@@ -25,16 +28,25 @@ class UtStorage < Test::Unit::TestCase
25
28
 
26
29
  #@s.add_type('errors')
27
30
 
31
+ @s.purge_type!('errors')
32
+ @s.purge_type!('expressions')
33
+ @s.purge_type!('msgs')
34
+ @s.purge_type!('workitems')
35
+
28
36
  @s.put(
29
37
  '_id' => 'toto',
30
38
  'type' => 'errors',
31
39
  'message' => 'testing')
32
40
  end
41
+
33
42
  def teardown
34
43
 
35
- @s.get_many('errors').each do |d|
36
- @s.delete(d)
37
- end
44
+ @s.purge_type!('errors')
45
+ @s.purge_type!('expressions')
46
+ @s.purge_type!('msgs')
47
+ @s.purge_type!('workitems')
48
+
49
+ @s.shutdown
38
50
  end
39
51
 
40
52
  def test_get_configuration
@@ -214,12 +226,7 @@ class UtStorage < Test::Unit::TestCase
214
226
 
215
227
  def test_get_many_options
216
228
 
217
- 30.times do |i|
218
- @s.put(
219
- '_id' => sprintf("yy!%0.2d", i),
220
- 'type' => 'errors',
221
- 'msg' => "whatever #{i}")
222
- end
229
+ load_30_errors
223
230
 
224
231
  # limit
225
232
 
@@ -255,5 +262,142 @@ class UtStorage < Test::Unit::TestCase
255
262
  'errors', nil, :skip => 0, :limit => 3, :descending => true
256
263
  ).collect { |d| d['_id'] })
257
264
  end
265
+
266
+ def test_dump
267
+
268
+ load_30_errors
269
+
270
+ assert @s.dump('errors').length > 0
271
+ end
272
+
273
+ def test_ids_and_errors
274
+
275
+ load_30_errors
276
+
277
+ assert_equal 31, @s.ids('errors').length
278
+ end
279
+
280
+ def test_ids_are_sorted
281
+
282
+ load_30_errors
283
+
284
+ assert_equal @s.ids('errors').sort, @s.ids('errors')
285
+ end
286
+
287
+ def test_reserve
288
+
289
+ taoe = Thread.abort_on_exception
290
+ Thread.abort_on_exception = true
291
+
292
+ reserved = []
293
+ threads = []
294
+
295
+ threads << Thread.new do
296
+ i = 0
297
+ loop do
298
+ @s.put_msg('launch', 'tree' => i)
299
+ i = i + 1
300
+ end
301
+ end
302
+
303
+ 2.times do
304
+
305
+ threads << Thread.new do
306
+ loop do
307
+ msgs = @s.get_msgs
308
+ msgs[0, 100].each do |msg|
309
+ next if msg['tree'].nil?
310
+ next unless @s.reserve(msg)
311
+ if reserved.include?(msg['tree'])
312
+ puts "=" * 80
313
+ p [ :dbl, :r, msg['_rev'], :t, msg['tree'] ]
314
+ end
315
+ reserved << msg['tree']
316
+ sleep(rand * 0.01)
317
+ end
318
+ end
319
+ end
320
+ end
321
+
322
+ sleep 7
323
+
324
+ threads.each { |t| t.terminate }
325
+
326
+ Thread.abort_on_exception = taoe
327
+
328
+ assert_equal false, reserved.empty?
329
+ assert_equal reserved.size, reserved.uniq.size
330
+ end
331
+
332
+ def test_by_field
333
+
334
+ return unless @s.respond_to?(:by_field)
335
+
336
+ load_workitems
337
+
338
+ assert_equal 3, @s.by_field('workitems', 'place', 'kyouto').size
339
+ assert_equal 1, @s.by_field('workitems', 'place', 'sendai').size
340
+ assert_equal Hash, @s.by_field('workitems', 'place', 'sendai').first.class
341
+ end
342
+
343
+ def test_by_participant
344
+
345
+ return unless @s.respond_to?(:by_participant)
346
+
347
+ load_workitems
348
+
349
+ assert_equal 2, @s.by_participant('workitems', 'fujiwara', {}).size
350
+ assert_equal 1, @s.by_participant('workitems', 'shingen', {}).size
351
+ assert_equal Hash, @s.by_participant('workitems', 'shingen', {}).first.class
352
+ end
353
+
354
+ def test_query_workitems
355
+
356
+ return unless @s.respond_to?(:query_workitems)
357
+
358
+ load_workitems
359
+
360
+ assert_equal 3, @s.query_workitems('place' => 'kyouto').size
361
+ assert_equal 1, @s.query_workitems('place' => 'kyouto', 'at' => 'kamo').size
362
+
363
+ assert_equal(
364
+ Ruote::Workitem, @s.query_workitems('place' => 'kyouto').first.class)
365
+ end
366
+
367
+ protected
368
+
369
+ def load_30_errors
370
+
371
+ 30.times do |i|
372
+ @s.put(
373
+ '_id' => sprintf("yy!%0.2d", i),
374
+ 'type' => 'errors',
375
+ 'msg' => "whatever #{i}")
376
+ end
377
+ end
378
+
379
+ def put_workitem(wfid, participant_name, fields)
380
+
381
+ @s.put(
382
+ 'type' => 'workitems',
383
+ '_id' => "wi!0_0!12ff!#{wfid}",
384
+ 'participant_name' => participant_name,
385
+ 'wfid' => wfid,
386
+ 'fields' => fields)
387
+ end
388
+
389
+ def load_workitems
390
+
391
+ put_workitem(
392
+ '20110218-nadanada', 'fujiwara', 'place' => 'kyouto')
393
+ put_workitem(
394
+ '20110218-nedenada', 'fujiwara', 'place' => 'kyouto', 'at' => 'kamo')
395
+ put_workitem(
396
+ '20110218-nadanodo', 'taira', 'place' => 'kyouto')
397
+ put_workitem(
398
+ '20110218-nodonada', 'date', 'place' => 'sendai')
399
+ put_workitem(
400
+ '20110218-nadanudu', 'shingen', 'place' => 'nagoya')
401
+ end
258
402
  end
259
403
 
@@ -7,11 +7,10 @@
7
7
 
8
8
  require File.join(File.dirname(__FILE__), '..', 'test_helper.rb')
9
9
 
10
- require 'ruote/parser'
11
- #require 'ruote/parser/ruby_dsl'
10
+ require 'ruote/reader'
12
11
 
13
12
 
14
- class UtRubyParserTest < Test::Unit::TestCase
13
+ class UtRubyReaderTest < Test::Unit::TestCase
15
14
 
16
15
  #def test_whatever
17
16
  # tree = Ruote.define do
@@ -125,33 +124,84 @@ class UtRubyParserTest < Test::Unit::TestCase
125
124
  Ruote.to_tree { sequence { alpha; bravo } })
126
125
  end
127
126
 
128
- def test_raise
127
+ def test_treechecker
129
128
 
130
129
  #assert_raise Nada do
131
- Ruote::Parser.parse %{ Ruote.define { alpha } }
130
+ Ruote::Reader.read %{ Ruote.define { alpha } }
132
131
  #end
133
132
 
134
133
  assert_raise ArgumentError do
135
- Ruote::Parser.parse %{ Ruote.define { abort } }
134
+ Ruote::Reader.read %{ Ruote.define { abort } }
136
135
  end
137
136
  assert_raise ArgumentError do
138
- Ruote::Parser.parse %{ Ruote.define { exit } }
137
+ Ruote::Reader.read %{ Ruote.define { exit } }
139
138
  end
140
139
  assert_raise ArgumentError do
141
- Ruote::Parser.parse %{ Ruote.define { exit! } }
140
+ Ruote::Reader.read %{ Ruote.define { exit! } }
142
141
  end
143
142
 
144
143
  assert_raise ArgumentError do
145
- Ruote::Parser.parse %{ Ruote.define { x = Kernel } }
144
+ Ruote::Reader.read %{ Ruote.define { x = Kernel } }
146
145
  end
147
146
 
148
147
  assert_raise ArgumentError do
149
- Ruote::Parser.parse %{ Ruote.define { module Nada; end } }
148
+ Ruote::Reader.read %{ Ruote.define { module Nada; end } }
150
149
  end
151
150
 
152
151
  assert_raise ArgumentError do
153
- Ruote::Parser.parse %{ Ruote.define { File.read('stuff') } }
152
+ Ruote::Reader.read %{ Ruote.define { File.read('stuff') } }
154
153
  end
154
+
155
+ assert_raise ArgumentError do
156
+ Ruote::Reader.read %{ Ruote.define { at_exit { } } }
157
+ end
158
+
159
+ assert_raise ArgumentError do
160
+ Ruote::Reader.read %{ Ruote.define { def nada; end } }
161
+ end
162
+ end
163
+
164
+ def test_attribute_text_regexp
165
+
166
+ tree = Ruote.define do
167
+ given "${target}" do
168
+ of "/^employee-/" do
169
+ end
170
+ of /^customer-/ do
171
+ end
172
+ end
173
+ end
174
+
175
+ assert_equal(
176
+ ["define", {}, [
177
+ ["given", {"${target}"=>nil}, [
178
+ ["of", {"/^employee-/"=>nil}, []],
179
+ ["of", {"/^customer-/"=>nil}, []]]]]],
180
+ tree)
181
+ end
182
+
183
+ def test_attribute_value_regexp
184
+
185
+ tree = Ruote.define do
186
+ subprocess 'alpha', :match => /^nada$/
187
+ end
188
+
189
+ assert_equal(
190
+ ["define", {}, [["subprocess", {"alpha"=>nil, "match"=>"/^nada$/"}, []]]],
191
+ tree)
192
+ end
193
+
194
+ def test_attribute_value_regexp_deep
195
+
196
+ tree = Ruote.define do
197
+ alpha :filter => { :in => [ { :field => /^private_/ } ] }
198
+ end
199
+
200
+ assert_equal(
201
+ [ "define", {}, [
202
+ [ "alpha", { "filter" => { "in" => [ { "field" => '/^private_/' } ] } }, [] ]
203
+ ] ],
204
+ tree)
155
205
  end
156
206
  end
157
207
 
@@ -18,6 +18,13 @@ class LookupTest < Test::Unit::TestCase
18
18
  assert_equal('B', Ruote.lookup({ 'h' => %w[ A B C ] }, 'h.1'))
19
19
  end
20
20
 
21
+ def test_lookup_dot
22
+
23
+ h = { 'a' => 'b' }
24
+
25
+ assert_equal h, Ruote.lookup(h, '.')
26
+ end
27
+
21
28
  def test_container_lookup
22
29
 
23
30
  assert_equal(
@@ -14,7 +14,7 @@ class UtSerializerTest < Test::Unit::TestCase
14
14
 
15
15
  class Vehicle
16
16
  attr_accessor :type
17
- def initialize (t)
17
+ def initialize(t)
18
18
  @type = t
19
19
  end
20
20
  end
@@ -30,5 +30,28 @@ class UtMiscTest < Test::Unit::TestCase
30
30
  assert_equal 0.0, Ruote.narrow_to_number('0.0')
31
31
  assert_equal 1.0, Ruote.narrow_to_number('1.0')
32
32
  end
33
+
34
+ def test_regex_or_s
35
+
36
+ assert_equal /bravo/, Ruote.regex_or_s('/bravo/')
37
+ assert_equal 'nada', Ruote.regex_or_s('nada')
38
+ assert_equal nil, Ruote.regex_or_s(nil)
39
+ end
40
+
41
+ class Klass
42
+ def initialize(s)
43
+ @s = s
44
+ end
45
+ end
46
+
47
+ def test_fulldup
48
+
49
+ a = Klass.new('hello')
50
+ b = Ruote.fulldup(a)
51
+
52
+ assert_equal Klass, b.class
53
+ assert_not_equal a.object_id, b.object_id
54
+ assert_equal 'hello', b.instance_variable_get(:@s)
55
+ end
33
56
  end
34
57
 
@@ -7,10 +7,10 @@
7
7
 
8
8
  require File.join(File.dirname(__FILE__), '..', 'test_helper.rb')
9
9
 
10
- require 'ruote/parser'
10
+ require 'ruote/reader'
11
11
 
12
12
 
13
- class PdefParserTest < Test::Unit::TestCase
13
+ class PdefReaderTest < Test::Unit::TestCase
14
14
 
15
15
  DEF0 = %{
16
16
  Ruote.define :name => 'nada' do
@@ -22,7 +22,7 @@ class PdefParserTest < Test::Unit::TestCase
22
22
  }
23
23
 
24
24
 
25
- TREE1 = Ruote::Parser.parse(%{
25
+ TREE1 = Ruote::Reader.read(%{
26
26
  Ruote.define :name => 'nada' do
27
27
  sequence do
28
28
  alpha
@@ -33,7 +33,7 @@ class PdefParserTest < Test::Unit::TestCase
33
33
 
34
34
  def test_from_string
35
35
 
36
- tree = Ruote::Parser.parse(DEF0)
36
+ tree = Ruote::Reader.read(DEF0)
37
37
 
38
38
  assert_equal(
39
39
  ["define", {"name"=>"nada"}, [
@@ -48,7 +48,7 @@ class PdefParserTest < Test::Unit::TestCase
48
48
 
49
49
  File.open(fn, 'w') { |f| f.write(DEF0) }
50
50
 
51
- tree = Ruote::Parser.parse(fn)
51
+ tree = Ruote::Reader.read(fn)
52
52
 
53
53
  assert_equal(
54
54
  ["define", {"name"=>"nada"}, [
@@ -61,7 +61,6 @@ class PdefParserTest < Test::Unit::TestCase
61
61
 
62
62
  def test_to_xml
63
63
 
64
- #puts Ruote::Parser.to_xml(TREE1, :indent => 2)
65
64
  assert_equal(
66
65
  %{
67
66
  <?xml version="1.0" encoding="UTF-8"?>
@@ -72,7 +71,7 @@ class PdefParserTest < Test::Unit::TestCase
72
71
  </sequence>
73
72
  </define>
74
73
  }.strip,
75
- Ruote::Parser.to_xml(TREE1, :indent => 2).strip)
74
+ Ruote::Reader.to_xml(TREE1, :indent => 2).strip)
76
75
  end
77
76
 
78
77
  def test_if_to_xml
@@ -92,12 +91,11 @@ class PdefParserTest < Test::Unit::TestCase
92
91
  </if>
93
92
  </define>
94
93
  }.strip,
95
- Ruote::Parser.to_xml(tree, :indent => 2).strip)
94
+ Ruote::Reader.to_xml(tree, :indent => 2).strip)
96
95
  end
97
96
 
98
97
  def test_to_ruby
99
98
 
100
- #puts Ruote::Parser.to_ruby(TREE1)
101
99
  assert_equal(
102
100
  %{
103
101
  Ruote.process_definition :name => "nada" do
@@ -107,14 +105,14 @@ Ruote.process_definition :name => "nada" do
107
105
  end
108
106
  end
109
107
  }.strip,
110
- Ruote::Parser.to_ruby(TREE1).strip)
108
+ Ruote::Reader.to_ruby(TREE1).strip)
111
109
  end
112
110
 
113
111
  def test_to_json
114
112
 
115
113
  require 'json'
116
114
 
117
- assert_equal TREE1.to_json, Ruote::Parser.to_json(TREE1)
115
+ assert_equal TREE1.to_json, Ruote::Reader.to_json(TREE1)
118
116
  end
119
117
 
120
118
  DEF1 = %{
@@ -135,7 +133,7 @@ end
135
133
 
136
134
  assert_equal(
137
135
  ["define", {}, [["sequence", {}, [["alpha", {}, []], ["set", {"field"=>"f", "value"=>"v"}, []], ["bravo", {}, []]]]]],
138
- Ruote::Parser.parse(fn))
136
+ Ruote::Reader.read(fn))
139
137
 
140
138
  FileUtils.rm(fn)
141
139
  end
@@ -145,7 +143,7 @@ end
145
143
  #
146
144
  def test_ruby_blank_slate
147
145
 
148
- t = Ruote::Parser.parse(%{
146
+ t = Ruote::Reader.read(%{
149
147
  Ruote.define do
150
148
  freeze
151
149
  clone