Fix nextfile expecting full path from prevfile
This commit is contained in:
parent
7a6d182454
commit
160b7509a2
|
@ -3,8 +3,8 @@ local prevfile = require "prevfile"
|
||||||
local nextfile = {}
|
local nextfile = {}
|
||||||
|
|
||||||
function nextfile.splitfilename(path)
|
function nextfile.splitfilename(path)
|
||||||
dir, name, ext = path:match("^(.*/)(.*)(%.%w*)")
|
name, ext = path:match("^(.*)(%.%w*)")
|
||||||
return dir, name, ext
|
return 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 dir, name, ext = nextfile.splitfilename(previous)
|
local name, ext = nextfile.splitfilename(previous)
|
||||||
|
|
||||||
value = dir
|
value = ""
|
||||||
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)
|
||||||
|
|
|
@ -1,21 +1,12 @@
|
||||||
describe("splitfilename", function()
|
describe("splitfilename", function()
|
||||||
local nextfile = require "nextfile"
|
local nextfile = require "nextfile"
|
||||||
|
|
||||||
it("should return the filename and extension of an absolute filepath", function()
|
it("should return the filename and extension of a filename", function()
|
||||||
local dir, name, ext = nextfile.splitfilename("/testdir/701.txt")
|
local name, ext = nextfile.splitfilename("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()
|
||||||
|
|
Loading…
Reference in New Issue