mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
test: add hexdump utilitiy function
This commit is contained in:
parent
85bc6630c0
commit
8540b5e4ad
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user