aboutsummaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
Diffstat (limited to 'commands')
-rw-r--r--commands/commands.go5
-rw-r--r--commands/commands_test.go52
2 files changed, 52 insertions, 5 deletions
diff --git a/commands/commands.go b/commands/commands.go
index 7dfd183b..59f87321 100644
--- a/commands/commands.go
+++ b/commands/commands.go
@@ -98,8 +98,7 @@ func templateData(
msg, _ = acct.SelectedMessage()
}
- var data state.TemplateData
-
+ data := state.NewDataSetter()
data.SetAccount(cfg)
data.SetFolder(folder)
data.SetInfo(msg, 0, false)
@@ -109,7 +108,7 @@ func templateData(
})
}
- return &data
+ return data.Data()
}
func (cmds *Commands) ExecuteCommand(
diff --git a/commands/commands_test.go b/commands/commands_test.go
index a424d16d..dccb8572 100644
--- a/commands/commands_test.go
+++ b/commands/commands_test.go
@@ -3,8 +3,10 @@ package commands
import (
"reflect"
"testing"
+ "time"
- "git.sr.ht/~rjarry/aerc/lib/state"
+ "git.sr.ht/~rjarry/aerc/models"
+ "github.com/emersion/go-message/mail"
)
func TestExecuteCommand_expand(t *testing.T) {
@@ -40,7 +42,7 @@ func TestExecuteCommand_expand(t *testing.T) {
},
}
- data := state.TemplateData{}
+ var data dummyData
for i, test := range tests {
got, err := expand(&data, test.args)
@@ -52,3 +54,49 @@ func TestExecuteCommand_expand(t *testing.T) {
}
}
}
+
+// only for validation
+type dummyData struct{}
+
+var (
+ addr1 = mail.Address{Name: "John Foo", Address: "foo@bar.org"}
+ addr2 = mail.Address{Name: "John Bar", Address: "bar@foo.org"}
+)
+
+func (d *dummyData) Account() string { return "work" }
+func (d *dummyData) Folder() string { return "INBOX" }
+func (d *dummyData) To() []*mail.Address { return []*mail.Address{&addr1} }
+func (d *dummyData) Cc() []*mail.Address { return nil }
+func (d *dummyData) Bcc() []*mail.Address { return nil }
+func (d *dummyData) From() []*mail.Address { return []*mail.Address{&addr2} }
+func (d *dummyData) Peer() []*mail.Address { return d.From() }
+func (d *dummyData) ReplyTo() []*mail.Address { return nil }
+func (d *dummyData) Date() time.Time { return time.Now() }
+func (d *dummyData) DateAutoFormat(time.Time) string { return "" }
+func (d *dummyData) Header(string) string { return "" }
+func (d *dummyData) ThreadPrefix() string { return "└─>" }
+func (d *dummyData) Subject() string { return "Re: [PATCH] hey" }
+func (d *dummyData) SubjectBase() string { return "[PATCH] hey" }
+func (d *dummyData) Number() int { return 0 }
+func (d *dummyData) Labels() []string { return nil }
+func (d *dummyData) Flags() []string { return nil }
+func (d *dummyData) MessageId() string { return "123456789@foo.org" }
+func (d *dummyData) Size() int { return 420 }
+func (d *dummyData) OriginalText() string { return "Blah blah blah" }
+func (d *dummyData) OriginalDate() time.Time { return time.Now() }
+func (d *dummyData) OriginalFrom() []*mail.Address { return d.From() }
+func (d *dummyData) OriginalMIMEType() string { return "text/plain" }
+func (d *dummyData) OriginalHeader(string) string { return "" }
+func (d *dummyData) Recent(...string) int { return 1 }
+func (d *dummyData) Unread(...string) int { return 3 }
+func (d *dummyData) Exists(...string) int { return 14 }
+func (d *dummyData) RUE(...string) string { return "1/3/14" }
+func (d *dummyData) Connected() bool { return false }
+func (d *dummyData) ConnectionInfo() string { return "" }
+func (d *dummyData) ContentInfo() string { return "" }
+func (d *dummyData) StatusInfo() string { return "" }
+func (d *dummyData) TrayInfo() string { return "" }
+func (d *dummyData) PendingKeys() string { return "" }
+func (d *dummyData) Role() string { return "inbox" }
+func (d *dummyData) Style(string, string) string { return "" }
+func (d *dummyData) StyleSwitch(string, ...models.Case) string { return "" }