aboutsummaryrefslogtreecommitdiffstats
path: root/commands/commands_test.go
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2023-05-10 23:56:25 +0200
committerRobin Jarry <robin@jarry.cc>2023-05-16 13:41:02 +0200
commit42cd415756bff13acd306db21eff5f4439665270 (patch)
tree9fe9bfe9d3224f88961f922fcf5a6b6ba23c8bab /commands/commands_test.go
parent20747fcf104aa05bdc4d7d2b12a2488940bcae2f (diff)
downloadaerc-42cd415756bff13acd306db21eff5f4439665270.tar.gz
commands: execute commands with templates
Execute template code before running a command. With this, we can use templates in our keybinds like: [messages] E = :'{{if match (.Flags|join "") "O"}}envelope{{else}}view{{end}}'<Enter> Signed-off-by: Koni Marti <koni.marti@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'commands/commands_test.go')
-rw-r--r--commands/commands_test.go54
1 files changed, 54 insertions, 0 deletions
diff --git a/commands/commands_test.go b/commands/commands_test.go
new file mode 100644
index 00000000..a424d16d
--- /dev/null
+++ b/commands/commands_test.go
@@ -0,0 +1,54 @@
+package commands
+
+import (
+ "reflect"
+ "testing"
+
+ "git.sr.ht/~rjarry/aerc/lib/state"
+)
+
+func TestExecuteCommand_expand(t *testing.T) {
+ tests := []struct {
+ args []string
+ want []string
+ }{
+ {
+ args: []string{"prompt", "Really quit? ", "quit"},
+ want: []string{"prompt", "Really quit? ", "quit"},
+ },
+ {
+ args: []string{"{{", "print", "\"hello\"", "}}"},
+ want: []string{"hello"},
+ },
+ {
+ args: []string{"prompt", "Really quit ? ", " quit "},
+ want: []string{"prompt", "Really quit ? ", " quit "},
+ },
+ {
+ args: []string{
+ "prompt", "Really quit? ", "{{",
+ "print", "\"quit\"", "}}",
+ },
+ want: []string{"prompt", "Really quit? ", "quit"},
+ },
+ {
+ args: []string{
+ "prompt", "Really quit? ", "{{",
+ "if", "1", "}}", "quit", "{{end}}",
+ },
+ want: []string{"prompt", "Really quit? ", "quit"},
+ },
+ }
+
+ data := state.TemplateData{}
+
+ for i, test := range tests {
+ got, err := expand(&data, test.args)
+ if err != nil {
+ t.Errorf("test %d failed with err: %v", i, err)
+ } else if !reflect.DeepEqual(got, test.want) {
+ t.Errorf("test %d failed: "+
+ "got: %v, but want: %v", i, got, test.want)
+ }
+ }
+}