aboutsummaryrefslogtreecommitdiff
path: root/test/testutil.lua
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2024-09-09 04:00:35 -0700
committerGitHub <noreply@github.com>2024-09-09 04:00:35 -0700
commitf0334c2c711ab6d2cd123f7506497c1311b0b926 (patch)
tree96a58f869698b9e80662f0793fdcc72a32293d64 /test/testutil.lua
parent8a2aec99748229ad9d1e12c1cbc0768d063e8eed (diff)
parentc8e3618e0e68485c92bba3790a06d472d9b62697 (diff)
downloadrneovim-f0334c2c711ab6d2cd123f7506497c1311b0b926.tar.gz
rneovim-f0334c2c711ab6d2cd123f7506497c1311b0b926.tar.bz2
rneovim-f0334c2c711ab6d2cd123f7506497c1311b0b926.zip
Merge #30312 from justinmk/testslashes
Diffstat (limited to 'test/testutil.lua')
-rw-r--r--test/testutil.lua23
1 files changed, 23 insertions, 0 deletions
diff --git a/test/testutil.lua b/test/testutil.lua
index 19e297c503..02f343891d 100644
--- a/test/testutil.lua
+++ b/test/testutil.lua
@@ -42,6 +42,29 @@ function M.isdir(path)
return stat.type == 'directory'
end
+--- (Only on Windows) Replaces yucky "\\" slashes with delicious "/" slashes in a string, or all
+--- string values in a table (recursively).
+---
+--- @param obj string|table
+--- @return any
+function M.fix_slashes(obj)
+ if not M.is_os('win') then
+ return obj
+ end
+ if type(obj) == 'string' then
+ local ret = obj:gsub('\\', '/')
+ return ret
+ elseif type(obj) == 'table' then
+ --- @cast obj table<any,any>
+ local ret = {} --- @type table<any,any>
+ for k, v in pairs(obj) do
+ ret[k] = M.fix_slashes(v)
+ end
+ return ret
+ end
+ assert(false, 'expected string or table of strings, got ' .. type(obj))
+end
+
--- @param ... string|string[]
--- @return string
function M.argss_to_cmd(...)