test/functional/eft_13_iterator.rb in ruote-2.2.0 vs test/functional/eft_13_iterator.rb in ruote-2.3.0
- old
+ new
@@ -3,11 +3,11 @@
# testing ruote
#
# Mon Jun 29 09:35:48 JST 2009
#
-require File.join(File.dirname(__FILE__), 'base')
+require File.expand_path('../base', __FILE__)
require 'ruote/participant'
class EftIteratorTest < Test::Unit::TestCase
@@ -42,11 +42,11 @@
iterator :on_val => 'alice, bob, charly', :to_var => 'v' do
participant '${v:v}'
end
end
- @engine.register_participant '.*', TraceParticipant
+ @dashboard.register_participant '.*', TraceParticipant
#noisy
assert_trace(%w[ alice/0_0_0 bob/0_0_0 charly/0_0_0 ], pdef)
end
@@ -57,11 +57,11 @@
iterator :on => 'alice, bob, charly', :to_var => 'v' do
participant '${v:v}'
end
end
- @engine.register_participant '.*', TraceParticipant
+ @dashboard.register_participant '.*', TraceParticipant
assert_trace(%w[ alice/0_0_0 bob/0_0_0 charly/0_0_0 ], pdef)
end
def test_on_f
@@ -71,32 +71,69 @@
iterator :on_f => 'people', :to_var => 'v' do
participant '${v:v}'
end
end
- @engine.register_participant '.*', TraceParticipant
+ @dashboard.register_participant '.*', TraceParticipant
assert_trace(%w[ alice/0_1_0 bob/0_1_0 charly/0_1_0 ], pdef)
end
+ def test_on_nested_f
+
+ pdef = Ruote.process_definition :name => 'test' do
+ set 'f:data' => {}
+ set 'f:data.people' => %w[ alice bob charly ]
+ iterator :on_f => 'data.people', :to_var => 'v' do
+ participant '${v:v}'
+ end
+ end
+
+ @dashboard.register_participant '.*', TraceParticipant
+
+ assert_trace(%w[ alice/0_2_0 bob/0_2_0 charly/0_2_0 ], pdef)
+ end
+
def test_to_f
pdef = Ruote.process_definition :name => 'test' do
iterator :on_val => 'alice, bob, charly', :to_field => 'f' do
participant '${f:f}'
end
end
- @engine.register_participant '.*' do |workitem|
- @tracer << "#{workitem.fields['f']}/#{workitem.fei.expid}\n"
+ @dashboard.register_participant '.*' do |workitem|
+ tracer << "#{workitem.fields['f']}/#{workitem.fei.expid}\n"
end
#noisy
assert_trace(%w[ alice/0_0_0 bob/0_0_0 charly/0_0_0 ], pdef)
end
+ def test_to
+
+ pdef = Ruote.process_definition :name => 'test' do
+ iterator :on_val => 'a, b', :to => 'x' do
+ echo '${f:x}'
+ end
+ iterator :on_val => 'c, d', :to => 'f:y' do
+ echo '${f:y}'
+ end
+ iterator :on_val => 'e, f', :to => 'v:z' do
+ echo '${v:z}'
+ end
+ end
+
+ #@dashboard.noisy = true
+
+ wfid = @dashboard.launch(pdef)
+ @dashboard.wait_for(wfid)
+
+ assert_equal %w[ a b c d e f ], @tracer.to_a
+ end
+
PDEF0 = Ruote.process_definition :name => 'test' do
sequence do
iterator :on_val => 'alice, bob, charly', :to_var => 'v' do
participant '${v:v}'
end
@@ -104,13 +141,13 @@
end
end
def test_break
- @engine.register_participant '.*' do |workitem|
+ @dashboard.register_participant '.*' do |workitem|
- @tracer << "#{workitem.participant_name}\n"
+ tracer << "#{workitem.participant_name}\n"
if workitem.participant_name == 'bob'
workitem.fields['__command__'] = [ 'break', nil ]
end
end
@@ -122,16 +159,16 @@
def test_rewind
stash[:rewound] = false
- @engine.register_participant '.*' do |workitem|
+ @dashboard.register_participant '.*' do |workitem|
- @tracer << "#{workitem.participant_name}\n"
+ tracer << "#{workitem.participant_name}\n"
- if (not stash[:rewound]) and workitem.participant_name == 'bob'
- stash[:rewound] = true
+ if (not context.stash[:rewound]) and workitem.participant_name == 'bob'
+ context.stash[:rewound] = true
workitem.fields['__command__'] = [ 'rewind', nil ]
end
end
#noisy
@@ -139,13 +176,13 @@
assert_trace(%w[ alice bob alice bob charly done. ], PDEF0)
end
def test_skip
- @engine.register_participant '.*' do |workitem|
+ @dashboard.register_participant '.*' do |workitem|
- @tracer << "#{workitem.participant_name}\n"
+ tracer << "#{workitem.participant_name}\n"
if workitem.participant_name == 'alice'
workitem.fields['__command__'] = [ 'skip', 1 ]
end
end
@@ -155,13 +192,13 @@
assert_trace(%w[ alice charly done.], PDEF0)
end
def test_jump
- @engine.register_participant '.*' do |workitem|
+ @dashboard.register_participant '.*' do |workitem|
- @tracer << "#{workitem.participant_name}\n"
+ tracer << "#{workitem.participant_name}\n"
if workitem.participant_name == 'alice'
workitem.fields['__command__'] = [ 'jump', -1 ]
end
end
@@ -180,12 +217,12 @@
skip 1, :if => '${v:v} == alice'
end
end
end
- @engine.register_participant '.*' do |workitem|
- @tracer << "#{workitem.participant_name}/#{workitem.fei.expid}\n"
+ @dashboard.register_participant '.*' do |workitem|
+ tracer << "#{workitem.participant_name}/#{workitem.fei.expid}\n"
end
#noisy
assert_trace(%w[ alice/0_0_0_0 charly/0_0_0_0 ], pdef)
@@ -197,12 +234,12 @@
iterator :on_val => 'a, b, c', :to_var => 'v', :break_if => '${v:v} == b' do
participant '${v:v}'
end
end
- @engine.register_participant '.*' do |workitem|
- @tracer << "#{workitem.participant_name}/#{workitem.fei.expid}\n"
+ @dashboard.register_participant '.*' do |workitem|
+ tracer << "#{workitem.participant_name}/#{workitem.fei.expid}\n"
end
#noisy
assert_trace(%w[ a/0_0_0 b/0_0_0 ], pdef)
@@ -215,12 +252,12 @@
iterator :on_val => 'a, b, c', :to_var => 'v', :break_unless => '${v:v} == a' do
participant '${v:v}'
end
end
- @engine.register_participant '.*' do |workitem|
- @tracer << "#{workitem.participant_name}/#{workitem.fei.expid}\n"
+ @dashboard.register_participant '.*' do |workitem|
+ tracer << "#{workitem.participant_name}/#{workitem.fei.expid}\n"
end
#noisy
assert_trace(%w[ a/0_1_0 b/0_1_0 ], pdef)
@@ -232,13 +269,13 @@
iterator :on_val => { 'a' => 'A', 'b' => 'B' }, :to_f => 'f' do
p1
end
end
- @engine.register_participant :p1 do |wi|
- @tracer << wi.fields['f'].join(':')
- @tracer << "\n"
+ @dashboard.register_participant :p1 do |wi|
+ tracer << wi.fields['f'].join(':')
+ tracer << "\n"
end
#noisy
assert_trace %w[ a:A b:B ], pdef
@@ -250,17 +287,23 @@
iterator :on_val => 'alice, bob, charly' do
participant '${v:i}:${v:ii}'
end
end
- @engine.register_participant '.*' do |workitem|
- @tracer << "#{workitem.participant_name}/#{workitem.fei.expid}\n"
+ @dashboard.register_participant '.*' do |workitem|
+ tracer << "#{workitem.participant_name}/#{workitem.fei.expid}\n"
end
- #noisy
+ #@dashboard.noisy = true
- assert_trace(%w[ alice:0/0_0_0 bob:1/0_0_0 charly:2/0_0_0 ], pdef)
+ wfid = @dashboard.launch(pdef)
+ r = @dashboard.wait_for(wfid)
+
+ assert_equal %w[ alice:0/0_0_0 bob:1/0_0_0 charly:2/0_0_0 ], @tracer.to_a
+
+ assert_equal 'charly', r['variables']['i']
+ assert_equal 2, r['variables']['ii']
end
def test_nested_break
pdef = Ruote.process_definition :name => 'test' do
@@ -298,8 +341,31 @@
end
#noisy
assert_trace %w[ 1 2 ], pdef
+ end
+
+ def test_implicit_sequence
+
+ pdef = Ruote.process_definition :name => 'test' do
+ iterator :on_val => 'alice, bob, charly', :to_var => 'v' do
+ echo '0:${v:v}'
+ echo '1:${v:v}'
+ end
+ end
+
+ #@dashboard.noisy = true
+
+ wfid = @dashboard.launch(pdef)
+ r = @dashboard.wait_for(wfid)
+
+ assert_equal(
+ %w[
+ 0:alice 1:alice
+ 0:bob 1:bob
+ 0:charly 1:charly
+ ],
+ @tracer.to_a)
end
end