diff --git a/spec/nextfile_spec.lua b/spec/nextfile_spec.lua index a6005de..78a9a62 100644 --- a/spec/nextfile_spec.lua +++ b/spec/nextfile_spec.lua @@ -2,17 +2,19 @@ describe("splitfilename", function() local nextfile = require "nextfile" it("should return the filename and extension of an absolute filepath", function() - local name, ext = nextfile.splitfilename("/testdir/701.txt") + local dir, name, ext = nextfile.splitfilename("/testdir/701.txt") + assert.are.equal("/testdir/", dir) assert.are.equal("701", name) - assert.are.equal("txt", ext) + assert.are.equal(".txt", ext) end) it("should return the filename and extension of a relative filepath", function() - local name, ext = nextfile.splitfilename("../../foo/testdir/file.mp3") + local dir, name, ext = nextfile.splitfilename("../../foo/testdir/file.mp3") + assert.are.equal("../../foo/testdir/", dir) assert.are.equal("file", name) - assert.are.equal("mp3", ext) + assert.are.equal(".mp3", ext) end) end) @@ -39,13 +41,13 @@ describe("nextfile", function() end) end) - --insulate("prevfile.prevfile returns a numeric filename", function() - --prevfile.prevfile = function() return "/testdir/701.txt" end --- + insulate("prevfile.prevfile returns a numeric filename", function() + prevfile.prevfile = function() return "/testdir/701.txt" end + --it("should return the result of incrementing the filename", function() --local file = nextfile.nextfile("/testdir") --- + --assert.are.equal("/testdir/702.txt", file) --end) - --end) + end) end) diff --git a/src/nextfile.lua b/src/nextfile.lua index 2464595..695e4a9 100644 --- a/src/nextfile.lua +++ b/src/nextfile.lua @@ -3,15 +3,18 @@ local prevfile = require "prevfile" local nextfile = {} function nextfile.splitfilename(path) - name, ext = path:match("^.*/(.*)%.(%w*)") - return name, ext + dir, name, ext = path:match("^(.*/)(.*)(%.%w*)") + return dir, name, ext end function nextfile.nextfile(directory) local previous = prevfile.prevfile(directory) if previous == nil then return nil end - local name, ext = nextfile.splitfilename(previous) + local dir, name, ext = nextfile.splitfilename(previous) + print(dir) + print(name) + print(ext) return "" end