Skip to content

Commit

Permalink
Add c-each specs for custom vars
Browse files Browse the repository at this point in the history
  • Loading branch information
jmettraux committed Jan 8, 2024
1 parent 2ed5f8f commit 35eaca4
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
17 changes: 16 additions & 1 deletion doc/patterns__control_flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,26 @@ sequence
examine_sample 'laboratory 1'
examine_sample 'laboratory 2'
examine_sample 'laboratory 3'
review_drilling _
drill_review _
```

The [concurrence](procedures/concurrence.md) expects one reply and then cancels the remaining branches.

Here is a varient using [c-each](procedures/c_each.md):

```python
sequence

set labs [ 'lab alpha', 'lab biometa', 'lab cruz' ]

# ...

extract_sample _
c-each labs expect: 1 remaining: 'cancel'
examine_sample lab: elt
drill_review _
```

[wp/explanation](http://www.workflowpatterns.com/patterns/control/advanced_branching/wcp29.php) | [wp/animation](http://www.workflowpatterns.com/patterns/control/advanced_branching/wcp29_animation.php) | [top](#top)

<!-- --------------------------------------------------------------------- -->
Expand Down
48 changes: 48 additions & 0 deletions spec/punit/c_each_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,20 @@
expect(r['payload']['ret']).to eq([ 10, 11 ])
end

it 'accepts custom keys (arrays) (2)' do

r = @unit.launch(
%q{
set l []
c-each [ 'lab a', 'lab b' ] v.lab
push l lab
},
wait: true)

expect(r).to have_terminated_as_point
expect(r['vars']['l']).to eq([ 'lab a', 'lab b' ])
end

it 'accepts custom keys (objects)' do

r = @unit.launch(
Expand Down Expand Up @@ -100,6 +114,40 @@

expect(r['vars']['l']).to eq([ 0 ])
end

it 'accepts expect: and remaining: (2)' do

r = @unit.launch(
%q{
set l []
set labs [ 'lab alpha', 'lab biometa', 'lab cruz' ]
#c-each labs v.lab expect: 2 remaining: 'cancel'
# push l lab
c-each labs expect: 2 remaining: 'cancel'
sleep for: "$(idx)s"
push l elt
},
wait: true)

expect(r['vars']['l']).to eq([ 'lab alpha', 'lab biometa' ])
end

it 'accepts expect: and remaining: (3)'
#
# r = @unit.launch(
# %q{
# set l []
# set labs [ 'lab arcturus', 'lab brizer', 'lab cruz' ]
#
# c-each labs v.lab expect: 2 remaining: 'cancel'
# sleep for: "$(idx)s"
# push l lab
# },
# wait: true)
#
# expect(r['vars']['l']).to eq([ 'lab arcturus', 'lab brizer' ])
# end
end
end

Expand Down

0 comments on commit 35eaca4

Please sign in to comment.