nextfile/spec/nextfile_spec.lua

54 lines
1.5 KiB
Lua
Raw Normal View History

describe("splitfilename", function()
2023-11-18 17:57:53 +00:00
local nextfile = require "nextfile"
it("should return the filename and extension of an absolute filepath", function()
2023-11-18 19:21:46 +00:00
local dir, name, ext = nextfile.splitfilename("/testdir/701.txt")
2023-11-18 17:57:53 +00:00
2023-11-18 19:21:46 +00:00
assert.are.equal("/testdir/", dir)
2023-11-18 17:57:53 +00:00
assert.are.equal("701", name)
2023-11-18 19:21:46 +00:00
assert.are.equal(".txt", ext)
2023-11-18 17:57:53 +00:00
end)
it("should return the filename and extension of a relative filepath", function()
2023-11-18 19:21:46 +00:00
local dir, name, ext = nextfile.splitfilename("../../foo/testdir/file.mp3")
2023-11-18 17:57:53 +00:00
2023-11-18 19:21:46 +00:00
assert.are.equal("../../foo/testdir/", dir)
2023-11-18 17:57:53 +00:00
assert.are.equal("file", name)
2023-11-18 19:21:46 +00:00
assert.are.equal(".mp3", ext)
2023-11-18 17:57:53 +00:00
end)
end)
2023-11-18 12:46:28 +00:00
describe("nextfile", function()
2023-11-18 17:57:53 +00:00
local prevfile = require "prevfile"
2023-11-18 12:46:28 +00:00
local nextfile = require "nextfile"
2023-11-18 17:57:53 +00:00
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)
2023-11-18 12:46:28 +00:00
end)
2023-11-18 17:57:53 +00:00
2023-11-18 19:21:46 +00:00
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")
2023-11-18 19:21:46 +00:00
--assert.are.equal("/testdir/702.txt", file)
--end)
2023-11-18 19:21:46 +00:00
end)
2023-11-18 12:46:28 +00:00
end)