diff options
author | Björn Linse <bjorn.linse@gmail.com> | 2017-09-03 09:29:01 +0200 |
---|---|---|
committer | Björn Linse <bjorn.linse@gmail.com> | 2017-11-25 09:37:00 +0100 |
commit | 8540b5e4adcf5175b6f73261736a66fecae81f28 (patch) | |
tree | 7d30184ec86e9080b52599f3b173f69863f544ac /test/functional/helpers.lua | |
parent | 85bc6630c0a8259c713383c8787e65f92e24e600 (diff) | |
download | rneovim-8540b5e4adcf5175b6f73261736a66fecae81f28.tar.gz rneovim-8540b5e4adcf5175b6f73261736a66fecae81f28.tar.bz2 rneovim-8540b5e4adcf5175b6f73261736a66fecae81f28.zip |
test: add hexdump utilitiy function
Diffstat (limited to 'test/functional/helpers.lua')
-rw-r--r-- | test/functional/helpers.lua | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index 848f1ef477..2472062d1e 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -618,6 +618,33 @@ local function alter_slashes(obj) end end +local function hexdump(str) + local len = string.len( str ) + local dump = "" + local hex = "" + local asc = "" + + for i = 1, len do + if 1 == i % 8 then + dump = dump .. hex .. asc .. "\n" + hex = string.format( "%04x: ", i - 1 ) + asc = "" + end + + local ord = string.byte( str, i ) + hex = hex .. string.format( "%02x ", ord ) + if ord >= 32 and ord <= 126 then + asc = asc .. string.char( ord ) + else + asc = asc .. "." + end + end + + return dump .. hex + .. string.rep( " ", 8 - len % 8 ) .. asc + +end + local module = { prepend_argv = prepend_argv, clear = clear, @@ -687,6 +714,7 @@ local module = { get_pathsep = get_pathsep, missing_provider = missing_provider, alter_slashes = alter_slashes, + hexdump = hexdump, } return function(after_each) |