2020-10-30 17:20:04 +00:00
|
|
|
link = require 'zettelkasten.link'
|
2020-10-30 15:30:37 +00:00
|
|
|
Test_date = {year = 2019, month = 10, day = 29, hour = 16, min = 45}
|
|
|
|
|
|
|
|
before_each(function() _G.vim = {g = {}, b = {}} end)
|
|
|
|
after_each(function() _G.vim = nil end)
|
|
|
|
|
2020-10-30 17:20:04 +00:00
|
|
|
describe("prepend_anchor", function()
|
|
|
|
it("should append text to link", function()
|
|
|
|
assert.same("1910291645_isappended",
|
|
|
|
link.prepend_anchor("1910291645", "isappended"))
|
|
|
|
end)
|
|
|
|
it("should not add a separator if no text appended", function()
|
|
|
|
assert.same("1910291645", link.prepend_anchor("1910291645", ""))
|
|
|
|
end)
|
2020-10-30 15:30:37 +00:00
|
|
|
|
2020-10-30 17:20:04 +00:00
|
|
|
it("should return solely the anchor if no text is passed in", function()
|
|
|
|
assert.same("1910291645", link.prepend_anchor("1910291645", nil))
|
|
|
|
end)
|
|
|
|
it("should return solely the anchor if empty text is passed in", function()
|
|
|
|
assert.same("1910291645", link.prepend_anchor("1910291645", ""))
|
|
|
|
end)
|
|
|
|
it("should add contents of g:zettel_anchor_separator variable to link",
|
|
|
|
function()
|
|
|
|
vim.g.zettel_anchor_separator = "SEP"
|
|
|
|
assert.same("1910291645SEParated",
|
|
|
|
link.prepend_anchor("1910291645", "arated"))
|
|
|
|
end)
|
|
|
|
it("should add contents of b:zettel_anchor_separator variable to link",
|
|
|
|
function()
|
|
|
|
vim.b.zettel_anchor_separator = "---"
|
|
|
|
assert.same("1910291645---arated",
|
|
|
|
link.prepend_anchor("1910291645", "arated"))
|
2020-10-30 15:30:37 +00:00
|
|
|
end)
|
2020-10-30 17:20:04 +00:00
|
|
|
end)
|
2020-10-30 15:30:37 +00:00
|
|
|
|
2020-10-30 17:20:04 +00:00
|
|
|
describe("clean", function()
|
2020-10-30 15:30:37 +00:00
|
|
|
it("should return lowercased link text", function()
|
2020-10-30 17:20:04 +00:00
|
|
|
assert.same("yesiamshouting", link.clean("YESIAMSHOUTING"))
|
2020-10-30 15:30:37 +00:00
|
|
|
end)
|
|
|
|
|
|
|
|
it("should return spaces in text replaced with dashes", function()
|
2020-10-30 17:20:04 +00:00
|
|
|
assert.same("yes-indeed-a-space", link.clean("yes indeed a space"))
|
2020-10-30 15:30:37 +00:00
|
|
|
end)
|
2020-10-30 17:20:04 +00:00
|
|
|
end)
|
2020-10-30 15:30:37 +00:00
|
|
|
|
2020-10-30 17:20:04 +00:00
|
|
|
describe("append_extension", function()
|
|
|
|
it("should append the contents set in global zettel extension option",
|
2020-10-30 15:30:37 +00:00
|
|
|
function()
|
2020-10-30 17:20:04 +00:00
|
|
|
vim.g.zettel_extension = ".extension"
|
|
|
|
assert.same("myfile.extension", link.append_extension("myfile"))
|
2020-10-30 15:30:37 +00:00
|
|
|
end)
|
2020-10-30 17:20:04 +00:00
|
|
|
it("should append the contents set in global zettel extension option",
|
2020-10-30 15:30:37 +00:00
|
|
|
function()
|
2020-10-30 17:20:04 +00:00
|
|
|
vim.b.zettel_extension = ".bufext"
|
|
|
|
assert.same("myfile.bufext", link.append_extension("myfile"))
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
|
|
|
describe("style_markdown", function()
|
|
|
|
it("should correctly apply transformations to link and text", function()
|
|
|
|
assert.same("[My AWESOME Link](1910291645_my-awesome-link.md)",
|
|
|
|
link.style_markdown("1910291645_my-awesome-link.md",
|
|
|
|
"My AWESOME Link"))
|
|
|
|
end)
|
|
|
|
it("should trim whitespace for the text area", function()
|
|
|
|
assert.same("[](1910291645_my-awesome-link.md)",
|
|
|
|
link.style_markdown("1910291645_my-awesome-link.md", " "))
|
|
|
|
assert.same("[hi](1910291645_my-awesome-link.md)", link.style_markdown(
|
|
|
|
"1910291645_my-awesome-link.md", " hi "))
|
2020-10-30 15:30:37 +00:00
|
|
|
end)
|
2020-10-30 17:20:04 +00:00
|
|
|
it("should error if no link provided", function()
|
|
|
|
assert.is_error(function() link.style_markdown("", "mytext") end)
|
|
|
|
assert.is_error(function() link.style_markdown(nil, "mytext") end)
|
|
|
|
end)
|
|
|
|
end)
|
2020-10-30 15:30:37 +00:00
|
|
|
|
2020-10-30 17:20:04 +00:00
|
|
|
describe("style_wiki", function()
|
|
|
|
it("should error if no link provided", function()
|
|
|
|
assert.is_error(function() link.style_wiki("", "mytext") end)
|
|
|
|
assert.is_error(function() link.style_wiki(nil, "mytext") end)
|
|
|
|
end)
|
|
|
|
it("should correctly apply transformations to link and text", function()
|
|
|
|
assert.same("[[1910291645|My AWESOME Link]]",
|
|
|
|
link.style_wiki("1910291645", "My AWESOME Link"))
|
2020-10-30 15:30:37 +00:00
|
|
|
end)
|
2020-10-30 17:20:04 +00:00
|
|
|
it("should trim whitespace for the text area", function()
|
|
|
|
assert.same("[[1910291645]]", link.style_wiki("1910291645", " "))
|
|
|
|
assert.same("[[1910291645|hi]]",
|
|
|
|
link.style_wiki("1910291645", " hi "))
|
2020-10-30 15:30:37 +00:00
|
|
|
end)
|
|
|
|
end)
|