Add simple zettel retrieval function
This commit is contained in:
parent
313ad0b60c
commit
e96b454b23
2 changed files with 41 additions and 21 deletions
|
@ -31,4 +31,12 @@ function ls.get_anchors_and_paths(path, recursive, options)
|
||||||
return zettel
|
return zettel
|
||||||
end
|
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
|
return ls
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
ls = require'zettelkasten.list'
|
ls = require'zettelkasten.list'
|
||||||
-- these tests, I suppose, only work on unix due to the file structure
|
-- these tests, I suppose, only work on unix due to the file structure
|
||||||
|
|
||||||
describe("zettel listing", function()
|
local function simple_api_mock(files)
|
||||||
before_each(function()
|
|
||||||
_G.get_api_mock = function(files)
|
|
||||||
return {
|
return {
|
||||||
g = {},
|
g = {},
|
||||||
b = {},
|
b = {},
|
||||||
|
@ -20,10 +18,13 @@ describe("zettel listing", function()
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe("get_anchors_and_paths", function()
|
||||||
|
before_each(function()
|
||||||
|
get_api_mock = simple_api_mock
|
||||||
end)
|
end)
|
||||||
after_each(function()
|
after_each(function()
|
||||||
_G.get_api_mock = nil
|
|
||||||
_G.vim = nil
|
_G.vim = nil
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
@ -138,5 +139,16 @@ describe("zettel listing", function()
|
||||||
assert.same(expected, ls.get_anchors_and_paths('mydirectory', false, vim.g))
|
assert.same(expected, ls.get_anchors_and_paths('mydirectory', false, vim.g))
|
||||||
|
|
||||||
end)
|
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)
|
end)
|
||||||
|
|
Loading…
Reference in a new issue