test/functional/eft_27_inc.rb in ruote-2.2.0 vs test/functional/eft_27_inc.rb in ruote-2.3.0

- old
+ new

@@ -3,11 +3,11 @@ # testing ruote # # Sat Sep 19 12:56:16 JST 2009 # -require File.join(File.dirname(__FILE__), 'base') +require File.expand_path('../base', __FILE__) class EftIncTest < Test::Unit::TestCase include FunctionalBase @@ -26,12 +26,10 @@ echo '${v:x}|${f:y}' end end - #noisy - assert_trace '2|2', pdef end def test_inc_missing @@ -45,12 +43,10 @@ echo '${v:x}|${f:y}' end end - #noisy - assert_trace '2|2', pdef end def test_inc_delta @@ -58,21 +54,24 @@ sequence do inc 'v:x', :val => 2 inc 'f:y', :val => 3 inc 'v:z', :val => 1.0 + inc :var => 'x', :val => '4' inc :field => 'y', :val => 5 inc 'v:z', :val => '2.0' + inc 'v:x' => 2 + inc 'y' => 2 + inc 'v:z' => 0.5 + echo '${v:x}|${f:y}|${v:z}' end end - #noisy - - assert_trace '6|8|3.0', pdef + assert_trace '8|10|3.5', pdef end def test_inc_v_val pdef = Ruote.process_definition do @@ -84,18 +83,16 @@ echo '${v:x}' end end - #noisy - assert_trace '4', pdef end def test_inc_array - @engine.context['ruby_eval_allowed'] = true + @dashboard.context['ruby_eval_allowed'] = true pdef = Ruote.process_definition do sequence do set 'v:x' => %w[ alpha bravo ] @@ -104,19 +101,17 @@ echo '${r:fe.lv("x").join("\n")}' end end - #noisy - assert_trace %w[ alpha bravo charly ], pdef end def test_inc_array_head - #@engine.context['ruby_eval_allowed'] = true - @engine.configure('ruby_eval_allowed', true) + #@dashboard.context['ruby_eval_allowed'] = true + @dashboard.configure('ruby_eval_allowed', true) pdef = Ruote.process_definition do sequence do set 'v:x' => %w[ alpha bravo ] @@ -125,18 +120,16 @@ echo '${r:fe.lv("x").join("\n")}' end end - #noisy - assert_trace %w[ charly alpha bravo ], pdef end def test_inc_array_missing - @engine.context['ruby_eval_allowed'] = true + @dashboard.context['ruby_eval_allowed'] = true pdef = Ruote.process_definition do sequence do inc 'v:x', :val => 'charly' @@ -145,12 +138,10 @@ echo '${r:fe.lv("x").join(".")}' echo '${r:fe.lv("y").join(".")}' end end - #noisy - assert_trace %w[ charly charly ], pdef end def test_dec @@ -166,96 +157,80 @@ echo '${v:x}|${f:y}|${v:z}' end end - #noisy - assert_trace '3|3|-1', pdef end def test_dec_array - @engine.context['ruby_eval_allowed'] = true + @dashboard.context['ruby_eval_allowed'] = true - pdef = Ruote.process_definition do - sequence do + pdef = Ruote.define do - set 'v:x' => %w[ a b c ] - set 'v:y' => %w[ a b c ] + set 'v:x' => %w[ a b c ] + set 'v:y' => %w[ d e f ] - dec 'v:x' - dec 'v:y', :position => :head + dec 'v:x' + dec 'v:y', :position => :head - echo '${r:fe.lv("x").join(".")}' - echo '${r:fe.lv("y").join(".")}' - echo '${v:d}' - end + echo '${r:fe.lv("x").join(".")}' + echo '${r:fe.lv("y").join(".")}' + echo '${__result__}' end - #noisy - - assert_trace %w[ a.b b.c a ], pdef + assert_trace %w[ a.b e.f d ], pdef end - def test_dec_to + def test_dec_val - @engine.context['ruby_eval_allowed'] = true + @dashboard.context['ruby_eval_allowed'] = true - pdef = Ruote.process_definition do - sequence do + pdef = Ruote.define do - set 'v:x' => %w[ a b c ] + set 'v:x' => %w[ a b c ] - dec 'v:x', :to_var => 'y' + dec 'v:x', :val => 'b' - echo '${r:fe.lv("x").join(".")}' - echo '${v:y}' - end + echo '${r:fe.lv("x").join(".")}' + echo '${__result__}' end - #noisy - - assert_trace %w[ a.b c ], pdef + assert_trace %w[ a.c b ], pdef end - def test_dec_val + def test_dec_val_to_d - @engine.context['ruby_eval_allowed'] = true + @dashboard.context['ruby_eval_allowed'] = true - pdef = Ruote.process_definition do - sequence do + pdef = Ruote.define do - set 'v:x' => %w[ a b c ] + set 'v:x' => %w[ a b c ] - dec 'v:x', :val => 'b' + dec 'v:x', :val => 'b', :to_v => 'd' - echo '${r:fe.lv("x").join(".")}' - echo '${v:d}' - end + echo '${r:fe.lv("x").join(".")}' + echo '${v:d}' end - #noisy - assert_trace %w[ a.c b ], pdef end def test_cursor pdef = Ruote.process_definition do sequence do set 'v:x' => %w[ a b c d ] repeat do dec 'v:x', :pos => :head - _break :unless => '${v:d}' - echo '${v:d}' + echo '${__result__}' + _break :unless => '${__result__}' end end end - #noisy - assert_trace %w[ a b c d ], pdef end def test_bare_inc @@ -264,17 +239,86 @@ inc echo 'done.' end end - #noisy + wfid = @dashboard.launch(pdef) - wfid = @engine.launch(pdef) - wait_for(wfid) - ps = @engine.process(wfid) + ps = @dashboard.process(wfid) assert_equal 1, ps.errors.size + end + + def test_nested_inc + + pdef = Ruote.define do + + set :var => 'x', :value => 1 + + inc 'v:x' do + set '__result__' => 2 + end + + echo '${v:x}' + end + + wfid = @dashboard.launch(pdef) + r = @dashboard.wait_for(wfid) + + assert_equal 'terminated', r['action'] + assert_equal '3', @tracer.to_s + end + + def test_push + + pdef = Ruote.define do + push 'v:x' => 1 + push 'v:x' => 2 + end + + wfid = @dashboard.launch(pdef) + r = @dashboard.wait_for(wfid) + + assert_equal 'terminated', r['action'] + assert_equal [ 1, 2 ], r['variables']['x'] + end + + def test_pop + + pdef = Ruote.define do + pop 'v:x' + push 'v:x' => false + push 'v:x' => 1 + push 'v:x' => 2 + pop 'v:x' + end + + wfid = @dashboard.launch(pdef) + r = @dashboard.wait_for(wfid) + + assert_equal 'terminated', r['action'] + assert_equal [ false, 1 ], r['variables']['x'] + assert_equal 2, r['workitem']['fields']['__result__'] + end + + def test_pop_2 + + pdef = Ruote.define do + + set 'v:x' => 12 + push 'v:x' => 4 + pop 'v:x' + + pop 'v:y' + end + + wfid = @dashboard.launch(pdef) + r = @dashboard.wait_for(wfid) + + assert_equal 'terminated', r['action'] + assert_equal [ 12 ], r['variables']['x'] + assert_equal [], r['variables']['y'] end end