forked from mozilla-services/heka
-
Notifications
You must be signed in to change notification settings - Fork 0
/
encoding_utils_test.go
78 lines (71 loc) · 2.4 KB
/
encoding_utils_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
/***** BEGIN LICENSE BLOCK *****
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at https://mozilla.org/MPL/2.0/.
#
# The Initial Developer of the Original Code is the Mozilla Foundation.
# Portions created by the Initial Developer are Copyright (C) 2015
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Kun Liu ([email protected])
#
# ***** END LICENSE BLOCK *****/
package smtp
import (
gs "github.com/rafrombrc/gospec/src/gospec"
)
func EncoderSpec(c gs.Context) {
c.Specify("Base64 Encoding", func() {
c.Specify("limit output length", func() {
str, num := encodeBase64LimitChars("Hello", 7)
c.Expect(num, gs.Equals, 3)
c.Expect(str, gs.Equals, "SGVs")
})
c.Specify("source within limit", func() {
str, num := encodeBase64LimitChars("Hello", 80)
c.Expect(num, gs.Equals, 5)
c.Expect(str, gs.Equals, "SGVsbG8=")
})
c.Specify("utf-8 skip half rune", func() {
str, num := encodeBase64LimitChars("o测试", 8)
c.Expect(num, gs.Equals, 4)
c.Expect(str, gs.Equals, "b+a1iw==")
})
})
c.Specify("Quoted-printable Encoding", func() {
c.Specify("limit output length", func() {
str, num := encodeQuoPriLimitChars("Hello world", 7)
c.Expect(num, gs.Equals, 7)
c.Expect(str, gs.Equals, "Hello_w")
})
c.Specify("source within limit", func() {
str, num := encodeQuoPriLimitChars("Hello\r\n=?=_.", 80)
c.Expect(num, gs.Equals, 12)
c.Expect(str, gs.Equals, "Hello=0A=3D=3F=3D=5F=2E.")
})
c.Specify("utf-8 skip half rune", func() {
str, num := encodeQuoPriLimitChars("o测试", 12)
c.Expect(num, gs.Equals, 4)
c.Expect(str, gs.Equals, "o=E8=AF=95")
})
})
c.Specify("Subject Encoding", func() {
c.Specify("subject 1", func() {
str := encodeSubject("The ï, ö, ë, ä, and é work, \n" +
"but when adding the ü it doesn't.")
c.Expect(str, gs.Equals, "Subject: =?utf-8?B?VGhlIMOvLCDD"+
"tiwgw6ssIMOkLCBhbmQgw6kgd29yaywgCmJ1dCB3aGVu?=\r\n"+
" =?utf-8?Q?_adding_the_=20=69_it_doesn't.?=")
})
c.Specify("subject 2", func() {
str := encodeSubject("Hello world!")
c.Expect(str, gs.Equals, "Subject: Hello world!")
})
c.Specify("subject 3", func() {
str := encodeSubject("从前有座山,山里有座庙")
c.Expect(str, gs.Equals, "Subject: =?utf-8?B?"+
"5LuO5YmN5pyJ5bqn5bGx77yM5bGx6YeM5pyJ5bqn5bqZ?=")
})
})
}