source: trip-planner-front/node_modules/jsonparse/test/primitives.js@ 6fe77af

Last change on this file since 6fe77af was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.2 KB
Line 
1var test = require('tape');
2var Parser = require('../');
3
4var expected = [
5 [ [], '' ],
6 [ [], 'Hello' ],
7 [ [], 'This"is' ],
8 [ [], '\r\n\f\t\\/"' ],
9 [ [], 'Λάμβδα' ],
10 [ [], '\\' ],
11 [ [], '/' ],
12 [ [], '"' ],
13 [ [ 0 ], 0 ],
14 [ [ 1 ], 1 ],
15 [ [ 2 ], -1 ],
16 [ [], [ 0, 1, -1 ] ],
17 [ [ 0 ], 1 ],
18 [ [ 1 ], 1.1 ],
19 [ [ 2 ], -1.1 ],
20 [ [ 3 ], -1 ],
21 [ [], [ 1, 1.1, -1.1, -1 ] ],
22 [ [ 0 ], -1 ],
23 [ [], [ -1 ] ],
24 [ [ 0 ], -0.1 ],
25 [ [], [ -0.1 ] ],
26 [ [ 0 ], 6.02e+23 ],
27 [ [], [ 6.02e+23 ] ],
28 [ [ 0 ], '7161093205057351174' ],
29 [ [], [ '7161093205057351174'] ]
30];
31
32test('primitives', function (t) {
33 t.plan(25);
34
35 var p = new Parser();
36 p.onValue = function (value) {
37 var keys = this.stack
38 .slice(1)
39 .map(function (item) { return item.key })
40 .concat(this.key !== undefined ? this.key : [])
41 ;
42 t.deepEqual(
43 [ keys, value ],
44 expected.shift()
45 );
46 };
47
48 p.write('"""Hello""This\\"is""\\r\\n\\f\\t\\\\\\/\\""');
49 p.write('"\\u039b\\u03ac\\u03bc\\u03b2\\u03b4\\u03b1"');
50 p.write('"\\\\"');
51 p.write('"\\/"');
52 p.write('"\\""');
53 p.write('[0,1,-1]');
54 p.write('[1.0,1.1,-1.1,-1.0][-1][-0.1]');
55 p.write('[6.02e23]');
56 p.write('[7161093205057351174]');
57});
Note: See TracBrowser for help on using the repository browser.