Generate next filenames correctly
This commit is contained in:
parent
a876678dea
commit
1400dae3df
|
@ -68,12 +68,20 @@ describe("nextfile", function()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
insulate("prevfile.prevfile returns a non-numeric filename", function()
|
insulate("prevfile.prevfile returns a non-numeric filename", function()
|
||||||
prevfile.prevfile = function() return "/testdir/421b.txt" end
|
it("should return the result of replacing the last character with the next letter of the alphabet", function()
|
||||||
|
prevfile.prevfile = function() return "/testdir/421b.txt" end
|
||||||
|
|
||||||
--it("should return the result of replacing the last character with the next letter of the alphabet", function()
|
local file = nextfile.nextfile("/testdir")
|
||||||
--local file = nextfile.nextfile("/testdir")
|
|
||||||
|
|
||||||
--assert.are.equal("/testdir/421c.txt", file)
|
assert.are.equal("/testdir/421c.txt", file)
|
||||||
--end)
|
end)
|
||||||
|
|
||||||
|
it("should return the result of replacing z with za when z is the last letter of the filename", function()
|
||||||
|
prevfile.prevfile = function() return "/testdir/421z.txt" end
|
||||||
|
|
||||||
|
local file = nextfile.nextfile("/testdir")
|
||||||
|
|
||||||
|
assert.are.equal("/testdir/421za.txt", file)
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
|
@ -23,7 +23,8 @@ function nextfile.nextfile(directory)
|
||||||
|
|
||||||
if tonumber(name) == nil then
|
if tonumber(name) == nil then
|
||||||
local lastletter = name:sub(#name)
|
local lastletter = name:sub(#name)
|
||||||
return dir .. name:gsub() .. ext
|
local nextletter = nextfile.nextletter(lastletter)
|
||||||
|
return dir .. name:gsub(lastletter .. "$", nextletter) .. ext
|
||||||
end
|
end
|
||||||
|
|
||||||
return dir .. name + 1 .. ext
|
return dir .. name + 1 .. ext
|
||||||
|
|
Loading…
Reference in New Issue