/
MailAddressTokenizerTest.class.st
83 lines (74 loc) · 2.17 KB
/
MailAddressTokenizerTest.class.st
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
Class {
#name : #MailAddressTokenizerTest,
#superclass : #TestCase,
#category : #'Network-Tests-Mail'
}
{ #category : #tests }
MailAddressTokenizerTest >> testTokensInAscii [
"Basic test that the tokenizer returns the correct values"
| tokens tokensCollection |
tokens := MailAddressTokenizer tokensIn: 'first last <person@company.com>'.
tokensCollection := tokens collect: [ :each |
each type -> each text ] as: Array.
self
assert: tokensCollection
equals: {#Atom->'first'. #Atom->'last'. $<->'<'. #Atom->'person'. $@->'@'. #Atom->'company'. $.->'.'. #Atom->'com'. $>->'>'}.
]
{ #category : #tests }
MailAddressTokenizerTest >> testTokensInLatin [
"RFC6531 (February 2012) allows character values > 127.
Check that the parser handles values between 128 and 255 (which can be correctly represented with single byte encoding)"
| email tokens tokensCollection |
email := 'first last <person@company.com>'.
email
at: 2 put: 237 asCharacter;
at: 14 put: 233 asCharacter.
tokens := MailAddressTokenizer tokensIn: email.
tokensCollection := tokens collect: [ :each |
each type -> each text ] as: Array.
self
assert: tokensCollection
equals: {
#Atom->('first'
at: 2 put: 237 asCharacter;
yourself).
#Atom->'last'.
$<->'<'.
#Atom->('person'
at: 2 put: 233 asCharacter;
yourself).
$@->'@'.
#Atom->'company'.
$.->'.'.
#Atom->'com'.
$>->'>'}.
]
{ #category : #tests }
MailAddressTokenizerTest >> testTokensInUnicode [
"RFC6531 (February 2012) allows character values > 127.
Check that the parser handles values greater than 255 (which require multi-byte encoding)"
| email tokens tokensCollection |
email := 'first last <person@company.com>'.
email
at: 3 put: 345 asCharacter;
at: 15 put: 345 asCharacter.
tokens := MailAddressTokenizer tokensIn: email.
tokensCollection := tokens collect: [ :each |
each type -> each text ] as: Array.
self
assert: tokensCollection
equals: {
#Atom->('first'
at: 3 put: 345 asCharacter;
yourself).
#Atom->'last'.
$<->'<'.
#Atom->('person'
at: 3 put: 345 asCharacter;
yourself).
$@->'@'.
#Atom->'company'.
$.->'.'.
#Atom->'com'.
$>->'>'}.
]