Skip to content

Commit

Permalink
feat: ✨ enable and in foreach
Browse files Browse the repository at this point in the history
  • Loading branch information
albertolerda authored and jaromil committed Mar 9, 2023
1 parent f427459 commit c30588c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ test_dir = meson.source_root() + '/../test/'
bats_bin = find_program(test_dir+'bats/bin/bats')
tests = [ 'array', 'dictionary', 'branching', 'float',
'generic_ecdh', 'generic_eddsa', 'generic_schnorr', 'generic_dilithium',
'zkp', 'credential', 'bitcoin', 'ecdh', 'foreach' ]
'zkp', 'credential', 'bitcoin', 'ecdh', 'foreach', 'and' ]
foreach test_suite : tests
test('zencode_'+test_suite.underscorify(),
bats_bin,
Expand Down
5 changes: 5 additions & 0 deletions src/lua/zencode.lua
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,11 @@ local function new_state_machine()
{name = 'enter_and', from = 'whenif', to = 'whenif'},
{name = 'enter_and', from = 'thenif', to = 'thenif'},
{name = 'enter_and', from = 'if', to = 'if'},
{name = 'enter_and', from = 'foreach', to = 'foreach'},
{name = 'enter_and', from = 'ifforeach', to = 'ifforeach'},
{name = 'enter_and', from = 'foreachif', to = 'foreachif'},
{name = 'enter_and', from = 'whenforeach', to = 'whenforeach'},
{name = 'enter_and', from = 'whenifforeach', to = 'whenifforeach'},

},
-- graph TD
Expand Down
33 changes: 33 additions & 0 deletions test/zencode/and.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
load ../bats_setup
load ../bats_zencode
SUBDOC=and

@test "And inside foreach" {
cat <<EOF | save_asset andforeach.data
{
"to_be_hashed": [
"a",
"b",
"john",
12345,
"[email protected]",
"(!)"
]
}
EOF
cat <<EOF | zexe andforeach.zen andforeach.data
Given I have a 'string array' named 'to_be_hashed'
When I create the 'base64 array' named 'array of hashes'
Foreach 'element_to_be_hashed' in 'to_be_hashed'
When I create the hash of 'element_to_be_hashed'
and I move 'hash' in 'array of hashes'
EndForeach
Then print 'array of hashes'
EOF
save_output "andforeach.json"
assert_output '{"array_of_hashes":["ypeBEsobvcr6wjGzmiPcTaeG7/gUfE5yuYB3ha/uSLs=","PiPoFgA5WUoziU9lZOGxNIu9egCI1CxKy3PurtWcAJ0=","ltljLzY1ZMwwMlIUCc8iqFLyAy7sCZ7VlnwNAAzsYHo=","WZRHGrsBESr8wYFZ9sx0tPURuZgG2lmzyvWpwXPKz8U=","1wnzcOUrV7TrdfBOKzQixNQaBRSMrY+Bd22UoEj7cK8=","CVh+6HMogNKneQFF+XSaFy0nJ80KKduyZRbky5xVGKg="]}'
}

0 comments on commit c30588c

Please sign in to comment.