UNPKG

2.36 kBJavaScriptView Raw
1var parseBodyStructure = require('../lib/Parser').parseBodyStructure;
2
3var assert = require('assert'),
4 inspect = require('util').inspect;
5
6[
7 { source: '("TEXT" "PLAIN" ("CHARSET" "US-ASCII") NIL NIL "7BIT" 1152 23)'
8 + '("TEXT" "PLAIN" ("CHARSET" "US-ASCII" "NAME" "cc.diff")'
9 + ' "<960723163407.20117h@cac.washington.edu>" "Compiler diff"'
10 + ' "BASE64" 4554 73)'
11 + '"MIXED"',
12 expected: [ { type: 'mixed' },
13 [ { partID: '1',
14 type: 'text',
15 subtype: 'plain',
16 params: { charset: 'US-ASCII' },
17 id: null,
18 description: null,
19 encoding: '7BIT',
20 size: 1152,
21 lines: 23
22 }
23 ],
24 [ { partID: '2',
25 type: 'text',
26 subtype: 'plain',
27 params: { charset: 'US-ASCII', name: 'cc.diff' },
28 id: '<960723163407.20117h@cac.washington.edu>',
29 description: 'Compiler diff',
30 encoding: 'BASE64',
31 size: 4554,
32 lines: 73
33 }
34 ]
35 ],
36 what: 'RFC3501 example #1'
37 },
38 { source: '"TEXT" "PLAIN" ("CHARSET" "US-ASCII") NIL NIL "7BIT" 3028 92',
39 expected: [ { partID: '1',
40 type: 'text',
41 subtype: 'plain',
42 params: { charset: 'US-ASCII' },
43 id: null,
44 description: null,
45 encoding: '7BIT',
46 size: 3028,
47 lines: 92
48 }
49 ],
50 what: 'RFC3501 example #2'
51 },
52].forEach(function(v) {
53 var result;
54 try {
55 result = parseBodyStructure(v.source);
56 } catch (e) {
57 console.log(makeMsg(v.what, 'JS Exception: ' + e.stack));
58 return;
59 }
60 assert.deepEqual(result,
61 v.expected,
62 makeMsg(v.what,
63 'Result mismatch:'
64 + '\nParsed: ' + inspect(result, false, 10)
65 + '\nExpected: ' + inspect(v.expected, false, 10)
66 )
67 );
68});
69
70function makeMsg(what, msg) {
71 return '[' + what + ']: ' + msg;
72}
\No newline at end of file