source: trip-planner-front/node_modules/jsonparse/test/offset.js@ 8d391a1

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

initial commit

  • Property mode set to 100644
File size: 1.7 KB
Line 
1var test = require('tape');
2var Parser = require('../');
3
4var input = '{\n "string": "value",\n "number": 3,\n "object"';
5var input2 = ': {\n "key": "vд"\n },\n "array": [\n -1,\n 12\n ]\n ';
6var input3 = '"null": null, "true": true, "false": false, "frac": 3.14 }';
7
8var offsets = [
9 [ 0, Parser.C.LEFT_BRACE ],
10 [ 4, Parser.C.STRING ],
11 [ 12, Parser.C.COLON ],
12 [ 14, Parser.C.STRING ],
13 [ 21, Parser.C.COMMA ],
14 [ 25, Parser.C.STRING ],
15 [ 33, Parser.C.COLON ],
16 [ 35, Parser.C.NUMBER ],
17 [ 36, Parser.C.COMMA ],
18 [ 40, Parser.C.STRING ],
19 [ 48, Parser.C.COLON ],
20 [ 50, Parser.C.LEFT_BRACE ],
21 [ 54, Parser.C.STRING ],
22 [ 59, Parser.C.COLON ],
23 [ 61, Parser.C.STRING ],
24 [ 69, Parser.C.RIGHT_BRACE ],
25 [ 70, Parser.C.COMMA ],
26 [ 74, Parser.C.STRING ],
27 [ 81, Parser.C.COLON ],
28 [ 83, Parser.C.LEFT_BRACKET ],
29 [ 87, Parser.C.NUMBER ],
30 [ 89, Parser.C.COMMA ],
31 [ 93, Parser.C.NUMBER ],
32 [ 98, Parser.C.RIGHT_BRACKET ],
33 [ 102, Parser.C.STRING ],
34 [ 108, Parser.C.COLON ],
35 [ 110, Parser.C.NULL ],
36 [ 114, Parser.C.COMMA ],
37 [ 116, Parser.C.STRING ],
38 [ 122, Parser.C.COLON ],
39 [ 124, Parser.C.TRUE ],
40 [ 128, Parser.C.COMMA ],
41 [ 130, Parser.C.STRING ],
42 [ 137, Parser.C.COLON ],
43 [ 139, Parser.C.FALSE ],
44 [ 144, Parser.C.COMMA ],
45 [ 146, Parser.C.STRING ],
46 [ 152, Parser.C.COLON ],
47 [ 154, Parser.C.NUMBER ],
48 [ 159, Parser.C.RIGHT_BRACE ]
49];
50
51test('offset', function(t) {
52 t.plan(offsets.length * 2 + 1);
53
54 var p = new Parser();
55 var i = 0;
56 p.onToken = function (token) {
57 t.equal(p.offset, offsets[i][0]);
58 t.equal(token, offsets[i][1]);
59 i++;
60 };
61
62 p.write(input);
63 p.write(input2);
64 p.write(input3);
65
66 t.equal(i, offsets.length);
67});
Note: See TracBrowser for help on using the repository browser.