1 | var parseExpr = require('../lib/Parser').parseExpr;
|
2 |
|
3 | var assert = require('assert'),
|
4 | inspect = require('util').inspect;
|
5 |
|
6 | [
|
7 | { source: '',
|
8 | expected: [],
|
9 | what: 'Empty value'
|
10 | },
|
11 | { source: 'FLAGS NIL RFC822.SIZE 44827',
|
12 | expected: ['FLAGS', null, 'RFC822.SIZE', 44827],
|
13 | what: 'Simple, two key-value pairs with nil'
|
14 | },
|
15 | { source: 'FLAGS (\\Seen) RFC822.SIZE 44827',
|
16 | expected: ['FLAGS', ['\\Seen'], 'RFC822.SIZE', 44827],
|
17 | what: 'Simple, two key-value pairs with list'
|
18 | },
|
19 | { source: 'RFC822.SIZE 9007199254740993',
|
20 | expected: ['RFC822.SIZE', '9007199254740993'],
|
21 | what: 'Integer exceeding JavaScript max int size'
|
22 | },
|
23 | { source: 'FLAGS (\\Seen) INTERNALDATE "17-Jul-1996 02:44:25 -0700"',
|
24 | expected: ['FLAGS', ['\\Seen'], 'INTERNALDATE', '17-Jul-1996 02:44:25 -0700'],
|
25 | what: 'Quoted string'
|
26 | },
|
27 | { source: '("Foo")("Bar") ("Baz")',
|
28 | expected: [['Foo'], ['Bar'], ['Baz']],
|
29 | what: 'Lists with varying spacing'
|
30 | },
|
31 | { source: '""',
|
32 | expected: [''],
|
33 | what: 'Empty quoted string'
|
34 | },
|
35 | ].forEach(function(v) {
|
36 | var result;
|
37 |
|
38 | try {
|
39 | result = parseExpr(v.source);
|
40 | } catch (e) {
|
41 | console.log(makeMsg(v.what, 'JS Exception: ' + e.stack));
|
42 | return;
|
43 | }
|
44 |
|
45 | assert.deepEqual(result,
|
46 | v.expected,
|
47 | makeMsg(v.what,
|
48 | 'Result mismatch:'
|
49 | + '\nParsed: ' + inspect(result, false, 10)
|
50 | + '\nExpected: ' + inspect(v.expected, false, 10)
|
51 | )
|
52 | );
|
53 | });
|
54 |
|
55 | function makeMsg(what, msg) {
|
56 | return '[' + what + ']: ' + msg;
|
57 | } |
\ | No newline at end of file |