[go: up one dir, main page]

Add test suite for template.lua variable expansion engine

Overview

The template.lua module (~120 lines) handles template variable expansion, a core feature. It has no test coverage.

Functions Needing Tests

Public API

  • build_context(notebook_path) - Build template context

    • Test: includes date variables (date, time, datetime, iso_datetime)
    • Test: includes file variables (file, filename, basename, ext, dir, relpath)
    • Test: includes cursor variables (cursor_line, cursor_col)
    • Test: includes clipboard content
    • Test: handles custom variables from vim.g.zk_template_vars
    • Test: handles custom variables from function
    • Test: handles missing notebook_path
    • Test: computes relative path correctly
  • expand_template(text, context) - Expand template variables

    • Test: expands {{date}} to current date
    • Test: expands {{time}} to current time
    • Test: expands {{datetime}} correctly
    • Test: expands {{iso_datetime}} with timezone
    • Test: expands {{file}}, {{filename}}, {{basename}}, {{ext}}
    • Test: expands {{dir}}, {{relpath}}, {{notebook}}
    • Test: expands {{cursor_line}}, {{cursor_col}}
    • Test: expands {{clipboard}}
    • Test: expands custom variables
    • Test: handles {{input:prompt}} with user input
    • Test: handles {{ENV:VAR_NAME}} environment variables
    • Test: handles {{reg:x}} vim registers
    • Test: leaves unknown variables unchanged
    • Test: auto-builds context when not provided

Internal Functions

  • new_from_template() - Create note from template picker
    • Test: shows template picker
    • Test: prompts for title
    • Test: calls zk.new with correct parameters
    • Test: handles zk-nvim not available
    • Test: handles no templates found
    • Test: handles user cancellation

Edge Cases to Test

  • Empty template text
  • Template with no variables
  • Template with malformed variables
  • Multiple variables on same line
  • Nested variable-like patterns
  • Very long template text
  • Unicode in template text
  • Special characters in variable values

Test File Location

tests/zk-extras/template_spec.lua

Priority

High - Template expansion is a key differentiator of this plugin