Skip to content

Commit

Permalink
fix(zencode): deprecate length word in favour of size
Browse files Browse the repository at this point in the history
update also tests
  • Loading branch information
matteo-cristino authored and jaromil committed Oct 17, 2023
1 parent 3b10b98 commit 039c951
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 32 deletions.
52 changes: 44 additions & 8 deletions src/lua/zencode_verify.lua
Original file line number Diff line number Diff line change
Expand Up @@ -217,30 +217,66 @@ local function _check_compare_length(obj_name, num_name)
return obj_len, num
end

IfWhen("verify the length of '' is less than ''", function(obj_name, num_name)
IfWhen("verify the size of '' is less than ''", function(obj_name, num_name)
local l, r = _check_compare_length(obj_name, num_name)
zencode_assert(l < r,
"Comparison fail: length of "..obj_name.." is not less than "..num_name)
"Comparison fail: size of "..obj_name.." is not less than "..num_name)
end)

IfWhen("verify the length of '' is less or equal than ''", function(obj_name, num_name)
IfWhen(deprecated("verify the length of '' is less than ''",
"verify the size of '' is less than ''",
function(obj_name, num_name)
local l, r = _check_compare_length(obj_name, num_name)
zencode_assert(l < r,
"Comparison fail: length of "..obj_name.." is not less than "..num_name)
end)
)

IfWhen("verify the size of '' is less or equal than ''", function(obj_name, num_name)
local l, r = _check_compare_length(obj_name, num_name)
zencode_assert(l <= r,
"Comparison fail: length of "..obj_name.." is not less or equal than "..num_name)
"Comparison fail: size of "..obj_name.." is not less or equal than "..num_name)
end)

IfWhen("verify the length of '' is more than ''", function(obj_name, num_name)
IfWhen(deprecated("verify the length of '' is less or equal than ''",
"verify the size of '' is less or equal than ''",
function(obj_name, num_name)
local l, r = _check_compare_length(obj_name, num_name)
zencode_assert(l <= r,
"Comparison fail: length of "..obj_name.." is not less or equal than "..num_name)
end)
)

IfWhen("verify the size of '' is more than ''", function(obj_name, num_name)
local l, r = _check_compare_length(obj_name, num_name)
zencode_assert(r < l,
"Comparison fail: length of "..obj_name.." is not more than "..num_name)
"Comparison fail: size of "..obj_name.." is not more than "..num_name)
end)

IfWhen("verify the length of '' is more or equal than ''", function(obj_name, num_name)
IfWhen(deprecated("verify the length of '' is more than ''",
"verify the size of '' is more than ''",
function(obj_name, num_name)
local l, r = _check_compare_length(obj_name, num_name)
zencode_assert(r < l,
"Comparison fail: length of "..obj_name.." is not more than "..num_name)
end)
)

IfWhen("verify the size of '' is more or equal than ''", function(obj_name, num_name)
local l, r = _check_compare_length(obj_name, num_name)
zencode_assert(r <= l,
"Comparison fail: length of "..obj_name.." is not more or equal than "..num_name)
"Comparison fail: size of "..obj_name.." is not more or equal than "..num_name)
end)

IfWhen(deprecated("verify the length of '' is more or equal than ''",
"verify the size of '' is more or equal than ''",
function(obj_name, num_name)
local l, r = _check_compare_length(obj_name, num_name)
zencode_assert(r <= l,
"Comparison fail: length of "..obj_name.." is not more or equal than "..num_name)
end)
)

-- TODO: substitute with RFC2047 compliant code (take from jaromail)
local function validemail(str)
if str == nil then
Expand Down
48 changes: 24 additions & 24 deletions test/zencode/branching.bats
Original file line number Diff line number Diff line change
Expand Up @@ -561,37 +561,37 @@ Given I have a 'float' named '5_float'
Given I have a 'float' named '6_float'
# string with integer
When I verify the length of 'my_string' is more than '2_int'
When I verify the length of 'my_string' is more or equal than '5_int'
When I verify the length of 'my_string' is less or equal than '5_int'
When I verify the length of 'my_string' is less than '6_int'
When I verify the size of 'my_string' is more than '2_int'
When I verify the size of 'my_string' is more or equal than '5_int'
When I verify the size of 'my_string' is less or equal than '5_int'
When I verify the size of 'my_string' is less than '6_int'
# string with float
When I verify the length of 'my_string' is more than '2_float'
When I verify the length of 'my_string' is more or equal than '5_float'
When I verify the length of 'my_string' is less or equal than '5_float'
When I verify the length of 'my_string' is less than '6_float'
When I verify the size of 'my_string' is more than '2_float'
When I verify the size of 'my_string' is more or equal than '5_float'
When I verify the size of 'my_string' is less or equal than '5_float'
When I verify the size of 'my_string' is less than '6_float'
# array with integer
When I verify the length of 'my_array' is more than '3_int'
When I verify the length of 'my_array' is more or equal than '5_int'
When I verify the length of 'my_array' is less or equal than '5_int'
When I verify the length of 'my_array' is less than '6_int'
When I verify the size of 'my_array' is more than '3_int'
When I verify the size of 'my_array' is more or equal than '5_int'
When I verify the size of 'my_array' is less or equal than '5_int'
When I verify the size of 'my_array' is less than '6_int'
# array with float
When I verify the length of 'my_array' is more than '3_float'
When I verify the length of 'my_array' is more or equal than '5_float'
When I verify the length of 'my_array' is less or equal than '5_float'
When I verify the length of 'my_array' is less than '6_float'
When I verify the size of 'my_array' is more than '3_float'
When I verify the size of 'my_array' is more or equal than '5_float'
When I verify the size of 'my_array' is less or equal than '5_float'
When I verify the size of 'my_array' is less than '6_float'
# array with integer
When I verify the length of 'my_dict' is more than '2_int'
When I verify the length of 'my_dict' is more or equal than '3_int'
When I verify the length of 'my_dict' is less or equal than '3_int'
When I verify the length of 'my_dict' is less than '5_int'
When I verify the size of 'my_dict' is more than '2_int'
When I verify the size of 'my_dict' is more or equal than '3_int'
When I verify the size of 'my_dict' is less or equal than '3_int'
When I verify the size of 'my_dict' is less than '5_int'
# array with float
When I verify the length of 'my_dict' is more than '2_float'
When I verify the length of 'my_dict' is more or equal than '3_float'
When I verify the length of 'my_dict' is less or equal than '3_float'
When I verify the length of 'my_dict' is less than '5_float'
When I verify the size of 'my_dict' is more than '2_float'
When I verify the size of 'my_dict' is more or equal than '3_float'
When I verify the size of 'my_dict' is less or equal than '3_float'
When I verify the size of 'my_dict' is less than '5_float'
Then print the string 'all comparison succedded'
EOF
Expand Down

0 comments on commit 039c951

Please sign in to comment.