mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-12-22 19:45:02 +00:00
path.new ==> path.norm & fixed errors
This commit is contained in:
parent
3c88ae9e23
commit
82d8fd8c31
2 changed files with 9 additions and 9 deletions
|
@ -1,8 +1,8 @@
|
|||
local Path = require("worldeditadditions_core.utils.path")
|
||||
|
||||
describe("Path.new", function()
|
||||
describe("Path.norm", function()
|
||||
it("should correct bad formatting", function()
|
||||
local result, err = Path.new("C:\\Users\\me\\".."/Documents//code.lua")
|
||||
local result, err = Path.norm("C:\\Users\\me\\".."/Documents//code.lua")
|
||||
assert.is_nil(err)
|
||||
assert.are.same(
|
||||
table.concat({"C:","Users","me","Documents","code.lua"}, Path.sep),
|
||||
|
@ -10,7 +10,7 @@ describe("Path.new", function()
|
|||
)
|
||||
end)
|
||||
it("should return an error if not a string", function()
|
||||
local result, err = Path.new(123)
|
||||
local result, err = Path.norm(123)
|
||||
assert.is_false(result)
|
||||
assert.are.same("string", type(err))
|
||||
end)
|
|
@ -4,9 +4,9 @@ local path = {}
|
|||
|
||||
-- Helper functions
|
||||
local check = function( ... )
|
||||
for _, v in ipairs( ... ) do
|
||||
for _, v in ipairs( {...} ) do
|
||||
if type(v) ~= "string" then
|
||||
return false, v .. " is not a string."
|
||||
return false, tostring(v) .. " is not a string."
|
||||
end
|
||||
end
|
||||
return true
|
||||
|
@ -24,8 +24,8 @@ end
|
|||
-- @return string|false, string? The formatted path string or
|
||||
-- false and an error message.
|
||||
-- @example Basic usage
|
||||
-- local path = path.new("C:\\Users\\me\\".."/Documents//code.lua")
|
||||
path.new = function( str )
|
||||
-- local path = path.norm("C:\\Users\\me\\".."/Documents//code.lua")
|
||||
path.norm = function( str )
|
||||
local ok, err = check(str)
|
||||
if not ok then return false, err end
|
||||
return ({str:gsub("[/\\]+", path.sep)})[1]
|
||||
|
@ -39,9 +39,9 @@ end
|
|||
-- local path = file_path("C:\\Users", "me", "/Documents/code.lua")
|
||||
path.join = function( ... )
|
||||
local pathlets = { ... }
|
||||
local ok, err = check(pathlets)
|
||||
local ok, err = check( ... )
|
||||
if not ok then return false, err end
|
||||
return path.new(table.concat(pathlets, path.sep))
|
||||
return path.norm(table.concat(pathlets, path.sep))
|
||||
end
|
||||
|
||||
local Path = {}
|
||||
|
|
Loading…
Reference in a new issue