forked from wneessen/go-mail
-
Notifications
You must be signed in to change notification settings - Fork 0
/
encoding_test.go
123 lines (118 loc) · 3.93 KB
/
encoding_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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// SPDX-FileCopyrightText: 2022-2023 The go-mail Authors
//
// SPDX-License-Identifier: MIT
package mail
import "testing"
// TestEncoding_String tests the string method of the Encoding object
func TestEncoding_String(t *testing.T) {
tests := []struct {
name string
e Encoding
want string
}{
{"Encoding: Base64", EncodingB64, "base64"},
{"Encoding: QP", EncodingQP, "quoted-printable"},
{"Encoding: None/8bit", NoEncoding, "8bit"},
{"Encoding: US-ASCII/7bit", EncodingUSASCII, "7bit"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if tt.e.String() != tt.want {
t.Errorf("wrong string for Encoding returned. Expected: %s, got: %s",
tt.want, tt.e.String())
}
})
}
}
// TestContentType_String tests the string method of the ContentType object
func TestContentType_String(t *testing.T) {
tests := []struct {
name string
ct ContentType
want string
}{
{"ContentType: text/plain", TypeTextPlain, "text/plain"},
{"ContentType: text/html", TypeTextHTML, "text/html"},
{
"ContentType: application/octet-stream", TypeAppOctetStream,
"application/octet-stream",
},
{
"ContentType: multipart/alternative", TypeMultipartAlternative,
"multipart/alternative",
},
{
"ContentType: multipart/mixed", TypeMultipartMixed,
"multipart/mixed",
},
{
"ContentType: multipart/related", TypeMultipartRelated,
"multipart/related",
},
{
"ContentType: application/pgp-signature", TypePGPSignature,
"application/pgp-signature",
},
{
"ContentType: application/pgp-encrypted", TypePGPEncrypted,
"application/pgp-encrypted",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if tt.ct.String() != tt.want {
t.Errorf("wrong string for Content-Type returned. Expected: %s, got: %s",
tt.want, tt.ct.String())
}
})
}
}
// TestCharset_String tests the string method of the Charset object
func TestCharset_String(t *testing.T) {
tests := []struct {
name string
c Charset
want string
}{
{"Charset: US-ASCII", CharsetASCII, "US-ASCII"},
{"Charset: UTF-7", CharsetUTF7, "UTF-7"},
{"Charset: UTF-8", CharsetUTF8, "UTF-8"},
{"Charset: ISO-8859-1", CharsetISO88591, "ISO-8859-1"},
{"Charset: ISO-8859-2", CharsetISO88592, "ISO-8859-2"},
{"Charset: ISO-8859-3", CharsetISO88593, "ISO-8859-3"},
{"Charset: ISO-8859-4", CharsetISO88594, "ISO-8859-4"},
{"Charset: ISO-8859-5", CharsetISO88595, "ISO-8859-5"},
{"Charset: ISO-8859-6", CharsetISO88596, "ISO-8859-6"},
{"Charset: ISO-8859-7", CharsetISO88597, "ISO-8859-7"},
{"Charset: ISO-8859-9", CharsetISO88599, "ISO-8859-9"},
{"Charset: ISO-8859-13", CharsetISO885913, "ISO-8859-13"},
{"Charset: ISO-8859-14", CharsetISO885914, "ISO-8859-14"},
{"Charset: ISO-8859-15", CharsetISO885915, "ISO-8859-15"},
{"Charset: ISO-8859-16", CharsetISO885916, "ISO-8859-16"},
{"Charset: ISO-2022-JP", CharsetISO2022JP, "ISO-2022-JP"},
{"Charset: ISO-2022-KR", CharsetISO2022KR, "ISO-2022-KR"},
{"Charset: windows-1250", CharsetWindows1250, "windows-1250"},
{"Charset: windows-1251", CharsetWindows1251, "windows-1251"},
{"Charset: windows-1252", CharsetWindows1252, "windows-1252"},
{"Charset: windows-1255", CharsetWindows1255, "windows-1255"},
{"Charset: windows-1256", CharsetWindows1256, "windows-1256"},
{"Charset: KOI8-R", CharsetKOI8R, "KOI8-R"},
{"Charset: KOI8-U", CharsetKOI8U, "KOI8-U"},
{"Charset: Big5", CharsetBig5, "Big5"},
{"Charset: GB18030", CharsetGB18030, "GB18030"},
{"Charset: GB2312", CharsetGB2312, "GB2312"},
{"Charset: GBK", CharsetGBK, "GBK"},
{"Charset: TIS-620", CharsetTIS620, "TIS-620"},
{"Charset: EUC-KR", CharsetEUCKR, "EUC-KR"},
{"Charset: Shift_JIS", CharsetShiftJIS, "Shift_JIS"},
{"Charset: Unknown", CharsetUnknown, "Unknown"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if tt.c.String() != tt.want {
t.Errorf("wrong string for Charset returned. Expected: %s, got: %s",
tt.want, tt.c.String())
}
})
}
}