Compare commits

..

2 Commits

Author SHA1 Message Date
The Magician 294e2f2d5b .gitignore .rock 2023-11-20 18:59:58 +00:00
The Magician 160b7509a2 Fix nextfile expecting full path from prevfile 2023-11-20 18:59:37 +00:00
3 changed files with 7 additions and 15 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
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)
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)

View File

@ -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()