Skip to content

Commit

Permalink
path.new ==> path.norm & fixed errors
Browse files Browse the repository at this point in the history
  • Loading branch information
VorTechnix committed Oct 25, 2024
1 parent 3c88ae9 commit 82d8fd8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions .tests/path/new.test.lua → .tests/path/norm.test.lua
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
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),
result
)
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)
Expand Down
12 changes: 6 additions & 6 deletions worldeditadditions_core/utils/path.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
Expand All @@ -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 = {}
Expand Down

0 comments on commit 82d8fd8

Please sign in to comment.