cborg 1.4.2 → 1.5.3
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 +133 -50
- package/cjs/browser-test/test-0uint.js +1 -1
- package/cjs/browser-test/test-1negint.js +1 -1
- package/cjs/browser-test/test-2bytes.js +1 -1
- package/cjs/browser-test/test-3string.js +1 -1
- package/cjs/browser-test/test-4array.js +1 -1
- package/cjs/browser-test/test-5map.js +1 -1
- package/cjs/browser-test/test-6tag.js +1 -1
- package/cjs/browser-test/test-7float.js +1 -1
- package/cjs/browser-test/test-bl.js +1 -1
- package/cjs/browser-test/test-cbor-vectors.js +1 -1
- package/cjs/browser-test/test-decode-errors.js +1 -1
- package/cjs/browser-test/test-fuzz.js +1 -1
- package/cjs/lib/bin.js +100 -37
- package/cjs/node-test/node-test-bin.js +133 -50
- package/cjs/node-test/test-0uint.js +1 -1
- package/cjs/node-test/test-1negint.js +1 -1
- package/cjs/node-test/test-2bytes.js +1 -1
- package/cjs/node-test/test-3string.js +1 -1
- package/cjs/node-test/test-4array.js +1 -1
- package/cjs/node-test/test-5map.js +1 -1
- package/cjs/node-test/test-6tag.js +1 -1
- package/cjs/node-test/test-7float.js +1 -1
- package/cjs/node-test/test-bl.js +1 -1
- package/cjs/node-test/test-cbor-vectors.js +1 -1
- package/cjs/node-test/test-decode-errors.js +1 -1
- package/cjs/node-test/test-fuzz.js +1 -1
- package/esm/browser-test/node-test-bin.js +131 -48
- package/esm/lib/bin.js +99 -36
- package/esm/node-test/node-test-bin.js +131 -48
- package/lib/bin.js +125 -40
- package/package.json +1 -1
- package/test/node-test-bin.js +155 -50
- package/types/lib/common.d.ts +1 -1
- package/types/lib/common.d.ts.map +1 -1
|
@@ -13,11 +13,14 @@ var chai__default = /*#__PURE__*/_interopDefaultLegacy(chai);
|
|
|
13
13
|
var process__default = /*#__PURE__*/_interopDefaultLegacy(process);
|
|
14
14
|
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
|
15
15
|
|
|
16
|
-
const {assert} = chai__default[
|
|
17
|
-
const binPath = path__default[
|
|
18
|
-
|
|
16
|
+
const {assert} = chai__default["default"];
|
|
17
|
+
const binPath = path__default["default"].join(path__default["default"].dirname(url.fileURLToPath((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('node-test/node-test-bin.js', document.baseURI).href)))), '../lib/bin.js');
|
|
18
|
+
function fromHex(hex) {
|
|
19
|
+
return new Uint8Array(hex.split('').map((c, i, d) => i % 2 === 0 ? `0x${ c }${ d[i + 1] }` : '').filter(Boolean).map(e => parseInt(e, 16)));
|
|
20
|
+
}
|
|
21
|
+
async function execBin(cmd, stdin) {
|
|
19
22
|
return new Promise((resolve, reject) => {
|
|
20
|
-
child_process.exec(`"${ process__default[
|
|
23
|
+
const cp = child_process.exec(`"${ process__default["default"].execPath }" "${ binPath }" ${ cmd }`, (err, stdout, stderr) => {
|
|
21
24
|
if (err) {
|
|
22
25
|
err.stdout = stdout;
|
|
23
26
|
err.stderr = stderr;
|
|
@@ -28,6 +31,12 @@ async function execBin(cmd) {
|
|
|
28
31
|
stderr
|
|
29
32
|
});
|
|
30
33
|
});
|
|
34
|
+
if (stdin != null) {
|
|
35
|
+
cp.on('spawn', () => {
|
|
36
|
+
cp.stdin.write(stdin);
|
|
37
|
+
cp.stdin.end();
|
|
38
|
+
});
|
|
39
|
+
}
|
|
31
40
|
});
|
|
32
41
|
}
|
|
33
42
|
describe('Bin', () => {
|
|
@@ -39,9 +48,16 @@ describe('Bin', () => {
|
|
|
39
48
|
assert.strictEqual(e.stdout, '');
|
|
40
49
|
assert.strictEqual(e.stderr, `Usage: cborg <command> <args>
|
|
41
50
|
Valid commands:
|
|
42
|
-
\thex2diag
|
|
43
|
-
\
|
|
44
|
-
\
|
|
51
|
+
\thex2diag [hex input]
|
|
52
|
+
\thex2bin [hex input]
|
|
53
|
+
\thex2json [--pretty] [hex input]
|
|
54
|
+
\tbin2hex [binary input]
|
|
55
|
+
\tbin2diag [binary input]
|
|
56
|
+
\tbin2json [--pretty] [binary input]
|
|
57
|
+
\tjson2hex '[json input]'
|
|
58
|
+
\tjson2diag '[json input]'
|
|
59
|
+
\tjson2bin '[json input]'
|
|
60
|
+
Input may either be supplied as an argument or piped via stdin
|
|
45
61
|
`);
|
|
46
62
|
}
|
|
47
63
|
});
|
|
@@ -54,9 +70,16 @@ Valid commands:
|
|
|
54
70
|
assert.strictEqual(e.stderr, `Unknown command: 'blip'
|
|
55
71
|
Usage: cborg <command> <args>
|
|
56
72
|
Valid commands:
|
|
57
|
-
\thex2diag
|
|
58
|
-
\
|
|
59
|
-
\
|
|
73
|
+
\thex2diag [hex input]
|
|
74
|
+
\thex2bin [hex input]
|
|
75
|
+
\thex2json [--pretty] [hex input]
|
|
76
|
+
\tbin2hex [binary input]
|
|
77
|
+
\tbin2diag [binary input]
|
|
78
|
+
\tbin2json [--pretty] [binary input]
|
|
79
|
+
\tjson2hex '[json input]'
|
|
80
|
+
\tjson2diag '[json input]'
|
|
81
|
+
\tjson2bin '[json input]'
|
|
82
|
+
Input may either be supplied as an argument or piped via stdin
|
|
60
83
|
`);
|
|
61
84
|
}
|
|
62
85
|
});
|
|
@@ -65,27 +88,31 @@ Valid commands:
|
|
|
65
88
|
assert.strictEqual(stdout, '');
|
|
66
89
|
assert.strictEqual(stderr, `Usage: cborg <command> <args>
|
|
67
90
|
Valid commands:
|
|
68
|
-
\thex2diag
|
|
69
|
-
\
|
|
70
|
-
\
|
|
91
|
+
\thex2diag [hex input]
|
|
92
|
+
\thex2bin [hex input]
|
|
93
|
+
\thex2json [--pretty] [hex input]
|
|
94
|
+
\tbin2hex [binary input]
|
|
95
|
+
\tbin2diag [binary input]
|
|
96
|
+
\tbin2json [--pretty] [binary input]
|
|
97
|
+
\tjson2hex '[json input]'
|
|
98
|
+
\tjson2diag '[json input]'
|
|
99
|
+
\tjson2bin '[json input]'
|
|
100
|
+
Input may either be supplied as an argument or piped via stdin
|
|
71
101
|
`);
|
|
72
102
|
});
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
await execBin('hex2json');
|
|
79
|
-
assert.
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
const {stdout, stderr} = await execBin('hex2json --pretty a3616101616282020365736d696c6564f09f9880');
|
|
87
|
-
assert.strictEqual(stderr, '');
|
|
88
|
-
assert.strictEqual(stdout, `{
|
|
103
|
+
for (const stdin of [
|
|
104
|
+
true,
|
|
105
|
+
false
|
|
106
|
+
]) {
|
|
107
|
+
it(`hex2json${ stdin ? ' (stdin)' : '' }`, async () => {
|
|
108
|
+
const {stdout, stderr} = stdin ? await execBin('hex2json a3616101616282020365736d696c6564f09f9880') : await execBin('hex2json', 'a3616101616282020365736d696c6564f09f9880');
|
|
109
|
+
assert.strictEqual(stderr, '');
|
|
110
|
+
assert.strictEqual(stdout, '{"a":1,"b":[2,3],"smile":"\uD83D\uDE00"}\n');
|
|
111
|
+
});
|
|
112
|
+
it(`hex2json pretty${ stdin ? ' (stdin)' : '' }`, async () => {
|
|
113
|
+
const {stdout, stderr} = stdin ? await execBin('hex2json --pretty a3616101616282020365736d696c6564f09f9880') : await execBin('hex2json --pretty', 'a3616101616282020365736d696c6564f09f9880');
|
|
114
|
+
assert.strictEqual(stderr, '');
|
|
115
|
+
assert.strictEqual(stdout, `{
|
|
89
116
|
"a": 1,
|
|
90
117
|
"b": [
|
|
91
118
|
2,
|
|
@@ -94,11 +121,11 @@ Valid commands:
|
|
|
94
121
|
"smile": "😀"
|
|
95
122
|
}
|
|
96
123
|
`);
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
124
|
+
});
|
|
125
|
+
it(`hex2diag${ stdin ? ' (stdin)' : '' }`, async () => {
|
|
126
|
+
const {stdout, stderr} = stdin ? await execBin('hex2diag a4616101616282020363627566440102036165736d696c6564f09f9880') : await execBin('hex2diag', 'a4616101616282020363627566440102036165736d696c6564f09f9880');
|
|
127
|
+
assert.strictEqual(stderr, '');
|
|
128
|
+
assert.strictEqual(stdout, `a4 # map(4)
|
|
102
129
|
61 # string(1)
|
|
103
130
|
61 # "a"
|
|
104
131
|
01 # uint(1)
|
|
@@ -116,24 +143,80 @@ Valid commands:
|
|
|
116
143
|
64 f09f # string(2)
|
|
117
144
|
f09f9880 # "😀"
|
|
118
145
|
`);
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
assert.strictEqual(
|
|
124
|
-
|
|
125
|
-
}
|
|
146
|
+
});
|
|
147
|
+
it(`hex2bin${ stdin ? ' (stdin)' : '' }`, async () => {
|
|
148
|
+
const {stdout, stderr} = stdin ? await execBin('hex2bin a3616101616282020365736d696c6564f09f9880') : await execBin('hex2bin', 'a3616101616282020365736d696c6564f09f9880');
|
|
149
|
+
assert.strictEqual(stderr, '');
|
|
150
|
+
assert.strictEqual(stdout, new TextDecoder().decode(fromHex('a3616101616282020365736d696c6564f09f9880')));
|
|
151
|
+
});
|
|
152
|
+
it(`json2hex${ stdin ? ' (stdin)' : '' }`, async () => {
|
|
153
|
+
const {stdout, stderr} = stdin ? await execBin('json2hex "{\\"a\\":1,\\"b\\":[2,3],\\"smile\\":\\"\uD83D\uDE00\\"}"') : await execBin('json2hex', '{"a":1,"b":[2,3],"smile":"\uD83D\uDE00"}');
|
|
154
|
+
assert.strictEqual(stderr, '');
|
|
155
|
+
assert.strictEqual(stdout, 'a3616101616282020365736d696c6564f09f9880\n');
|
|
156
|
+
});
|
|
157
|
+
it(`json2bin${ stdin ? ' (stdin)' : '' }`, async () => {
|
|
158
|
+
const {stdout, stderr} = stdin ? await execBin('json2bin "{\\"a\\":1,\\"b\\":[2,3],\\"smile\\":\\"\uD83D\uDE00\\"}"') : await execBin('json2bin', '{"a":1,"b":[2,3],"smile":"\uD83D\uDE00"}');
|
|
159
|
+
assert.strictEqual(stderr, '');
|
|
160
|
+
assert.strictEqual(stdout, new TextDecoder().decode(fromHex('a3616101616282020365736d696c6564f09f9880')));
|
|
161
|
+
});
|
|
162
|
+
it(`json2diag${ stdin ? ' (stdin)' : '' }`, async () => {
|
|
163
|
+
const {stdout, stderr} = stdin ? await execBin('json2diag "{\\"a\\":1,\\"b\\":[2,3],\\"smile\\":\\"\uD83D\uDE00\\"}"') : await execBin('json2diag', '{"a":1,"b":[2,3],"smile":"\uD83D\uDE00"}');
|
|
164
|
+
assert.strictEqual(stderr, '');
|
|
165
|
+
assert.strictEqual(stdout, `a3 # map(3)
|
|
166
|
+
61 # string(1)
|
|
167
|
+
61 # "a"
|
|
168
|
+
01 # uint(1)
|
|
169
|
+
61 # string(1)
|
|
170
|
+
62 # "b"
|
|
171
|
+
82 # array(2)
|
|
172
|
+
02 # uint(2)
|
|
173
|
+
03 # uint(3)
|
|
174
|
+
65 # string(5)
|
|
175
|
+
736d696c65 # "smile"
|
|
176
|
+
64 f09f # string(2)
|
|
177
|
+
f09f9880 # "😀"
|
|
178
|
+
`);
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
it('bin2diag (stdin)', async () => {
|
|
182
|
+
const {stdout, stderr} = await execBin('bin2diag', fromHex('a3616101616282020365736d696c6564f09f9880'));
|
|
183
|
+
assert.strictEqual(stderr, '');
|
|
184
|
+
assert.strictEqual(stdout, `a3 # map(3)
|
|
185
|
+
61 # string(1)
|
|
186
|
+
61 # "a"
|
|
187
|
+
01 # uint(1)
|
|
188
|
+
61 # string(1)
|
|
189
|
+
62 # "b"
|
|
190
|
+
82 # array(2)
|
|
191
|
+
02 # uint(2)
|
|
192
|
+
03 # uint(3)
|
|
193
|
+
65 # string(5)
|
|
194
|
+
736d696c65 # "smile"
|
|
195
|
+
64 f09f # string(2)
|
|
196
|
+
f09f9880 # "😀"
|
|
197
|
+
`);
|
|
198
|
+
});
|
|
199
|
+
it('bin2json (stdin)', async () => {
|
|
200
|
+
const {stdout, stderr} = await execBin('bin2json', fromHex('a3616101616282020365736d696c6564f09f9880'));
|
|
201
|
+
assert.strictEqual(stderr, '');
|
|
202
|
+
assert.strictEqual(stdout, '{"a":1,"b":[2,3],"smile":"\uD83D\uDE00"}\n');
|
|
203
|
+
});
|
|
204
|
+
it('bin2json pretty (stdin)', async () => {
|
|
205
|
+
const {stdout, stderr} = await execBin('bin2json --pretty', fromHex('a3616101616282020365736d696c6564f09f9880'));
|
|
206
|
+
assert.strictEqual(stderr, '');
|
|
207
|
+
assert.strictEqual(stdout, `{
|
|
208
|
+
"a": 1,
|
|
209
|
+
"b": [
|
|
210
|
+
2,
|
|
211
|
+
3
|
|
212
|
+
],
|
|
213
|
+
"smile": "😀"
|
|
214
|
+
}
|
|
215
|
+
`);
|
|
126
216
|
});
|
|
127
|
-
it('
|
|
128
|
-
const {stdout, stderr} = await execBin('
|
|
217
|
+
it('bin2hex (stdin)', async () => {
|
|
218
|
+
const {stdout, stderr} = await execBin('bin2hex', fromHex('a3616101616282020365736d696c6564f09f9880'));
|
|
129
219
|
assert.strictEqual(stderr, '');
|
|
130
220
|
assert.strictEqual(stdout, 'a3616101616282020365736d696c6564f09f9880\n');
|
|
131
|
-
try {
|
|
132
|
-
await execBin('json2hex');
|
|
133
|
-
assert.fail('should have errored');
|
|
134
|
-
} catch (e) {
|
|
135
|
-
assert.strictEqual(e.stdout, '');
|
|
136
|
-
assert.isTrue(e.stderr.startsWith('json2hex requires a JSON input string\nUsage: '));
|
|
137
|
-
}
|
|
138
221
|
});
|
|
139
222
|
});
|
|
@@ -10,7 +10,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
10
10
|
|
|
11
11
|
var chai__default = /*#__PURE__*/_interopDefaultLegacy(chai);
|
|
12
12
|
|
|
13
|
-
const {assert} = chai__default[
|
|
13
|
+
const {assert} = chai__default["default"];
|
|
14
14
|
const fixtures = [
|
|
15
15
|
{
|
|
16
16
|
data: '00',
|
|
@@ -10,7 +10,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
10
10
|
|
|
11
11
|
var chai__default = /*#__PURE__*/_interopDefaultLegacy(chai);
|
|
12
12
|
|
|
13
|
-
const {assert} = chai__default[
|
|
13
|
+
const {assert} = chai__default["default"];
|
|
14
14
|
const fixtures = [
|
|
15
15
|
{
|
|
16
16
|
data: '20',
|
|
@@ -10,7 +10,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
10
10
|
|
|
11
11
|
var chai__default = /*#__PURE__*/_interopDefaultLegacy(chai);
|
|
12
12
|
|
|
13
|
-
const {assert} = chai__default[
|
|
13
|
+
const {assert} = chai__default["default"];
|
|
14
14
|
const fixtures = [
|
|
15
15
|
{
|
|
16
16
|
data: '40',
|
|
@@ -10,7 +10,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
10
10
|
|
|
11
11
|
var chai__default = /*#__PURE__*/_interopDefaultLegacy(chai);
|
|
12
12
|
|
|
13
|
-
const {assert} = chai__default[
|
|
13
|
+
const {assert} = chai__default["default"];
|
|
14
14
|
const fixtures = [
|
|
15
15
|
{
|
|
16
16
|
data: '60',
|
|
@@ -10,7 +10,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
10
10
|
|
|
11
11
|
var chai__default = /*#__PURE__*/_interopDefaultLegacy(chai);
|
|
12
12
|
|
|
13
|
-
const {assert} = chai__default[
|
|
13
|
+
const {assert} = chai__default["default"];
|
|
14
14
|
const fixtures = [
|
|
15
15
|
{
|
|
16
16
|
data: '80',
|
|
@@ -10,7 +10,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
10
10
|
|
|
11
11
|
var chai__default = /*#__PURE__*/_interopDefaultLegacy(chai);
|
|
12
12
|
|
|
13
|
-
const {assert} = chai__default[
|
|
13
|
+
const {assert} = chai__default["default"];
|
|
14
14
|
const fixtures = [
|
|
15
15
|
{
|
|
16
16
|
data: 'a0',
|
|
@@ -11,7 +11,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
11
11
|
|
|
12
12
|
var chai__default = /*#__PURE__*/_interopDefaultLegacy(chai);
|
|
13
13
|
|
|
14
|
-
const {assert} = chai__default[
|
|
14
|
+
const {assert} = chai__default["default"];
|
|
15
15
|
function dateDecoder(obj) {
|
|
16
16
|
if (typeof obj !== 'string') {
|
|
17
17
|
throw new Error('expected string for tag 1');
|
|
@@ -10,7 +10,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
10
10
|
|
|
11
11
|
var chai__default = /*#__PURE__*/_interopDefaultLegacy(chai);
|
|
12
12
|
|
|
13
|
-
const {assert} = chai__default[
|
|
13
|
+
const {assert} = chai__default["default"];
|
|
14
14
|
const fixtures = [
|
|
15
15
|
{
|
|
16
16
|
data: '8601f5f4f6f720',
|
package/cjs/node-test/test-bl.js
CHANGED
|
@@ -7,7 +7,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
7
7
|
|
|
8
8
|
var chai__default = /*#__PURE__*/_interopDefaultLegacy(chai);
|
|
9
9
|
|
|
10
|
-
const {assert} = chai__default[
|
|
10
|
+
const {assert} = chai__default["default"];
|
|
11
11
|
describe('Internal bytes list', () => {
|
|
12
12
|
describe('push', () => {
|
|
13
13
|
it('push bits', () => {
|
|
@@ -13,7 +13,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
13
13
|
|
|
14
14
|
var chai__default = /*#__PURE__*/_interopDefaultLegacy(chai);
|
|
15
15
|
|
|
16
|
-
const {assert} = chai__default[
|
|
16
|
+
const {assert} = chai__default["default"];
|
|
17
17
|
const tags = [];
|
|
18
18
|
const typeEncoders = {};
|
|
19
19
|
tags[0] = function (obj) {
|
|
@@ -9,7 +9,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
9
9
|
|
|
10
10
|
var chai__default = /*#__PURE__*/_interopDefaultLegacy(chai);
|
|
11
11
|
|
|
12
|
-
const {assert} = chai__default[
|
|
12
|
+
const {assert} = chai__default["default"];
|
|
13
13
|
describe('decode errors', () => {
|
|
14
14
|
it('not Uint8Array', () => {
|
|
15
15
|
for (const arg of [
|
|
@@ -10,7 +10,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
10
10
|
|
|
11
11
|
var chai__default = /*#__PURE__*/_interopDefaultLegacy(chai);
|
|
12
12
|
|
|
13
|
-
const {assert} = chai__default[
|
|
13
|
+
const {assert} = chai__default["default"];
|
|
14
14
|
describe('Fuzz round-trip', () => {
|
|
15
15
|
it('random objects', function () {
|
|
16
16
|
this.timeout(5000);
|
|
@@ -6,9 +6,12 @@ import { fileURLToPath } from 'url';
|
|
|
6
6
|
import bin from '../lib/bin.js';
|
|
7
7
|
const {assert} = chai;
|
|
8
8
|
const binPath = path.join(path.dirname(fileURLToPath(import.meta.url)), '../lib/bin.js');
|
|
9
|
-
|
|
9
|
+
function fromHex(hex) {
|
|
10
|
+
return new Uint8Array(hex.split('').map((c, i, d) => i % 2 === 0 ? `0x${ c }${ d[i + 1] }` : '').filter(Boolean).map(e => parseInt(e, 16)));
|
|
11
|
+
}
|
|
12
|
+
async function execBin(cmd, stdin) {
|
|
10
13
|
return new Promise((resolve, reject) => {
|
|
11
|
-
exec(`"${ process.execPath }" "${ binPath }" ${ cmd }`, (err, stdout, stderr) => {
|
|
14
|
+
const cp = exec(`"${ process.execPath }" "${ binPath }" ${ cmd }`, (err, stdout, stderr) => {
|
|
12
15
|
if (err) {
|
|
13
16
|
err.stdout = stdout;
|
|
14
17
|
err.stderr = stderr;
|
|
@@ -19,6 +22,12 @@ async function execBin(cmd) {
|
|
|
19
22
|
stderr
|
|
20
23
|
});
|
|
21
24
|
});
|
|
25
|
+
if (stdin != null) {
|
|
26
|
+
cp.on('spawn', () => {
|
|
27
|
+
cp.stdin.write(stdin);
|
|
28
|
+
cp.stdin.end();
|
|
29
|
+
});
|
|
30
|
+
}
|
|
22
31
|
});
|
|
23
32
|
}
|
|
24
33
|
describe('Bin', () => {
|
|
@@ -30,9 +39,16 @@ describe('Bin', () => {
|
|
|
30
39
|
assert.strictEqual(e.stdout, '');
|
|
31
40
|
assert.strictEqual(e.stderr, `Usage: cborg <command> <args>
|
|
32
41
|
Valid commands:
|
|
33
|
-
\thex2diag
|
|
34
|
-
\
|
|
35
|
-
\
|
|
42
|
+
\thex2diag [hex input]
|
|
43
|
+
\thex2bin [hex input]
|
|
44
|
+
\thex2json [--pretty] [hex input]
|
|
45
|
+
\tbin2hex [binary input]
|
|
46
|
+
\tbin2diag [binary input]
|
|
47
|
+
\tbin2json [--pretty] [binary input]
|
|
48
|
+
\tjson2hex '[json input]'
|
|
49
|
+
\tjson2diag '[json input]'
|
|
50
|
+
\tjson2bin '[json input]'
|
|
51
|
+
Input may either be supplied as an argument or piped via stdin
|
|
36
52
|
`);
|
|
37
53
|
}
|
|
38
54
|
});
|
|
@@ -45,9 +61,16 @@ Valid commands:
|
|
|
45
61
|
assert.strictEqual(e.stderr, `Unknown command: 'blip'
|
|
46
62
|
Usage: cborg <command> <args>
|
|
47
63
|
Valid commands:
|
|
48
|
-
\thex2diag
|
|
49
|
-
\
|
|
50
|
-
\
|
|
64
|
+
\thex2diag [hex input]
|
|
65
|
+
\thex2bin [hex input]
|
|
66
|
+
\thex2json [--pretty] [hex input]
|
|
67
|
+
\tbin2hex [binary input]
|
|
68
|
+
\tbin2diag [binary input]
|
|
69
|
+
\tbin2json [--pretty] [binary input]
|
|
70
|
+
\tjson2hex '[json input]'
|
|
71
|
+
\tjson2diag '[json input]'
|
|
72
|
+
\tjson2bin '[json input]'
|
|
73
|
+
Input may either be supplied as an argument or piped via stdin
|
|
51
74
|
`);
|
|
52
75
|
}
|
|
53
76
|
});
|
|
@@ -56,27 +79,31 @@ Valid commands:
|
|
|
56
79
|
assert.strictEqual(stdout, '');
|
|
57
80
|
assert.strictEqual(stderr, `Usage: cborg <command> <args>
|
|
58
81
|
Valid commands:
|
|
59
|
-
\thex2diag
|
|
60
|
-
\
|
|
61
|
-
\
|
|
82
|
+
\thex2diag [hex input]
|
|
83
|
+
\thex2bin [hex input]
|
|
84
|
+
\thex2json [--pretty] [hex input]
|
|
85
|
+
\tbin2hex [binary input]
|
|
86
|
+
\tbin2diag [binary input]
|
|
87
|
+
\tbin2json [--pretty] [binary input]
|
|
88
|
+
\tjson2hex '[json input]'
|
|
89
|
+
\tjson2diag '[json input]'
|
|
90
|
+
\tjson2bin '[json input]'
|
|
91
|
+
Input may either be supplied as an argument or piped via stdin
|
|
62
92
|
`);
|
|
63
93
|
});
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
await execBin('hex2json');
|
|
70
|
-
assert.
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const {stdout, stderr} = await execBin('hex2json --pretty a3616101616282020365736d696c6564f09f9880');
|
|
78
|
-
assert.strictEqual(stderr, '');
|
|
79
|
-
assert.strictEqual(stdout, `{
|
|
94
|
+
for (const stdin of [
|
|
95
|
+
true,
|
|
96
|
+
false
|
|
97
|
+
]) {
|
|
98
|
+
it(`hex2json${ stdin ? ' (stdin)' : '' }`, async () => {
|
|
99
|
+
const {stdout, stderr} = stdin ? await execBin('hex2json a3616101616282020365736d696c6564f09f9880') : await execBin('hex2json', 'a3616101616282020365736d696c6564f09f9880');
|
|
100
|
+
assert.strictEqual(stderr, '');
|
|
101
|
+
assert.strictEqual(stdout, '{"a":1,"b":[2,3],"smile":"\uD83D\uDE00"}\n');
|
|
102
|
+
});
|
|
103
|
+
it(`hex2json pretty${ stdin ? ' (stdin)' : '' }`, async () => {
|
|
104
|
+
const {stdout, stderr} = stdin ? await execBin('hex2json --pretty a3616101616282020365736d696c6564f09f9880') : await execBin('hex2json --pretty', 'a3616101616282020365736d696c6564f09f9880');
|
|
105
|
+
assert.strictEqual(stderr, '');
|
|
106
|
+
assert.strictEqual(stdout, `{
|
|
80
107
|
"a": 1,
|
|
81
108
|
"b": [
|
|
82
109
|
2,
|
|
@@ -85,11 +112,11 @@ Valid commands:
|
|
|
85
112
|
"smile": "😀"
|
|
86
113
|
}
|
|
87
114
|
`);
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
115
|
+
});
|
|
116
|
+
it(`hex2diag${ stdin ? ' (stdin)' : '' }`, async () => {
|
|
117
|
+
const {stdout, stderr} = stdin ? await execBin('hex2diag a4616101616282020363627566440102036165736d696c6564f09f9880') : await execBin('hex2diag', 'a4616101616282020363627566440102036165736d696c6564f09f9880');
|
|
118
|
+
assert.strictEqual(stderr, '');
|
|
119
|
+
assert.strictEqual(stdout, `a4 # map(4)
|
|
93
120
|
61 # string(1)
|
|
94
121
|
61 # "a"
|
|
95
122
|
01 # uint(1)
|
|
@@ -107,24 +134,80 @@ Valid commands:
|
|
|
107
134
|
64 f09f # string(2)
|
|
108
135
|
f09f9880 # "😀"
|
|
109
136
|
`);
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
assert.strictEqual(
|
|
115
|
-
|
|
116
|
-
}
|
|
137
|
+
});
|
|
138
|
+
it(`hex2bin${ stdin ? ' (stdin)' : '' }`, async () => {
|
|
139
|
+
const {stdout, stderr} = stdin ? await execBin('hex2bin a3616101616282020365736d696c6564f09f9880') : await execBin('hex2bin', 'a3616101616282020365736d696c6564f09f9880');
|
|
140
|
+
assert.strictEqual(stderr, '');
|
|
141
|
+
assert.strictEqual(stdout, new TextDecoder().decode(fromHex('a3616101616282020365736d696c6564f09f9880')));
|
|
142
|
+
});
|
|
143
|
+
it(`json2hex${ stdin ? ' (stdin)' : '' }`, async () => {
|
|
144
|
+
const {stdout, stderr} = stdin ? await execBin('json2hex "{\\"a\\":1,\\"b\\":[2,3],\\"smile\\":\\"\uD83D\uDE00\\"}"') : await execBin('json2hex', '{"a":1,"b":[2,3],"smile":"\uD83D\uDE00"}');
|
|
145
|
+
assert.strictEqual(stderr, '');
|
|
146
|
+
assert.strictEqual(stdout, 'a3616101616282020365736d696c6564f09f9880\n');
|
|
147
|
+
});
|
|
148
|
+
it(`json2bin${ stdin ? ' (stdin)' : '' }`, async () => {
|
|
149
|
+
const {stdout, stderr} = stdin ? await execBin('json2bin "{\\"a\\":1,\\"b\\":[2,3],\\"smile\\":\\"\uD83D\uDE00\\"}"') : await execBin('json2bin', '{"a":1,"b":[2,3],"smile":"\uD83D\uDE00"}');
|
|
150
|
+
assert.strictEqual(stderr, '');
|
|
151
|
+
assert.strictEqual(stdout, new TextDecoder().decode(fromHex('a3616101616282020365736d696c6564f09f9880')));
|
|
152
|
+
});
|
|
153
|
+
it(`json2diag${ stdin ? ' (stdin)' : '' }`, async () => {
|
|
154
|
+
const {stdout, stderr} = stdin ? await execBin('json2diag "{\\"a\\":1,\\"b\\":[2,3],\\"smile\\":\\"\uD83D\uDE00\\"}"') : await execBin('json2diag', '{"a":1,"b":[2,3],"smile":"\uD83D\uDE00"}');
|
|
155
|
+
assert.strictEqual(stderr, '');
|
|
156
|
+
assert.strictEqual(stdout, `a3 # map(3)
|
|
157
|
+
61 # string(1)
|
|
158
|
+
61 # "a"
|
|
159
|
+
01 # uint(1)
|
|
160
|
+
61 # string(1)
|
|
161
|
+
62 # "b"
|
|
162
|
+
82 # array(2)
|
|
163
|
+
02 # uint(2)
|
|
164
|
+
03 # uint(3)
|
|
165
|
+
65 # string(5)
|
|
166
|
+
736d696c65 # "smile"
|
|
167
|
+
64 f09f # string(2)
|
|
168
|
+
f09f9880 # "😀"
|
|
169
|
+
`);
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
it('bin2diag (stdin)', async () => {
|
|
173
|
+
const {stdout, stderr} = await execBin('bin2diag', fromHex('a3616101616282020365736d696c6564f09f9880'));
|
|
174
|
+
assert.strictEqual(stderr, '');
|
|
175
|
+
assert.strictEqual(stdout, `a3 # map(3)
|
|
176
|
+
61 # string(1)
|
|
177
|
+
61 # "a"
|
|
178
|
+
01 # uint(1)
|
|
179
|
+
61 # string(1)
|
|
180
|
+
62 # "b"
|
|
181
|
+
82 # array(2)
|
|
182
|
+
02 # uint(2)
|
|
183
|
+
03 # uint(3)
|
|
184
|
+
65 # string(5)
|
|
185
|
+
736d696c65 # "smile"
|
|
186
|
+
64 f09f # string(2)
|
|
187
|
+
f09f9880 # "😀"
|
|
188
|
+
`);
|
|
189
|
+
});
|
|
190
|
+
it('bin2json (stdin)', async () => {
|
|
191
|
+
const {stdout, stderr} = await execBin('bin2json', fromHex('a3616101616282020365736d696c6564f09f9880'));
|
|
192
|
+
assert.strictEqual(stderr, '');
|
|
193
|
+
assert.strictEqual(stdout, '{"a":1,"b":[2,3],"smile":"\uD83D\uDE00"}\n');
|
|
194
|
+
});
|
|
195
|
+
it('bin2json pretty (stdin)', async () => {
|
|
196
|
+
const {stdout, stderr} = await execBin('bin2json --pretty', fromHex('a3616101616282020365736d696c6564f09f9880'));
|
|
197
|
+
assert.strictEqual(stderr, '');
|
|
198
|
+
assert.strictEqual(stdout, `{
|
|
199
|
+
"a": 1,
|
|
200
|
+
"b": [
|
|
201
|
+
2,
|
|
202
|
+
3
|
|
203
|
+
],
|
|
204
|
+
"smile": "😀"
|
|
205
|
+
}
|
|
206
|
+
`);
|
|
117
207
|
});
|
|
118
|
-
it('
|
|
119
|
-
const {stdout, stderr} = await execBin('
|
|
208
|
+
it('bin2hex (stdin)', async () => {
|
|
209
|
+
const {stdout, stderr} = await execBin('bin2hex', fromHex('a3616101616282020365736d696c6564f09f9880'));
|
|
120
210
|
assert.strictEqual(stderr, '');
|
|
121
211
|
assert.strictEqual(stdout, 'a3616101616282020365736d696c6564f09f9880\n');
|
|
122
|
-
try {
|
|
123
|
-
await execBin('json2hex');
|
|
124
|
-
assert.fail('should have errored');
|
|
125
|
-
} catch (e) {
|
|
126
|
-
assert.strictEqual(e.stdout, '');
|
|
127
|
-
assert.isTrue(e.stderr.startsWith('json2hex requires a JSON input string\nUsage: '));
|
|
128
|
-
}
|
|
129
212
|
});
|
|
130
213
|
});
|