Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions tests/markdown-notes/config_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,32 @@ describe("config", function()
assert.is_not_nil(config.options.mappings.new_note)
end)

it("merges user-defined template variables with defaults", function()
local user_opts = {
template_vars = {
author = function() return "Test Author" end,
project = function() return "test-project" end,
custom_string = "static-value"
}
}

config.setup(user_opts)

-- User variables should be present
assert.is_function(config.options.template_vars.author)
assert.is_function(config.options.template_vars.project)
assert.are.equal("static-value", config.options.template_vars.custom_string)

-- Default variables should still be present
assert.is_function(config.options.template_vars.date)
assert.is_function(config.options.template_vars.time)
assert.is_function(config.options.template_vars.title)

-- Test that user functions work
assert.are.equal("Test Author", config.options.template_vars.author())
assert.are.equal("test-project", config.options.template_vars.project())
end)

describe("workspaces", function()
it("sets up workspace with custom config", function()
local workspace_opts = {
Expand Down
49 changes: 49 additions & 0 deletions tests/markdown-notes/templates_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,54 @@ describe("templates", function()
assert.matches("%d%d%d%d%-%d%d%-%d%d", result[1])
assert.matches("%d%d:%d%d", result[1])
end)

it("uses config-defined template variables", function()
-- Setup config with custom template variables
config.setup({
template_vars = {
author = function() return "Test Author" end,
project = function() return "my-project" end,
custom_static = "static-content"
}
})

local content = {
"Author: {{author}}",
"Project: {{project}}",
"Static: {{custom_static}}",
"Date: {{date}}"
}

local result = templates.substitute_template_vars(content)

-- Custom variables should be substituted
assert.are.equal("Author: Test Author", result[1])
assert.are.equal("Project: my-project", result[2])
assert.are.equal("Static: static-content", result[3])

-- Default variables should still work
assert.matches("Date: %d%d%d%d%-%d%d%-%d%d", result[4])
end)

it("overrides config variables with custom vars parameter", function()
-- Setup config with a template variable
config.setup({
template_vars = {
author = function() return "Config Author" end,
}
})

local content = {"Author: {{author}}"}

-- Override with custom vars
local custom_vars = {
author = function() return "Override Author" end
}

local result = templates.substitute_template_vars(content, custom_vars)

-- Should use the override, not the config value
assert.are.equal("Author: Override Author", result[1])
end)
end)
end)