96 lines
2.7 KiB
Lua
96 lines
2.7 KiB
Lua
describe("splitfilename", function()
|
|
local nextfile = require "nextfile"
|
|
|
|
it("should return the filename and extension of an absolute filepath", function()
|
|
local dir, name, ext = nextfile.splitfilename("/testdir/701.txt")
|
|
|
|
assert.are.equal("/testdir/", dir)
|
|
assert.are.equal("701", name)
|
|
assert.are.equal(".txt", ext)
|
|
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)
|
|
|
|
describe("nextletter", function()
|
|
local nextfile = require "nextfile"
|
|
|
|
it("should return the next letter when the current letter is not 'z'", function()
|
|
local letter = nextfile.nextletter("q")
|
|
|
|
assert.are.equal("r", letter)
|
|
end)
|
|
|
|
it("should return 'za' when the current letter is 'z'", function()
|
|
local letter = nextfile.nextletter("z")
|
|
|
|
assert.are.equal("za", letter)
|
|
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)
|
|
|
|
insulate("prevfile.prevfile returns a non-numeric filename", function()
|
|
it("should return the result of replacing the last character with the next letter of the alphabet", function()
|
|
prevfile.prevfile = function() return "/testdir/421b.txt" end
|
|
|
|
local file = nextfile.nextfile("/testdir")
|
|
|
|
assert.are.equal("/testdir/421c.txt", file)
|
|
end)
|
|
|
|
it("should return the result of replacing z with za when z is the last letter of the filename", function()
|
|
prevfile.prevfile = function() return "/testdir/421z.txt" end
|
|
|
|
local file = nextfile.nextfile("/testdir")
|
|
|
|
assert.are.equal("/testdir/421za.txt", file)
|
|
end)
|
|
|
|
it("should use the provided file extension if one is given", function()
|
|
prevfile.prevfile = function() return "/testdir/900.txt" end
|
|
|
|
local file = nextfile.nextfile("/testdir", "yaml")
|
|
|
|
assert.are.equal("/testdir/901.yaml", file)
|
|
end)
|
|
end)
|
|
end)
|