Compare commits

..

No commits in common. "294e2f2d5bfb6a57de754fc3ba7cec313b9b60b2" and "7a6d182454bb56f010652ad58d7d0dd73f03074b" have entirely different histories.

3 changed files with 15 additions and 7 deletions

1
.gitignore vendored
View File

@ -1,2 +1 @@
luacov.stats.out luacov.stats.out
nextfile-0.0.1-1.src.rock

View File

@ -3,8 +3,8 @@ local prevfile = require "prevfile"
local nextfile = {} local nextfile = {}
function nextfile.splitfilename(path) function nextfile.splitfilename(path)
name, ext = path:match("^(.*)(%.%w*)") dir, name, ext = path:match("^(.*/)(.*)(%.%w*)")
return name, ext return dir, name, ext
end end
function nextfile.nextletter(letter) function nextfile.nextletter(letter)
@ -19,9 +19,9 @@ function nextfile.nextfile(directory, extension)
local previous = prevfile.prevfile(directory) local previous = prevfile.prevfile(directory)
if previous == nil then return nil end if previous == nil then return nil end
local name, ext = nextfile.splitfilename(previous) local dir, name, ext = nextfile.splitfilename(previous)
value = "" value = dir
if tonumber(name) == nil then if tonumber(name) == nil then
local lastletter = name:sub(#name) local lastletter = name:sub(#name)
local nextletter = nextfile.nextletter(lastletter) local nextletter = nextfile.nextletter(lastletter)

View File

@ -1,12 +1,21 @@
describe("splitfilename", function() describe("splitfilename", function()
local nextfile = require "nextfile" local nextfile = require "nextfile"
it("should return the filename and extension of a filename", function() it("should return the filename and extension of an absolute filepath", function()
local name, ext = nextfile.splitfilename("701.txt") local dir, name, ext = nextfile.splitfilename("/testdir/701.txt")
assert.are.equal("/testdir/", dir)
assert.are.equal("701", name) assert.are.equal("701", name)
assert.are.equal(".txt", ext) assert.are.equal(".txt", ext)
end) end)
it("should return the filename and extension of a relative filepath", function()
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)
end)
end) end)
describe("nextletter", function() describe("nextletter", function()