cborg 1.6.1 → 1.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/browser-test/node-test-bin.js +58 -0
- package/cjs/lib/diagnostic.js +8 -13
- package/cjs/node-test/node-test-bin.js +58 -0
- package/esm/browser-test/node-test-bin.js +58 -0
- package/esm/lib/diagnostic.js +8 -13
- package/esm/node-test/node-test-bin.js +58 -0
- package/lib/diagnostic.js +8 -13
- package/package.json +1 -1
- package/test/node-test-bin.js +61 -0
- package/types/lib/diagnostic.d.ts.map +1 -1
|
@@ -219,4 +219,62 @@ Input may either be supplied as an argument or piped via stdin
|
|
|
219
219
|
assert.strictEqual(stderr, '');
|
|
220
220
|
assert.strictEqual(stdout, 'a3616101616282020365736d696c6564f09f9880\n');
|
|
221
221
|
});
|
|
222
|
+
it('diag indenting', async () => {
|
|
223
|
+
const {stdout, stderr} = await execBin('json2diag', '{"a":[],"b":{},"c":{"a":1,"b":{"a":{"a":{}}}},"d":{"a":{"a":{"a":1},"b":2,"c":[]}},"e":[[[[{"a":{}}]]]],"f":1}');
|
|
224
|
+
assert.strictEqual(stderr, '');
|
|
225
|
+
assert.strictEqual(stdout, `a6 # map(6)
|
|
226
|
+
61 # string(1)
|
|
227
|
+
61 # "a"
|
|
228
|
+
80 # array(0)
|
|
229
|
+
61 # string(1)
|
|
230
|
+
62 # "b"
|
|
231
|
+
a0 # map(0)
|
|
232
|
+
61 # string(1)
|
|
233
|
+
63 # "c"
|
|
234
|
+
a2 # map(2)
|
|
235
|
+
61 # string(1)
|
|
236
|
+
61 # "a"
|
|
237
|
+
01 # uint(1)
|
|
238
|
+
61 # string(1)
|
|
239
|
+
62 # "b"
|
|
240
|
+
a1 # map(1)
|
|
241
|
+
61 # string(1)
|
|
242
|
+
61 # "a"
|
|
243
|
+
a1 # map(1)
|
|
244
|
+
61 # string(1)
|
|
245
|
+
61 # "a"
|
|
246
|
+
a0 # map(0)
|
|
247
|
+
61 # string(1)
|
|
248
|
+
64 # "d"
|
|
249
|
+
a1 # map(1)
|
|
250
|
+
61 # string(1)
|
|
251
|
+
61 # "a"
|
|
252
|
+
a3 # map(3)
|
|
253
|
+
61 # string(1)
|
|
254
|
+
61 # "a"
|
|
255
|
+
a1 # map(1)
|
|
256
|
+
61 # string(1)
|
|
257
|
+
61 # "a"
|
|
258
|
+
01 # uint(1)
|
|
259
|
+
61 # string(1)
|
|
260
|
+
62 # "b"
|
|
261
|
+
02 # uint(2)
|
|
262
|
+
61 # string(1)
|
|
263
|
+
63 # "c"
|
|
264
|
+
80 # array(0)
|
|
265
|
+
61 # string(1)
|
|
266
|
+
65 # "e"
|
|
267
|
+
81 # array(1)
|
|
268
|
+
81 # array(1)
|
|
269
|
+
81 # array(1)
|
|
270
|
+
81 # array(1)
|
|
271
|
+
a1 # map(1)
|
|
272
|
+
61 # string(1)
|
|
273
|
+
61 # "a"
|
|
274
|
+
a0 # map(0)
|
|
275
|
+
61 # string(1)
|
|
276
|
+
66 # "f"
|
|
277
|
+
01 # uint(1)
|
|
278
|
+
`);
|
|
279
|
+
});
|
|
222
280
|
});
|
package/cjs/lib/diagnostic.js
CHANGED
|
@@ -49,17 +49,16 @@ function* tokensToDiagnostic(inp, width = 100) {
|
|
|
49
49
|
yield `${ margin }${ byteUtils.toHex(piece) }`.padEnd(width / 2, ' ') + `# ${ margin }"${ st }"`;
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
|
+
if (indent.length) {
|
|
53
|
+
indent[indent.length - 1]--;
|
|
54
|
+
}
|
|
52
55
|
if (!token.type.terminal) {
|
|
53
56
|
switch (token.type.name) {
|
|
54
57
|
case 'map':
|
|
55
|
-
|
|
56
|
-
indent.push(token.value * 2);
|
|
57
|
-
}
|
|
58
|
+
indent.push(token.value * 2);
|
|
58
59
|
break;
|
|
59
60
|
case 'array':
|
|
60
|
-
|
|
61
|
-
indent.push(token.value);
|
|
62
|
-
}
|
|
61
|
+
indent.push(token.value);
|
|
63
62
|
break;
|
|
64
63
|
case 'tag':
|
|
65
64
|
indent.push(1);
|
|
@@ -67,13 +66,9 @@ function* tokensToDiagnostic(inp, width = 100) {
|
|
|
67
66
|
default:
|
|
68
67
|
throw new Error(`Unknown token type '${ token.type.name }'`);
|
|
69
68
|
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
if (indent[indent.length - 1] === 0) {
|
|
74
|
-
indent.pop();
|
|
75
|
-
}
|
|
76
|
-
}
|
|
69
|
+
}
|
|
70
|
+
while (indent.length && indent[indent.length - 1] <= 0) {
|
|
71
|
+
indent.pop();
|
|
77
72
|
}
|
|
78
73
|
pos += token.encodedLength;
|
|
79
74
|
}
|
|
@@ -219,4 +219,62 @@ Input may either be supplied as an argument or piped via stdin
|
|
|
219
219
|
assert.strictEqual(stderr, '');
|
|
220
220
|
assert.strictEqual(stdout, 'a3616101616282020365736d696c6564f09f9880\n');
|
|
221
221
|
});
|
|
222
|
+
it('diag indenting', async () => {
|
|
223
|
+
const {stdout, stderr} = await execBin('json2diag', '{"a":[],"b":{},"c":{"a":1,"b":{"a":{"a":{}}}},"d":{"a":{"a":{"a":1},"b":2,"c":[]}},"e":[[[[{"a":{}}]]]],"f":1}');
|
|
224
|
+
assert.strictEqual(stderr, '');
|
|
225
|
+
assert.strictEqual(stdout, `a6 # map(6)
|
|
226
|
+
61 # string(1)
|
|
227
|
+
61 # "a"
|
|
228
|
+
80 # array(0)
|
|
229
|
+
61 # string(1)
|
|
230
|
+
62 # "b"
|
|
231
|
+
a0 # map(0)
|
|
232
|
+
61 # string(1)
|
|
233
|
+
63 # "c"
|
|
234
|
+
a2 # map(2)
|
|
235
|
+
61 # string(1)
|
|
236
|
+
61 # "a"
|
|
237
|
+
01 # uint(1)
|
|
238
|
+
61 # string(1)
|
|
239
|
+
62 # "b"
|
|
240
|
+
a1 # map(1)
|
|
241
|
+
61 # string(1)
|
|
242
|
+
61 # "a"
|
|
243
|
+
a1 # map(1)
|
|
244
|
+
61 # string(1)
|
|
245
|
+
61 # "a"
|
|
246
|
+
a0 # map(0)
|
|
247
|
+
61 # string(1)
|
|
248
|
+
64 # "d"
|
|
249
|
+
a1 # map(1)
|
|
250
|
+
61 # string(1)
|
|
251
|
+
61 # "a"
|
|
252
|
+
a3 # map(3)
|
|
253
|
+
61 # string(1)
|
|
254
|
+
61 # "a"
|
|
255
|
+
a1 # map(1)
|
|
256
|
+
61 # string(1)
|
|
257
|
+
61 # "a"
|
|
258
|
+
01 # uint(1)
|
|
259
|
+
61 # string(1)
|
|
260
|
+
62 # "b"
|
|
261
|
+
02 # uint(2)
|
|
262
|
+
61 # string(1)
|
|
263
|
+
63 # "c"
|
|
264
|
+
80 # array(0)
|
|
265
|
+
61 # string(1)
|
|
266
|
+
65 # "e"
|
|
267
|
+
81 # array(1)
|
|
268
|
+
81 # array(1)
|
|
269
|
+
81 # array(1)
|
|
270
|
+
81 # array(1)
|
|
271
|
+
a1 # map(1)
|
|
272
|
+
61 # string(1)
|
|
273
|
+
61 # "a"
|
|
274
|
+
a0 # map(0)
|
|
275
|
+
61 # string(1)
|
|
276
|
+
66 # "f"
|
|
277
|
+
01 # uint(1)
|
|
278
|
+
`);
|
|
279
|
+
});
|
|
222
280
|
});
|
|
@@ -210,4 +210,62 @@ Input may either be supplied as an argument or piped via stdin
|
|
|
210
210
|
assert.strictEqual(stderr, '');
|
|
211
211
|
assert.strictEqual(stdout, 'a3616101616282020365736d696c6564f09f9880\n');
|
|
212
212
|
});
|
|
213
|
+
it('diag indenting', async () => {
|
|
214
|
+
const {stdout, stderr} = await execBin('json2diag', '{"a":[],"b":{},"c":{"a":1,"b":{"a":{"a":{}}}},"d":{"a":{"a":{"a":1},"b":2,"c":[]}},"e":[[[[{"a":{}}]]]],"f":1}');
|
|
215
|
+
assert.strictEqual(stderr, '');
|
|
216
|
+
assert.strictEqual(stdout, `a6 # map(6)
|
|
217
|
+
61 # string(1)
|
|
218
|
+
61 # "a"
|
|
219
|
+
80 # array(0)
|
|
220
|
+
61 # string(1)
|
|
221
|
+
62 # "b"
|
|
222
|
+
a0 # map(0)
|
|
223
|
+
61 # string(1)
|
|
224
|
+
63 # "c"
|
|
225
|
+
a2 # map(2)
|
|
226
|
+
61 # string(1)
|
|
227
|
+
61 # "a"
|
|
228
|
+
01 # uint(1)
|
|
229
|
+
61 # string(1)
|
|
230
|
+
62 # "b"
|
|
231
|
+
a1 # map(1)
|
|
232
|
+
61 # string(1)
|
|
233
|
+
61 # "a"
|
|
234
|
+
a1 # map(1)
|
|
235
|
+
61 # string(1)
|
|
236
|
+
61 # "a"
|
|
237
|
+
a0 # map(0)
|
|
238
|
+
61 # string(1)
|
|
239
|
+
64 # "d"
|
|
240
|
+
a1 # map(1)
|
|
241
|
+
61 # string(1)
|
|
242
|
+
61 # "a"
|
|
243
|
+
a3 # map(3)
|
|
244
|
+
61 # string(1)
|
|
245
|
+
61 # "a"
|
|
246
|
+
a1 # map(1)
|
|
247
|
+
61 # string(1)
|
|
248
|
+
61 # "a"
|
|
249
|
+
01 # uint(1)
|
|
250
|
+
61 # string(1)
|
|
251
|
+
62 # "b"
|
|
252
|
+
02 # uint(2)
|
|
253
|
+
61 # string(1)
|
|
254
|
+
63 # "c"
|
|
255
|
+
80 # array(0)
|
|
256
|
+
61 # string(1)
|
|
257
|
+
65 # "e"
|
|
258
|
+
81 # array(1)
|
|
259
|
+
81 # array(1)
|
|
260
|
+
81 # array(1)
|
|
261
|
+
81 # array(1)
|
|
262
|
+
a1 # map(1)
|
|
263
|
+
61 # string(1)
|
|
264
|
+
61 # "a"
|
|
265
|
+
a0 # map(0)
|
|
266
|
+
61 # string(1)
|
|
267
|
+
66 # "f"
|
|
268
|
+
01 # uint(1)
|
|
269
|
+
`);
|
|
270
|
+
});
|
|
213
271
|
});
|
package/esm/lib/diagnostic.js
CHANGED
|
@@ -44,17 +44,16 @@ function* tokensToDiagnostic(inp, width = 100) {
|
|
|
44
44
|
yield `${ margin }${ toHex(piece) }`.padEnd(width / 2, ' ') + `# ${ margin }"${ st }"`;
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
+
if (indent.length) {
|
|
48
|
+
indent[indent.length - 1]--;
|
|
49
|
+
}
|
|
47
50
|
if (!token.type.terminal) {
|
|
48
51
|
switch (token.type.name) {
|
|
49
52
|
case 'map':
|
|
50
|
-
|
|
51
|
-
indent.push(token.value * 2);
|
|
52
|
-
}
|
|
53
|
+
indent.push(token.value * 2);
|
|
53
54
|
break;
|
|
54
55
|
case 'array':
|
|
55
|
-
|
|
56
|
-
indent.push(token.value);
|
|
57
|
-
}
|
|
56
|
+
indent.push(token.value);
|
|
58
57
|
break;
|
|
59
58
|
case 'tag':
|
|
60
59
|
indent.push(1);
|
|
@@ -62,13 +61,9 @@ function* tokensToDiagnostic(inp, width = 100) {
|
|
|
62
61
|
default:
|
|
63
62
|
throw new Error(`Unknown token type '${ token.type.name }'`);
|
|
64
63
|
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
if (indent[indent.length - 1] === 0) {
|
|
69
|
-
indent.pop();
|
|
70
|
-
}
|
|
71
|
-
}
|
|
64
|
+
}
|
|
65
|
+
while (indent.length && indent[indent.length - 1] <= 0) {
|
|
66
|
+
indent.pop();
|
|
72
67
|
}
|
|
73
68
|
pos += token.encodedLength;
|
|
74
69
|
}
|
|
@@ -210,4 +210,62 @@ Input may either be supplied as an argument or piped via stdin
|
|
|
210
210
|
assert.strictEqual(stderr, '');
|
|
211
211
|
assert.strictEqual(stdout, 'a3616101616282020365736d696c6564f09f9880\n');
|
|
212
212
|
});
|
|
213
|
+
it('diag indenting', async () => {
|
|
214
|
+
const {stdout, stderr} = await execBin('json2diag', '{"a":[],"b":{},"c":{"a":1,"b":{"a":{"a":{}}}},"d":{"a":{"a":{"a":1},"b":2,"c":[]}},"e":[[[[{"a":{}}]]]],"f":1}');
|
|
215
|
+
assert.strictEqual(stderr, '');
|
|
216
|
+
assert.strictEqual(stdout, `a6 # map(6)
|
|
217
|
+
61 # string(1)
|
|
218
|
+
61 # "a"
|
|
219
|
+
80 # array(0)
|
|
220
|
+
61 # string(1)
|
|
221
|
+
62 # "b"
|
|
222
|
+
a0 # map(0)
|
|
223
|
+
61 # string(1)
|
|
224
|
+
63 # "c"
|
|
225
|
+
a2 # map(2)
|
|
226
|
+
61 # string(1)
|
|
227
|
+
61 # "a"
|
|
228
|
+
01 # uint(1)
|
|
229
|
+
61 # string(1)
|
|
230
|
+
62 # "b"
|
|
231
|
+
a1 # map(1)
|
|
232
|
+
61 # string(1)
|
|
233
|
+
61 # "a"
|
|
234
|
+
a1 # map(1)
|
|
235
|
+
61 # string(1)
|
|
236
|
+
61 # "a"
|
|
237
|
+
a0 # map(0)
|
|
238
|
+
61 # string(1)
|
|
239
|
+
64 # "d"
|
|
240
|
+
a1 # map(1)
|
|
241
|
+
61 # string(1)
|
|
242
|
+
61 # "a"
|
|
243
|
+
a3 # map(3)
|
|
244
|
+
61 # string(1)
|
|
245
|
+
61 # "a"
|
|
246
|
+
a1 # map(1)
|
|
247
|
+
61 # string(1)
|
|
248
|
+
61 # "a"
|
|
249
|
+
01 # uint(1)
|
|
250
|
+
61 # string(1)
|
|
251
|
+
62 # "b"
|
|
252
|
+
02 # uint(2)
|
|
253
|
+
61 # string(1)
|
|
254
|
+
63 # "c"
|
|
255
|
+
80 # array(0)
|
|
256
|
+
61 # string(1)
|
|
257
|
+
65 # "e"
|
|
258
|
+
81 # array(1)
|
|
259
|
+
81 # array(1)
|
|
260
|
+
81 # array(1)
|
|
261
|
+
81 # array(1)
|
|
262
|
+
a1 # map(1)
|
|
263
|
+
61 # string(1)
|
|
264
|
+
61 # "a"
|
|
265
|
+
a0 # map(0)
|
|
266
|
+
61 # string(1)
|
|
267
|
+
66 # "f"
|
|
268
|
+
01 # uint(1)
|
|
269
|
+
`);
|
|
270
|
+
});
|
|
213
271
|
});
|
package/lib/diagnostic.js
CHANGED
|
@@ -67,17 +67,16 @@ function * tokensToDiagnostic (inp, width = 100) {
|
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
+
if (indent.length) {
|
|
71
|
+
indent[indent.length - 1]--
|
|
72
|
+
}
|
|
70
73
|
if (!token.type.terminal) {
|
|
71
74
|
switch (token.type.name) {
|
|
72
75
|
case 'map':
|
|
73
|
-
|
|
74
|
-
indent.push(token.value * 2)
|
|
75
|
-
}
|
|
76
|
+
indent.push(token.value * 2)
|
|
76
77
|
break
|
|
77
78
|
case 'array':
|
|
78
|
-
|
|
79
|
-
indent.push(token.value)
|
|
80
|
-
}
|
|
79
|
+
indent.push(token.value)
|
|
81
80
|
break
|
|
82
81
|
// TODO: test tags .. somehow
|
|
83
82
|
/* c8 ignore next 5 */
|
|
@@ -87,13 +86,9 @@ function * tokensToDiagnostic (inp, width = 100) {
|
|
|
87
86
|
default:
|
|
88
87
|
throw new Error(`Unknown token type '${token.type.name}'`)
|
|
89
88
|
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
if (indent[indent.length - 1] === 0) {
|
|
94
|
-
indent.pop()
|
|
95
|
-
}
|
|
96
|
-
}
|
|
89
|
+
}
|
|
90
|
+
while (indent.length && indent[indent.length - 1] <= 0) {
|
|
91
|
+
indent.pop()
|
|
97
92
|
}
|
|
98
93
|
// @ts-ignore it should be set on a decode operation
|
|
99
94
|
pos += token.encodedLength
|
package/package.json
CHANGED
package/test/node-test-bin.js
CHANGED
|
@@ -250,4 +250,65 @@ Input may either be supplied as an argument or piped via stdin
|
|
|
250
250
|
assert.strictEqual(stderr, '')
|
|
251
251
|
assert.strictEqual(stdout, 'a3616101616282020365736d696c6564f09f9880\n')
|
|
252
252
|
})
|
|
253
|
+
|
|
254
|
+
// complicated nesting to test indenting algorithm
|
|
255
|
+
it('diag indenting', async () => {
|
|
256
|
+
const { stdout, stderr } = await execBin('json2diag', '{"a":[],"b":{},"c":{"a":1,"b":{"a":{"a":{}}}},"d":{"a":{"a":{"a":1},"b":2,"c":[]}},"e":[[[[{"a":{}}]]]],"f":1}')
|
|
257
|
+
assert.strictEqual(stderr, '')
|
|
258
|
+
assert.strictEqual(stdout,
|
|
259
|
+
`a6 # map(6)
|
|
260
|
+
61 # string(1)
|
|
261
|
+
61 # "a"
|
|
262
|
+
80 # array(0)
|
|
263
|
+
61 # string(1)
|
|
264
|
+
62 # "b"
|
|
265
|
+
a0 # map(0)
|
|
266
|
+
61 # string(1)
|
|
267
|
+
63 # "c"
|
|
268
|
+
a2 # map(2)
|
|
269
|
+
61 # string(1)
|
|
270
|
+
61 # "a"
|
|
271
|
+
01 # uint(1)
|
|
272
|
+
61 # string(1)
|
|
273
|
+
62 # "b"
|
|
274
|
+
a1 # map(1)
|
|
275
|
+
61 # string(1)
|
|
276
|
+
61 # "a"
|
|
277
|
+
a1 # map(1)
|
|
278
|
+
61 # string(1)
|
|
279
|
+
61 # "a"
|
|
280
|
+
a0 # map(0)
|
|
281
|
+
61 # string(1)
|
|
282
|
+
64 # "d"
|
|
283
|
+
a1 # map(1)
|
|
284
|
+
61 # string(1)
|
|
285
|
+
61 # "a"
|
|
286
|
+
a3 # map(3)
|
|
287
|
+
61 # string(1)
|
|
288
|
+
61 # "a"
|
|
289
|
+
a1 # map(1)
|
|
290
|
+
61 # string(1)
|
|
291
|
+
61 # "a"
|
|
292
|
+
01 # uint(1)
|
|
293
|
+
61 # string(1)
|
|
294
|
+
62 # "b"
|
|
295
|
+
02 # uint(2)
|
|
296
|
+
61 # string(1)
|
|
297
|
+
63 # "c"
|
|
298
|
+
80 # array(0)
|
|
299
|
+
61 # string(1)
|
|
300
|
+
65 # "e"
|
|
301
|
+
81 # array(1)
|
|
302
|
+
81 # array(1)
|
|
303
|
+
81 # array(1)
|
|
304
|
+
81 # array(1)
|
|
305
|
+
a1 # map(1)
|
|
306
|
+
61 # string(1)
|
|
307
|
+
61 # "a"
|
|
308
|
+
a0 # map(0)
|
|
309
|
+
61 # string(1)
|
|
310
|
+
66 # "f"
|
|
311
|
+
01 # uint(1)
|
|
312
|
+
`)
|
|
313
|
+
})
|
|
253
314
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diagnostic.d.ts","sourceRoot":"","sources":["../../lib/diagnostic.js"],"names":[],"mappings":"AAGA;;;GAGG;AACH,wCAHW,UAAU,
|
|
1
|
+
{"version":3,"file":"diagnostic.d.ts","sourceRoot":"","sources":["../../lib/diagnostic.js"],"names":[],"mappings":"AAGA;;;GAGG;AACH,wCAHW,UAAU,gEA2FpB"}
|