aboutsummaryrefslogtreecommitdiffstats
path: root/commands/commands_test.go
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2023-05-06 11:30:48 +0200
committerRobin Jarry <robin@jarry.cc>2023-05-16 17:12:00 +0200
commit30c1a30168dfff8ca5eecb8d0fa42ab4b638f79d (patch)
tree97d177a8e399ed7ad7f107b85df1cd4d246e50ff /commands/commands_test.go
parent6b6aaf3ae131971d05ab3f849ea3db14c6a6e055 (diff)
downloadaerc-30c1a30168dfff8ca5eecb8d0fa42ab4b638f79d.tar.gz
templates: use template interface consistently
Use the template interface consistently. Before, we have exported the state.TemplateData struct and used it in most places instead of the models.TemplateData interface. This lead to some inconsistencies, i.e. Role() has been defined on the exported struct but not on the interface. Unexport the state.TemplateData struct, add a DataSetter interface to set the data needed for the template data and call the Data() method which returns a models.TemplateData interface when the template data is needed. Signed-off-by: Koni Marti <koni.marti@gmail.com> Acked-by: Tim Culverhouse <tim@timculverhouse.com>
Diffstat (limited to 'commands/commands_test.go')
-rw-r--r--commands/commands_test.go52
1 files changed, 50 insertions, 2 deletions
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 "" }