diff --git a/src/lua/zencode_data.lua b/src/lua/zencode_data.lua index 0f34ced12..bd5a30fab 100644 --- a/src/lua/zencode_data.lua +++ b/src/lua/zencode_data.lua @@ -355,12 +355,13 @@ end return data elseif dt == 'zenroom.big' then zencode_assert(fun ~= to_number_f and fun ~= O.to_mnemonic, "Encoding not valid for integers") - if fun == O.to_string then fun = BIG.to_decimal end - if fun ~= BIG.to_decimal then + local correct_fun = fun + if correct_fun == O.to_string then correct_fun = BIG.to_decimal end + if correct_fun ~= BIG.to_decimal then zencode_assert(BIG.zenpositive(data), "Negative integers can not be encoded") data = data:octet() end - return fun(data) + return correct_fun(data) elseif dt == 'zenroom.float' or dt == 'zenroom.time' then return to_number_f(data) elseif iszen(dt) then diff --git a/src/lua/zencode_then.lua b/src/lua/zencode_then.lua index ca4ee62f5..af545ff5a 100644 --- a/src/lua/zencode_then.lua +++ b/src/lua/zencode_then.lua @@ -69,7 +69,6 @@ local function then_outcast(val, key, enc) error("Then outcast called on empty variable", 2) end local fun - local codec if enc then fun = get_encoding_function(enc) if ZEN.schemas[enc] then @@ -88,7 +87,7 @@ local function then_outcast(val, key, enc) else fun = default_export_f end - return deepmap(fun,val) + return deepmap(fun, val) end local function then_insert(dest, val, key) @@ -338,4 +337,3 @@ Then("print object named by ''", function(name) OUT[real_name] = then_outcast( val, real_name ) end end) - diff --git a/test/zencode/array.bats b/test/zencode/array.bats index 05b00f073..d53cb3f1e 100755 --- a/test/zencode/array.bats +++ b/test/zencode/array.bats @@ -11,7 +11,7 @@ and I rename the 'array' to 'bonnetjes' Then print the 'bonnetjes' EOF save_output arr.json - + } @test "When I create the size of" { @@ -331,7 +331,7 @@ Given I have a 'string array' named 'haystack' and I have a 'number' named 'quorum' and I have a 'string' named 'needle' When I verify the 'needle' is found in 'haystack' at least 'quorum' times -Then Print the string 'Success' +Then Print the string 'Success' EOF save_output "needle_in_haystack.json" assert_output '{"output":["Success"]}' @@ -1020,3 +1020,27 @@ EOF save_output 'copy_from_schema_array.json' assert_output '{"copy":{"address":"0x2B8070975AF995Ef7eb949AE28ee7706B9039504","signature":"0xed8f36c71989f8660e8f5d4adbfd8f1c0288cca90d3a5330b7bf735d71ab52fe7ba0a7827dc4ba707431f1c10babd389f658f8e208b89390a9be3c097579a2ff1b"}}' } + +@test "print array with integers in it" { + cat << EOF | save_asset print_array_with_int.data.json +{ + "integer": "5", + "string": "a", + "another_string": "b" +} +EOF + cat << EOF | zexe print_array_with_int.zen print_array_with_int.data.json +Given I have a 'integer' +Given I have a 'string' +Given I have a 'string' named 'another_string' + +When I create the 'string array' named 'res' +When I move 'string' in 'res' +When I move 'integer' in 'res' +When I move 'another_string' in 'res' + +Then print the 'res' +EOF + save_output print_array_with_int.out.json + assert_output '{"res":["a","5","b"]}' +}