Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Zenroom
Zenroom
Commits
9ecd1c25
Commit
9ecd1c25
authored
May 09, 2022
by
matteo-cristino
Committed by
Jaromil
May 16, 2022
Browse files
found: empty octets are not found now
parent
4b572425
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/lua/zencode_when.lua
View file @
9ecd1c25
...
...
@@ -25,11 +25,38 @@
-- nop to terminate IF blocks
When
(
"done"
,
function
()
end
)
IfWhen
(
"'' is found"
,
function
(
n
)
ZEN
.
assert
(
ACK
[
n
]
~=
nil
,
"Cannot find object: "
..
n
)
local
function
_is_found
(
el
,
t
)
if
not
t
then
return
ACK
[
el
]
and
(
luatype
(
ACK
[
el
])
==
'table'
or
#
ACK
[
el
]
~=
0
)
else
ZEN
.
assert
(
ACK
[
t
],
"Array or dictionary not found in: "
..
t
)
if
ZEN
.
CODEC
[
t
].
zentype
==
'array'
then
local
o_el
=
O
.
from_string
(
el
)
for
_
,
v
in
pairs
(
ACK
[
t
])
do
if
v
==
o_el
then
return
true
end
end
elseif
ZEN
.
CODEC
[
t
].
zentype
==
'dictionary'
then
return
ACK
[
t
][
el
]
and
(
luatype
(
ACK
[
t
][
el
])
==
'table'
or
#
ACK
[
t
][
el
]
~=
0
)
else
ZEN
.
assert
(
false
,
"Invalid container type: "
..
t
..
" is "
..
ZEN
.
CODEC
[
t
].
zentype
)
end
end
return
false
end
IfWhen
(
"'' is found"
,
function
(
el
)
ZEN
.
assert
(
_is_found
(
el
),
"Cannot find object: "
..
el
)
end
)
IfWhen
(
"'' is not found"
,
function
(
el
)
ZEN
.
assert
(
not
_is_found
(
el
),
"Object should not be found: "
..
el
)
end
)
IfWhen
(
"'' is found in ''"
,
function
(
el
,
t
)
ZEN
.
assert
(
_is_found
(
el
,
t
),
"Cannot find object: "
..
el
..
" in "
..
t
)
end
)
IfWhen
(
"'' is not found"
,
function
(
n
)
ZEN
.
assert
(
ACK
[
n
]
==
nil
,
"Object
should not be found
:
"
..
n
)
IfWhen
(
"'' is not found
in ''
"
,
function
(
el
,
t
)
ZEN
.
assert
(
not
_is_found
(
el
,
t
),
"Object: "
..
el
..
"
should not be found
in
"
..
t
)
end
)
When
(
"append '' to ''"
,
function
(
src
,
dest
)
...
...
test/zencode_branching/run.sh
View file @
9ecd1c25
#!/usr/bin/env bash
# DEBUG=3
SUBDOC
=
branching
DEBUG
=
1
####################
# common script init
if
!
test
-r
../utils.sh
;
then
echo
"run executable from its own directory:
$0
"
;
exit
1
;
fi
.
../utils.sh
$*
is_cortexm
=
false
if
[[
"
$1
"
==
"cortexm"
]]
;
then
is_cortexm
=
true
fi
Z
=
"
`
detect_zenroom_path
`
`
detect_zenroom_conf
`
"
####################
set
-e
cat
<<
EOF
| save branching leftrightA.json
{ "number_lower": 10,
"number_higher": 50 }
...
...
@@ -79,3 +87,100 @@ endif
EOF
cat
<<
EOF
| save branching found.json
{
"str": "good",
"empty_arr": [],
"not_empty_dict": {
"empty_octet":""
},
"arr": ["hello",
"goodmorning",
"hi",
"goodevening"],
"dict": {
"hello": "world",
"nice": "world",
"big": "world"
}
}
EOF
cat
<<
EOF
| zexe found.zen -a found.json | jq .
Given I have a 'string dictionary' named 'dict'
Given I have a 'string array' named 'arr'
Given I have a 'string dictionary' named 'not_empty_dict'
Given I have a 'string array' named 'empty_arr'
Given I have a 'string' named 'str'
When I create the 'string array' named 'found output'
If 'str' is found
When I insert string '1.success' in 'found output'
EndIf
If 'empty_arr' is found
When I insert string '2.success' in 'found output'
EndIf
If 'hello' is not found
When I insert string '3.success' in 'found output'
EndIf
If 'hello' is found in 'arr'
When I insert string '4.success' in 'found output'
EndIf
If 'hello' is found in 'dict'
When I insert string '5.success' in 'found output'
EndIf
If 'good' is not found in 'arr'
When I insert string '6.success' in 'found output'
EndIf
If 'good' is not found in 'dict'
When I insert string '7.success' in 'found output'
EndIf
If 'empty octet' is not found in 'not_empty_dict'
When I insert string '8.success' in 'found output'
EndIf
If 'hello' is found
When I insert string '1.fail' in 'found output'
EndIf
If 'str' is not found
When I insert string '2.fail' in 'found output'
EndIf
If 'good' is found in 'arr'
When I insert string '3.fail' in 'found output'
EndIf
If 'good' is found in 'dict'
When I insert string '4.fail' in 'found output'
EndIf
If 'hello' is not found in 'arr'
When I insert string '5.fail' in 'found output'
EndIf
If 'hello' is not found in 'dict'
When I insert string '6.fail' in 'found output'
EndIf
If 'hello' is found in 'empty arr'
When I insert string '7.fail' in 'found output'
EndIf
If 'empty_arr' is not found
When I insert string '8.fail' in 'found output'
EndIf
Then print 'found output'
EOF
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment