mirror of https://github.com/mickael-menu/zk
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.6 KiB
Go
65 lines
1.6 KiB
Go
4 years ago
|
package cmd
|
||
|
|
||
|
import (
|
||
|
"testing"
|
||
|
|
||
|
"github.com/mickael-menu/zk/internal/util/test/assert"
|
||
|
)
|
||
|
|
||
|
func TestListFormatDefault(t *testing.T) {
|
||
|
cmd := List{}
|
||
|
assert.Equal(t, cmd.noteTemplate(), `{{style "title" title}} {{style "path" path}} ({{date created "elapsed"}})
|
||
|
|
||
|
{{list snippets}}`)
|
||
|
}
|
||
|
|
||
|
func TestListFormatPredefined(t *testing.T) {
|
||
|
test := func(format, expectedTemplate string) {
|
||
|
cmd := List{Format: format}
|
||
|
assert.Equal(t, cmd.noteTemplate(), expectedTemplate)
|
||
|
}
|
||
|
|
||
|
// Known formats
|
||
|
test("path", `{{path}}`)
|
||
|
|
||
|
test("oneline", `{{style "title" title}} {{style "path" path}} ({{date created "elapsed"}})`)
|
||
|
|
||
|
test("short", `{{style "title" title}} {{style "path" path}} ({{date created "elapsed"}})
|
||
|
|
||
|
{{list snippets}}`)
|
||
|
|
||
|
test("medium", `{{style "title" title}} {{style "path" path}}
|
||
|
Created: {{date created "short"}}
|
||
|
|
||
|
{{list snippets}}`)
|
||
|
|
||
|
test("long", `{{style "title" title}} {{style "path" path}}
|
||
|
Created: {{date created "short"}}
|
||
|
Modified: {{date created "short"}}
|
||
|
|
||
|
{{list snippets}}`)
|
||
|
|
||
|
test("full", `{{style "title" title}} {{style "path" path}}
|
||
|
Created: {{date created "short"}}
|
||
|
Modified: {{date created "short"}}
|
||
|
Tags: {{join tags ", "}}
|
||
|
|
||
|
{{prepend " " body}}
|
||
|
`)
|
||
|
|
||
|
// Predefined formats are case sensitive.
|
||
|
test("Path", "Path")
|
||
|
}
|
||
|
|
||
|
func TestListFormatCustom(t *testing.T) {
|
||
|
test := func(format, expectedTemplate string) {
|
||
|
cmd := List{Format: format}
|
||
|
assert.Equal(t, cmd.noteTemplate(), expectedTemplate)
|
||
|
}
|
||
|
|
||
|
// Custom formats are used literally.
|
||
|
test("{{title}}", "{{title}}")
|
||
|
// \n and \t in custom formats are expanded.
|
||
|
test(`{{title}}\t{{path}}\n{{snippet}}`, "{{title}}\t{{path}}\n{{snippet}}")
|
||
|
}
|