mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
5e68e168b8
Remove unnecessary imports from: * test/parallel/test-buffer-nopendingdep-map.js * test/parallel/test-buffer-pending-deprecation.js * test/parallel/test-buffer-sharedarraybuffer.js * test/parallel/test-buffer-slow.js * test/parallel/test-buffer-tojson.js * test/parallel/test-buffer-zero-fill.js Refs: https://github.com/nodejs/node/issues/13836 PR-URL: https://github.com/nodejs/node/pull/13851 Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
36 lines
858 B
JavaScript
36 lines
858 B
JavaScript
'use strict';
|
|
|
|
require('../common');
|
|
const assert = require('assert');
|
|
|
|
{
|
|
assert.strictEqual(JSON.stringify(Buffer.alloc(0)),
|
|
'{"type":"Buffer","data":[]}');
|
|
assert.strictEqual(JSON.stringify(Buffer.from([1, 2, 3, 4])),
|
|
'{"type":"Buffer","data":[1,2,3,4]}');
|
|
}
|
|
|
|
// issue GH-7849
|
|
{
|
|
const buf = Buffer.from('test');
|
|
const json = JSON.stringify(buf);
|
|
const obj = JSON.parse(json);
|
|
const copy = Buffer.from(obj);
|
|
|
|
assert.deepStrictEqual(buf, copy);
|
|
}
|
|
|
|
// GH-5110
|
|
{
|
|
const buffer = Buffer.from('test');
|
|
const string = JSON.stringify(buffer);
|
|
|
|
assert.strictEqual(string, '{"type":"Buffer","data":[116,101,115,116]}');
|
|
|
|
function receiver(key, value) {
|
|
return value && value.type === 'Buffer' ? Buffer.from(value.data) : value;
|
|
}
|
|
|
|
assert.deepStrictEqual(buffer, JSON.parse(string, receiver));
|
|
}
|