-
Notifications
You must be signed in to change notification settings - Fork 0
/
mime_test.go
68 lines (52 loc) · 2.4 KB
/
mime_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package wail
import (
"strings"
"testing"
)
var emails = []string{
"example1@example.com",
"example2@example.com",
"example3@example.com",
"example4@example.com",
}
const subjectExample = `=?UTF-8?B?U29tZSB2ZXJ5IGxvbmcgdGV4dCB3aXRob3V0IG1lYW5pbmc=?=
=?UTF-8?B?U29tZSB2ZXJ5IGxvbmcgdGV4dCB3aXRob3V0IG1lYW5pbmc=?=
=?UTF-8?B?U29tZSB2ZXJ5IGxvbmcgdGV4dCB3aXRob3V0IG1lYW5pbmc=?=`
func TestMakeAddrString(t *testing.T) {
if str := makeAddrString(emails[:1]); str != "<example1@example.com>" {
t.Errorf("Invalid adress string, expect %s, got %s", "<example1@example.com>", str)
}
if str := makeAddrString(emails[:2]); str != "<example1@example.com>,<example2@example.com>" {
t.Errorf("Invalid adress string, expect %s, got %s",
"<example1@example.com>,<example2@example.com>", str)
}
if str := makeAddrString(emails); str != "<example1@example.com>,<example2@example.com>,<example3@example.com>,\r\n<example4@example.com>" {
t.Errorf("Invalid adress string, expect %s, got %s",
"<example1@example.com>,<example2@example.com>,<example3@example.com>,\r\n<example4@example.com>", str)
}
}
func TestSplitHeader(t *testing.T) {
str := ""
if s := splitHeader(str); s != "" {
t.Error("Trying to split an empty header")
}
if s := splitHeader("=?UTF-8?B?SGVsbG8gd29ybGQ=?="); s != "=?UTF-8?B?SGVsbG8gd29ybGQ=?=" {
t.Errorf("Invalid split result, expect %s, got %s", "=?UTF-8?B?SGVsbG8gd29ybGQ=?=", s)
}
expect := "=?UTF-8?B?U29tZSB2ZXJ5IGxvbmcgdGV4dCB3aXRob3V0IG1lYW5pbmc=?=\r\n=?UTF-8?B?U29tZSB2ZXJ5IGxvbmcgdGV4dCB3aXRob3V0IG1lYW5pbmc=?=\r\n=?UTF-8?B?U29tZSB2ZXJ5IGxvbmcgdGV4dCB3aXRob3V0IG1lYW5pbmc=?="
if s := splitHeader(subjectExample); s != expect {
t.Errorf("Invalid split result, expect %s, got %s", expect, s)
}
expect = "=?UTF-8?B?VmVyeSB2ZXJ5IHZlcnkgdmVyeSB2ZXJ5IHZlcnkgdmVyeSB2ZXJ5IHZlcnkgdmVyeS\r\nB2ZXJ5IGxvbmcgc3RyaW5n?="
if s := splitHeader("=?UTF-8?B?VmVyeSB2ZXJ5IHZlcnkgdmVyeSB2ZXJ5IHZlcnkgdmVyeSB2ZXJ5IHZlcnkgdmVyeSB2ZXJ5IGxvbmcgc3RyaW5n?="); s != expect {
t.Errorf("Invalid split result, expect %s, got %s", expect, s)
}
}
func TestSplit(t *testing.T) {
s := "VmVyeSB2ZXJ5IHZlcnkgdmVyeSB2ZXJ5IHZlcnkgdmVyeSB2ZXJ5IHZlcnkgdmVyeSB2ZXJ5IGxvbmcgc3RyaW5n"
str := split(s)
expect := "VmVyeSB2ZXJ5IHZlcnkgdmVyeSB2ZXJ5IHZlcnkgdmVyeSB2ZXJ5IHZlcnkgdmVyeSB2ZXJ5IGxv\r\nbmcgc3RyaW5n"
if s := strings.Join(str, "\r\n"); s != expect {
t.Errorf("Invalid split result, expect %s, got %s", expect, s)
}
}