Files
node/test/parallel/test-stringbytes-external-exceed-max-by-1-binary.js
T
cjihrig 2c33819370 test: fix tests that check error messages
20285ad177 changed the format
of error messages throughout lib. However, the tests were not
updated to reflect these changes. This commit makes those
changes.

PR-URL: https://github.com/nodejs/node/pull/3727
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
Reviewed-By: James M Snell <jasnell@gmail.com>
2015-11-10 07:12:33 +01:00

32 lines
890 B
JavaScript

'use strict';
require('../common');
const assert = require('assert');
// v8 fails silently if string length > v8::String::kMaxLength
// v8::String::kMaxLength defined in v8.h
const kStringMaxLength = process.binding('buffer').kStringMaxLength;
try {
new Buffer(kStringMaxLength * 3);
} catch(e) {
assert.equal(e.message, 'Invalid array buffer length');
console.log(
'1..0 # Skipped: intensive toString tests due to memory confinements');
return;
}
const buf = new Buffer(kStringMaxLength + 1);
assert.throws(function() {
buf.toString('binary');
}, /"toString\(\)" failed/);
var maxString = buf.toString('binary', 1);
assert.equal(maxString.length, kStringMaxLength);
// Free the memory early instead of at the end of the next assignment
maxString = undefined;
maxString = buf.toString('binary', 0, kStringMaxLength);
assert.equal(maxString.length, kStringMaxLength);