aboutsummaryrefslogtreecommitdiff
path: root/pkg/rfc822/writer_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/rfc822/writer_test.go')
-rw-r--r--pkg/rfc822/writer_test.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/pkg/rfc822/writer_test.go b/pkg/rfc822/writer_test.go
new file mode 100644
index 0000000..7beae8d
--- /dev/null
+++ b/pkg/rfc822/writer_test.go
@@ -0,0 +1,47 @@
+package rfc822
+
+import (
+ "bytes"
+ "io"
+ "testing"
+)
+
+func TestRfc822Writer_Write(t *testing.T) {
+ tests := []struct {
+ before string
+ after string
+ }{
+ {"", ""},
+ {"foo", "foo"},
+ {"foo\r", "foo\r\n"},
+ {"foo\n", "foo\r\n"},
+ {"foo\r\n", "foo\r\n"},
+ {"\r", "\r\n"},
+ {"\n", "\r\n"},
+ {"\r\n", "\r\n"},
+ {"foo\rbar", "foo\r\nbar"},
+ {"foo\nbar", "foo\r\nbar"},
+ {"foo\r\nbar", "foo\r\nbar"},
+ {"\r\r", "\r\n\r\n"},
+ {"\n\n", "\r\n\r\n"},
+ {"\r\r\n", "\r\n\r\n"},
+ {"\n\r", "\r\n\r\n"},
+ {"\rbar", "\r\nbar"},
+ {"\nbar", "\r\nbar"},
+ {"\r\nbar", "\r\nbar"},
+ }
+ for _, tt := range tests {
+ t.Run(tt.before, func(t *testing.T) {
+ b := bytes.Buffer{}
+ w := Writer(&b)
+ if _, err := io.WriteString(w, tt.before); err != nil {
+ t.Errorf("Error: %v", err)
+ return
+ }
+ res := b.String()
+ if tt.after != res {
+ t.Errorf("Expected: %q, got: %q", tt.after, res)
+ }
+ })
+ }
+}