UNPKG

3.26 kBJavaScriptView Raw
1var parseExpr = require('../lib/Parser').parseExpr,
2 parseEnvelopeAddresses = require('../lib/Parser').parseEnvelopeAddresses;
3
4var assert = require('assert'),
5 inspect = require('util').inspect;
6
7[
8 { source: '("Terry Gray" NIL "gray" "cac.washington.edu")',
9 expected: [ { name: 'Terry Gray',
10 mailbox: 'gray',
11 host: 'cac.washington.edu'
12 }
13 ],
14 what: 'RFC3501 example #1'
15 },
16 { source: '(NIL NIL "imap" "cac.washington.edu")',
17 expected: [ { name: null,
18 mailbox: 'imap',
19 host: 'cac.washington.edu'
20 }
21 ],
22 what: 'RFC3501 example #2'
23 },
24 { source: '(NIL NIL "imap" NIL)'
25 + '(NIL NIL NIL NIL)',
26 expected: [ { group: 'imap',
27 addresses: []
28 }
29 ],
30 what: 'Zero-length group'
31 },
32 { source: '(NIL NIL "imap" NIL)'
33 + '("Terry Gray" NIL "gray" "cac.washington.edu")'
34 + '(NIL NIL NIL NIL)',
35 expected: [ { group: 'imap',
36 addresses: [
37 { name: 'Terry Gray',
38 mailbox: 'gray',
39 host: 'cac.washington.edu'
40 }
41 ]
42 }
43 ],
44 what: 'One-length group'
45 },
46 { source: '(NIL NIL "imap" NIL)'
47 + '("Terry Gray" NIL "gray" "cac.washington.edu")'
48 + '(NIL NIL NIL NIL)'
49 + '(NIL NIL "imap" "cac.washington.edu")',
50 expected: [ { group: 'imap',
51 addresses: [
52 { name: 'Terry Gray',
53 mailbox: 'gray',
54 host: 'cac.washington.edu'
55 }
56 ]
57 },
58 { name: null,
59 mailbox: 'imap',
60 host: 'cac.washington.edu'
61 }
62 ],
63 what: 'One-length group and address'
64 },
65 { source: '(NIL NIL "imap" NIL)'
66 + '("Terry Gray" NIL "gray" "cac.washington.edu")',
67 expected: [ { group: 'imap',
68 addresses: [
69 { name: 'Terry Gray',
70 mailbox: 'gray',
71 host: 'cac.washington.edu'
72 }
73 ]
74 }
75 ],
76 what: 'Implicit group end'
77 },
78 { source: '("Terry Gray" NIL "gray" "cac.washington.edu")'
79 + '(NIL NIL NIL NIL)',
80 expected: [ { name: 'Terry Gray',
81 mailbox: 'gray',
82 host: 'cac.washington.edu'
83 }
84 ],
85 what: 'Group end without start'
86 },
87].forEach(function(v) {
88 var result;
89
90 try {
91 result = parseEnvelopeAddresses(parseExpr(v.source));
92 } catch (e) {
93 console.log(makeMsg(v.what, 'JS Exception: ' + e.stack));
94 return;
95 }
96
97 assert.deepEqual(result,
98 v.expected,
99 makeMsg(v.what,
100 'Result mismatch:'
101 + '\nParsed: ' + inspect(result, false, 10)
102 + '\nExpected: ' + inspect(v.expected, false, 10)
103 )
104 );
105});
106
107function makeMsg(what, msg) {
108 return '[' + what + ']: ' + msg;
109}
\No newline at end of file