test-buffer-inspect.js 792 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. 'use strict';
  2. var Buffer = require('../../').Buffer;
  3. var assert = require('assert');
  4. var util = require('util');
  5. var buffer = require('../../');
  6. buffer.INSPECT_MAX_BYTES = 2;
  7. var b = Buffer.allocUnsafe(4);
  8. b.fill('1234');
  9. var s = buffer.SlowBuffer(4);
  10. s.fill('1234');
  11. var expected = '<Buffer 31 32 ... >';
  12. assert.strictEqual(util.inspect(b), expected);
  13. assert.strictEqual(util.inspect(s), expected);
  14. b = Buffer.allocUnsafe(2);
  15. b.fill('12');
  16. s = buffer.SlowBuffer(2);
  17. s.fill('12');
  18. expected = '<Buffer 31 32>';
  19. assert.strictEqual(util.inspect(b), expected);
  20. assert.strictEqual(util.inspect(s), expected);
  21. buffer.INSPECT_MAX_BYTES = Infinity;
  22. assert.doesNotThrow(function() {
  23. assert.strictEqual(util.inspect(b), expected);
  24. assert.strictEqual(util.inspect(s), expected);
  25. });