From 82d8fd8c31b425e1b4f240ce83696da9a46c584b Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Fri, 25 Oct 2024 16:57:49 -0700 Subject: [PATCH] path.new ==> path.norm & fixed errors --- .tests/path/{new.test.lua => norm.test.lua} | 6 +++--- worldeditadditions_core/utils/path.lua | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) rename .tests/path/{new.test.lua => norm.test.lua} (71%) diff --git a/.tests/path/new.test.lua b/.tests/path/norm.test.lua similarity index 71% rename from .tests/path/new.test.lua rename to .tests/path/norm.test.lua index da84029..0dab7e9 100644 --- a/.tests/path/new.test.lua +++ b/.tests/path/norm.test.lua @@ -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) diff --git a/worldeditadditions_core/utils/path.lua b/worldeditadditions_core/utils/path.lua index 407f7c8..21f1b76 100644 --- a/worldeditadditions_core/utils/path.lua +++ b/worldeditadditions_core/utils/path.lua @@ -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 = {}