Add basename function to nextfile
This commit is contained in:
parent
d802a6e25f
commit
04e9638261
|
@ -1,7 +1,49 @@
|
|||
describe("nextfile", function()
|
||||
describe("basename", function()
|
||||
local nextfile = require "nextfile"
|
||||
|
||||
it("returns true", function()
|
||||
assert.is_true(nextfile.nextfile())
|
||||
it("should return the basename of an absolute filepath", function()
|
||||
local name = nextfile.basename("/testdir/701.txt")
|
||||
|
||||
assert.are.equal("701", name)
|
||||
end)
|
||||
|
||||
it("should return the basename of a relative filepath", function()
|
||||
local name = nextfile.basename("../../foo/testdir/file.mp3")
|
||||
|
||||
assert.are.equal("file", name)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("nextfile", function()
|
||||
local prevfile = require "prevfile"
|
||||
local nextfile = require "nextfile"
|
||||
|
||||
insulate("prevfile.prevfile returns nil", function()
|
||||
prevfile.prevfile = function() return nil end
|
||||
|
||||
it("should call prevfile.prevfile", function()
|
||||
spy.on(prevfile, "prevfile")
|
||||
test_directory = "/testdir"
|
||||
|
||||
nextfile.nextfile(test_directory)
|
||||
|
||||
assert.spy(prevfile.prevfile).was_called_with(test_directory)
|
||||
end)
|
||||
|
||||
it("should return nil", function()
|
||||
local file = nextfile.nextfile("/testdir")
|
||||
|
||||
assert.are.equal(nil, file)
|
||||
end)
|
||||
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)
|
||||
|
|
|
@ -1,7 +1,15 @@
|
|||
local prevfile = require "prevfile"
|
||||
|
||||
local nextfile = {}
|
||||
|
||||
function nextfile.nextfile()
|
||||
return true
|
||||
function nextfile.basename(path)
|
||||
return path:match("^.*/(.*)%.%w*")
|
||||
|
||||
end
|
||||
|
||||
function nextfile.nextfile(directory)
|
||||
prevfile.prevfile(directory)
|
||||
return nil
|
||||
end
|
||||
|
||||
return nextfile
|
||||
|
|
Loading…
Reference in New Issue