diff --git a/spec/nextfile_spec.lua b/spec/nextfile_spec.lua index 7b4e430..7a2542e 100644 --- a/spec/nextfile_spec.lua +++ b/spec/nextfile_spec.lua @@ -68,12 +68,20 @@ describe("nextfile", function() end) 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) - --end) + assert.are.equal("/testdir/421c.txt", file) + 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) diff --git a/src/nextfile.lua b/src/nextfile.lua index e9ada7f..da63c6c 100644 --- a/src/nextfile.lua +++ b/src/nextfile.lua @@ -23,7 +23,8 @@ function nextfile.nextfile(directory) if tonumber(name) == nil then local lastletter = name:sub(#name) - return dir .. name:gsub() .. ext + local nextletter = nextfile.nextletter(lastletter) + return dir .. name:gsub(lastletter .. "$", nextletter) .. ext end return dir .. name + 1 .. ext