Add simple zettel retrieval function

This commit is contained in:
Marty Oehme 2020-10-30 13:48:17 +01:00
parent 313ad0b60c
commit e96b454b23
Signed by: Marty
GPG key ID: B7538B8F50A1C800
2 changed files with 41 additions and 21 deletions

View file

@ -31,4 +31,12 @@ function ls.get_anchors_and_paths(path, recursive, options)
return zettel
end
-- Returns the path to the zettel defined by the anchor argument.
-- Take a list of zettel as an optional variable, without which
-- it will use the (recursive) results of the zettel_root directory.
function ls.get_zettel(anchor, all)
return all[anchor]
end
return ls

View file

@ -1,9 +1,7 @@
ls = require'zettelkasten.list'
-- these tests, I suppose, only work on unix due to the file structure
describe("zettel listing", function()
before_each(function()
_G.get_api_mock = function(files)
local function simple_api_mock(files)
return {
g = {},
b = {},
@ -21,9 +19,12 @@ describe("zettel listing", function()
}
}
end
describe("get_anchors_and_paths", function()
before_each(function()
get_api_mock = simple_api_mock
end)
after_each(function()
_G.get_api_mock = nil
_G.vim = nil
end)
@ -138,5 +139,16 @@ describe("zettel listing", function()
assert.same(expected, ls.get_anchors_and_paths('mydirectory', false, vim.g))
end)
end)
describe("get_zettel", function()
it("should return the correct zettel by id", function()
local file_list = {
["1910291645"] = "1910291645 myfile.md",
["2345678901"] = "2345678901 another.md",
}
_G.vim = simple_api_mock(file_list)
assert.same("1910291645 myfile.md", ls.get_zettel("1910291645", file_list))
end)
end)