aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/query/outputs_test.go
diff options
context:
space:
mode:
authorJP Appel <jeanpierre.appel01@gmail.com>2025-04-28 23:34:42 -0400
committerJP Appel <jeanpierre.appel01@gmail.com>2025-04-28 23:34:42 -0400
commit35ec0f5afb9800b25bd813bccc57a16bc9f837c4 (patch)
tree3caae3b9410e6a2d8f099c0e072cb654f210e4b6 /pkg/query/outputs_test.go
parent34b8d8ff1f9d65c08a9156d72f08cf548183c6f4 (diff)
Add document output formatting
Diffstat (limited to 'pkg/query/outputs_test.go')
-rw-r--r--pkg/query/outputs_test.go62
1 files changed, 62 insertions, 0 deletions
diff --git a/pkg/query/outputs_test.go b/pkg/query/outputs_test.go
new file mode 100644
index 0000000..b5fdba7
--- /dev/null
+++ b/pkg/query/outputs_test.go
@@ -0,0 +1,62 @@
+package query
+
+import (
+ "errors"
+ "slices"
+ "testing"
+)
+
+func Test_parseOutputFormat(t *testing.T) {
+ tests := []struct {
+ name string
+ formatStr string
+ wantToks []OutputToken
+ wantStrToks []string
+ wantErr error
+ }{
+ {
+ "one big string",
+ "here is a string with no placeholders",
+ []OutputToken{OUT_TOK_STR},
+ []string{"here is a string with no placeholders"},
+ nil,
+ },
+ {
+ "default format",
+ "%p %T %d authors:%a tags:%t",
+ []OutputToken{OUT_TOK_PATH, OUT_TOK_STR, OUT_TOK_TITLE, OUT_TOK_STR, OUT_TOK_DATE, OUT_TOK_STR, OUT_TOK_AUTHORS, OUT_TOK_STR, OUT_TOK_TAGS},
+ []string{" ", " ", " authors:", " tags:"},
+ nil,
+ },
+ {
+ "literal percents",
+ "%%%p%%%T%%",
+ []OutputToken{OUT_TOK_STR, OUT_TOK_PATH, OUT_TOK_STR, OUT_TOK_TITLE, OUT_TOK_STR},
+ []string{"%", "%", "%"},
+ nil,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ gotToks, gotStrToks, gotErr := parseOutputFormat(tt.formatStr)
+
+ if !errors.Is(gotErr, tt.wantErr) {
+ t.Errorf("Recieved unexpected error: got %v want %v", gotErr, tt.wantErr)
+ } else if gotErr != nil {
+ return
+ }
+
+ if !slices.Equal(gotToks, tt.wantToks) {
+ t.Error("Unequal output tokens")
+ t.Log("Got:", gotToks)
+ t.Log("Want:", tt.wantToks)
+ }
+
+ if !slices.Equal(gotStrToks, tt.wantStrToks) {
+ t.Error("Unequal string tokens")
+ t.Log("Got:", gotStrToks)
+ t.Log("Want:", tt.wantStrToks)
+ }
+ })
+ }
+}