Browse Source

test: s/ASSERT/assert/

This commit addresses an inconsistency with eight tests. These
tests use the assert module, but named the variable ASSERT. This
goes against the project's typical coding style, and negatively
impacts global find and replace updates.

PR-URL: https://github.com/nodejs/node/pull/10544
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Reviewed-By: Jackson Tian <shyvo1987@gmail.com>
Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
v6.x
cjihrig 8 years ago
committed by Myles Borins
parent
commit
f3d1b7209d
  1. 62
      test/parallel/test-readdouble.js
  2. 38
      test/parallel/test-readfloat.js
  3. 62
      test/parallel/test-readint.js
  4. 40
      test/parallel/test-readuint.js
  5. 270
      test/parallel/test-writedouble.js
  6. 142
      test/parallel/test-writefloat.js
  7. 154
      test/parallel/test-writeint.js
  8. 106
      test/parallel/test-writeuint.js

62
test/parallel/test-readdouble.js

@ -3,7 +3,7 @@
* Tests to verify we're reading in doubles correctly
*/
require('../common');
var ASSERT = require('assert');
const assert = require('assert');
/*
* Test (64 bit) double
@ -19,8 +19,8 @@ function test(clazz) {
buffer[5] = 0x55;
buffer[6] = 0xd5;
buffer[7] = 0x3f;
ASSERT.equal(1.1945305291680097e+103, buffer.readDoubleBE(0));
ASSERT.equal(0.3333333333333333, buffer.readDoubleLE(0));
assert.equal(1.1945305291680097e+103, buffer.readDoubleBE(0));
assert.equal(0.3333333333333333, buffer.readDoubleLE(0));
buffer[0] = 1;
buffer[1] = 0;
@ -30,18 +30,18 @@ function test(clazz) {
buffer[5] = 0;
buffer[6] = 0xf0;
buffer[7] = 0x3f;
ASSERT.equal(7.291122019655968e-304, buffer.readDoubleBE(0));
ASSERT.equal(1.0000000000000002, buffer.readDoubleLE(0));
assert.equal(7.291122019655968e-304, buffer.readDoubleBE(0));
assert.equal(1.0000000000000002, buffer.readDoubleLE(0));
buffer[0] = 2;
ASSERT.equal(4.778309726801735e-299, buffer.readDoubleBE(0));
ASSERT.equal(1.0000000000000004, buffer.readDoubleLE(0));
assert.equal(4.778309726801735e-299, buffer.readDoubleBE(0));
assert.equal(1.0000000000000004, buffer.readDoubleLE(0));
buffer[0] = 1;
buffer[6] = 0;
buffer[7] = 0;
ASSERT.equal(7.291122019556398e-304, buffer.readDoubleBE(0));
ASSERT.equal(5e-324, buffer.readDoubleLE(0));
assert.equal(7.291122019556398e-304, buffer.readDoubleBE(0));
assert.equal(5e-324, buffer.readDoubleLE(0));
buffer[0] = 0xff;
buffer[1] = 0xff;
@ -51,13 +51,13 @@ function test(clazz) {
buffer[5] = 0xff;
buffer[6] = 0x0f;
buffer[7] = 0x00;
ASSERT.ok(isNaN(buffer.readDoubleBE(0)));
ASSERT.equal(2.225073858507201e-308, buffer.readDoubleLE(0));
assert.ok(isNaN(buffer.readDoubleBE(0)));
assert.equal(2.225073858507201e-308, buffer.readDoubleLE(0));
buffer[6] = 0xef;
buffer[7] = 0x7f;
ASSERT.ok(isNaN(buffer.readDoubleBE(0)));
ASSERT.equal(1.7976931348623157e+308, buffer.readDoubleLE(0));
assert.ok(isNaN(buffer.readDoubleBE(0)));
assert.equal(1.7976931348623157e+308, buffer.readDoubleLE(0));
buffer[0] = 0;
buffer[1] = 0;
@ -67,42 +67,42 @@ function test(clazz) {
buffer[5] = 0;
buffer[6] = 0xf0;
buffer[7] = 0x3f;
ASSERT.equal(3.03865e-319, buffer.readDoubleBE(0));
ASSERT.equal(1, buffer.readDoubleLE(0));
assert.equal(3.03865e-319, buffer.readDoubleBE(0));
assert.equal(1, buffer.readDoubleLE(0));
buffer[6] = 0;
buffer[7] = 0x40;
ASSERT.equal(3.16e-322, buffer.readDoubleBE(0));
ASSERT.equal(2, buffer.readDoubleLE(0));
assert.equal(3.16e-322, buffer.readDoubleBE(0));
assert.equal(2, buffer.readDoubleLE(0));
buffer[7] = 0xc0;
ASSERT.equal(9.5e-322, buffer.readDoubleBE(0));
ASSERT.equal(-2, buffer.readDoubleLE(0));
assert.equal(9.5e-322, buffer.readDoubleBE(0));
assert.equal(-2, buffer.readDoubleLE(0));
buffer[6] = 0x10;
buffer[7] = 0;
ASSERT.equal(2.0237e-320, buffer.readDoubleBE(0));
ASSERT.equal(2.2250738585072014e-308, buffer.readDoubleLE(0));
assert.equal(2.0237e-320, buffer.readDoubleBE(0));
assert.equal(2.2250738585072014e-308, buffer.readDoubleLE(0));
buffer[6] = 0;
ASSERT.equal(0, buffer.readDoubleBE(0));
ASSERT.equal(0, buffer.readDoubleLE(0));
ASSERT.equal(false, 1 / buffer.readDoubleLE(0) < 0);
assert.equal(0, buffer.readDoubleBE(0));
assert.equal(0, buffer.readDoubleLE(0));
assert.equal(false, 1 / buffer.readDoubleLE(0) < 0);
buffer[7] = 0x80;
ASSERT.equal(6.3e-322, buffer.readDoubleBE(0));
ASSERT.equal(0, buffer.readDoubleLE(0));
ASSERT.equal(true, 1 / buffer.readDoubleLE(0) < 0);
assert.equal(6.3e-322, buffer.readDoubleBE(0));
assert.equal(0, buffer.readDoubleLE(0));
assert.equal(true, 1 / buffer.readDoubleLE(0) < 0);
buffer[6] = 0xf0;
buffer[7] = 0x7f;
ASSERT.equal(3.0418e-319, buffer.readDoubleBE(0));
ASSERT.equal(Infinity, buffer.readDoubleLE(0));
assert.equal(3.0418e-319, buffer.readDoubleBE(0));
assert.equal(Infinity, buffer.readDoubleLE(0));
buffer[6] = 0xf0;
buffer[7] = 0xff;
ASSERT.equal(3.04814e-319, buffer.readDoubleBE(0));
ASSERT.equal(-Infinity, buffer.readDoubleLE(0));
assert.equal(3.04814e-319, buffer.readDoubleBE(0));
assert.equal(-Infinity, buffer.readDoubleLE(0));
}

38
test/parallel/test-readfloat.js

@ -3,7 +3,7 @@
* Tests to verify we're reading in floats correctly
*/
require('../common');
var ASSERT = require('assert');
const assert = require('assert');
/*
* Test (32 bit) float
@ -15,56 +15,56 @@ function test(clazz) {
buffer[1] = 0;
buffer[2] = 0x80;
buffer[3] = 0x3f;
ASSERT.equal(4.600602988224807e-41, buffer.readFloatBE(0));
ASSERT.equal(1, buffer.readFloatLE(0));
assert.equal(4.600602988224807e-41, buffer.readFloatBE(0));
assert.equal(1, buffer.readFloatLE(0));
buffer[0] = 0;
buffer[1] = 0;
buffer[2] = 0;
buffer[3] = 0xc0;
ASSERT.equal(2.6904930515036488e-43, buffer.readFloatBE(0));
ASSERT.equal(-2, buffer.readFloatLE(0));
assert.equal(2.6904930515036488e-43, buffer.readFloatBE(0));
assert.equal(-2, buffer.readFloatLE(0));
buffer[0] = 0xff;
buffer[1] = 0xff;
buffer[2] = 0x7f;
buffer[3] = 0x7f;
ASSERT.ok(isNaN(buffer.readFloatBE(0)));
ASSERT.equal(3.4028234663852886e+38, buffer.readFloatLE(0));
assert.ok(isNaN(buffer.readFloatBE(0)));
assert.equal(3.4028234663852886e+38, buffer.readFloatLE(0));
buffer[0] = 0xab;
buffer[1] = 0xaa;
buffer[2] = 0xaa;
buffer[3] = 0x3e;
ASSERT.equal(-1.2126478207002966e-12, buffer.readFloatBE(0));
ASSERT.equal(0.3333333432674408, buffer.readFloatLE(0));
assert.equal(-1.2126478207002966e-12, buffer.readFloatBE(0));
assert.equal(0.3333333432674408, buffer.readFloatLE(0));
buffer[0] = 0;
buffer[1] = 0;
buffer[2] = 0;
buffer[3] = 0;
ASSERT.equal(0, buffer.readFloatBE(0));
ASSERT.equal(0, buffer.readFloatLE(0));
ASSERT.equal(false, 1 / buffer.readFloatLE(0) < 0);
assert.equal(0, buffer.readFloatBE(0));
assert.equal(0, buffer.readFloatLE(0));
assert.equal(false, 1 / buffer.readFloatLE(0) < 0);
buffer[3] = 0x80;
ASSERT.equal(1.793662034335766e-43, buffer.readFloatBE(0));
ASSERT.equal(0, buffer.readFloatLE(0));
ASSERT.equal(true, 1 / buffer.readFloatLE(0) < 0);
assert.equal(1.793662034335766e-43, buffer.readFloatBE(0));
assert.equal(0, buffer.readFloatLE(0));
assert.equal(true, 1 / buffer.readFloatLE(0) < 0);
buffer[0] = 0;
buffer[1] = 0;
buffer[2] = 0x80;
buffer[3] = 0x7f;
ASSERT.equal(4.609571298396486e-41, buffer.readFloatBE(0));
ASSERT.equal(Infinity, buffer.readFloatLE(0));
assert.equal(4.609571298396486e-41, buffer.readFloatBE(0));
assert.equal(Infinity, buffer.readFloatLE(0));
buffer[0] = 0;
buffer[1] = 0;
buffer[2] = 0x80;
buffer[3] = 0xff;
ASSERT.equal(4.627507918739843e-41, buffer.readFloatBE(0));
ASSERT.equal(-Infinity, buffer.readFloatLE(0));
assert.equal(4.627507918739843e-41, buffer.readFloatBE(0));
assert.equal(-Infinity, buffer.readFloatLE(0));
}

62
test/parallel/test-readint.js

@ -3,7 +3,7 @@
* Tests to verify we're reading in signed integers correctly
*/
require('../common');
var ASSERT = require('assert');
const assert = require('assert');
/*
* Test 8 bit signed integers
@ -12,19 +12,19 @@ function test8(clazz) {
var data = new clazz(4);
data[0] = 0x23;
ASSERT.equal(0x23, data.readInt8(0));
assert.equal(0x23, data.readInt8(0));
data[0] = 0xff;
ASSERT.equal(-1, data.readInt8(0));
assert.equal(-1, data.readInt8(0));
data[0] = 0x87;
data[1] = 0xab;
data[2] = 0x7c;
data[3] = 0xef;
ASSERT.equal(-121, data.readInt8(0));
ASSERT.equal(-85, data.readInt8(1));
ASSERT.equal(124, data.readInt8(2));
ASSERT.equal(-17, data.readInt8(3));
assert.equal(-121, data.readInt8(0));
assert.equal(-85, data.readInt8(1));
assert.equal(124, data.readInt8(2));
assert.equal(-17, data.readInt8(3));
}
@ -33,13 +33,13 @@ function test16(clazz) {
buffer[0] = 0x16;
buffer[1] = 0x79;
ASSERT.equal(0x1679, buffer.readInt16BE(0));
ASSERT.equal(0x7916, buffer.readInt16LE(0));
assert.equal(0x1679, buffer.readInt16BE(0));
assert.equal(0x7916, buffer.readInt16LE(0));
buffer[0] = 0xff;
buffer[1] = 0x80;
ASSERT.equal(-128, buffer.readInt16BE(0));
ASSERT.equal(-32513, buffer.readInt16LE(0));
assert.equal(-128, buffer.readInt16BE(0));
assert.equal(-32513, buffer.readInt16LE(0));
/* test offset with weenix */
buffer[0] = 0x77;
@ -48,16 +48,16 @@ function test16(clazz) {
buffer[3] = 0x6e;
buffer[4] = 0x69;
buffer[5] = 0x78;
ASSERT.equal(0x7765, buffer.readInt16BE(0));
ASSERT.equal(0x6565, buffer.readInt16BE(1));
ASSERT.equal(0x656e, buffer.readInt16BE(2));
ASSERT.equal(0x6e69, buffer.readInt16BE(3));
ASSERT.equal(0x6978, buffer.readInt16BE(4));
ASSERT.equal(0x6577, buffer.readInt16LE(0));
ASSERT.equal(0x6565, buffer.readInt16LE(1));
ASSERT.equal(0x6e65, buffer.readInt16LE(2));
ASSERT.equal(0x696e, buffer.readInt16LE(3));
ASSERT.equal(0x7869, buffer.readInt16LE(4));
assert.equal(0x7765, buffer.readInt16BE(0));
assert.equal(0x6565, buffer.readInt16BE(1));
assert.equal(0x656e, buffer.readInt16BE(2));
assert.equal(0x6e69, buffer.readInt16BE(3));
assert.equal(0x6978, buffer.readInt16BE(4));
assert.equal(0x6577, buffer.readInt16LE(0));
assert.equal(0x6565, buffer.readInt16LE(1));
assert.equal(0x6e65, buffer.readInt16LE(2));
assert.equal(0x696e, buffer.readInt16LE(3));
assert.equal(0x7869, buffer.readInt16LE(4));
}
@ -68,15 +68,15 @@ function test32(clazz) {
buffer[1] = 0x53;
buffer[2] = 0x16;
buffer[3] = 0x79;
ASSERT.equal(0x43531679, buffer.readInt32BE(0));
ASSERT.equal(0x79165343, buffer.readInt32LE(0));
assert.equal(0x43531679, buffer.readInt32BE(0));
assert.equal(0x79165343, buffer.readInt32LE(0));
buffer[0] = 0xff;
buffer[1] = 0xfe;
buffer[2] = 0xef;
buffer[3] = 0xfa;
ASSERT.equal(-69638, buffer.readInt32BE(0));
ASSERT.equal(-84934913, buffer.readInt32LE(0));
assert.equal(-69638, buffer.readInt32BE(0));
assert.equal(-84934913, buffer.readInt32LE(0));
buffer[0] = 0x42;
buffer[1] = 0xc3;
@ -84,12 +84,12 @@ function test32(clazz) {
buffer[3] = 0xa9;
buffer[4] = 0x36;
buffer[5] = 0x17;
ASSERT.equal(0x42c395a9, buffer.readInt32BE(0));
ASSERT.equal(-1013601994, buffer.readInt32BE(1));
ASSERT.equal(-1784072681, buffer.readInt32BE(2));
ASSERT.equal(-1449802942, buffer.readInt32LE(0));
ASSERT.equal(917083587, buffer.readInt32LE(1));
ASSERT.equal(389458325, buffer.readInt32LE(2));
assert.equal(0x42c395a9, buffer.readInt32BE(0));
assert.equal(-1013601994, buffer.readInt32BE(1));
assert.equal(-1784072681, buffer.readInt32BE(2));
assert.equal(-1449802942, buffer.readInt32LE(0));
assert.equal(917083587, buffer.readInt32LE(1));
assert.equal(389458325, buffer.readInt32LE(2));
}

40
test/parallel/test-readuint.js

@ -4,7 +4,7 @@
*/
require('../common');
var ASSERT = require('assert');
const assert = require('assert');
/*
* We need to check the following things:
@ -20,13 +20,13 @@ function test8(clazz) {
data[1] = 23;
data[2] = 23;
data[3] = 23;
ASSERT.equal(23, data.readUInt8(0));
ASSERT.equal(23, data.readUInt8(1));
ASSERT.equal(23, data.readUInt8(2));
ASSERT.equal(23, data.readUInt8(3));
assert.equal(23, data.readUInt8(0));
assert.equal(23, data.readUInt8(1));
assert.equal(23, data.readUInt8(2));
assert.equal(23, data.readUInt8(3));
data[0] = 255; /* If it became a signed int, would be -1 */
ASSERT.equal(255, data.readUInt8(0));
assert.equal(255, data.readUInt8(0));
}
@ -45,17 +45,17 @@ function test16(clazz) {
data[1] = 0x23;
data[2] = 0x42;
data[3] = 0x3f;
ASSERT.equal(0x23, data.readUInt16BE(0));
ASSERT.equal(0x2342, data.readUInt16BE(1));
ASSERT.equal(0x423f, data.readUInt16BE(2));
ASSERT.equal(0x2300, data.readUInt16LE(0));
ASSERT.equal(0x4223, data.readUInt16LE(1));
ASSERT.equal(0x3f42, data.readUInt16LE(2));
assert.equal(0x23, data.readUInt16BE(0));
assert.equal(0x2342, data.readUInt16BE(1));
assert.equal(0x423f, data.readUInt16BE(2));
assert.equal(0x2300, data.readUInt16LE(0));
assert.equal(0x4223, data.readUInt16LE(1));
assert.equal(0x3f42, data.readUInt16LE(2));
data[0] = 0xfe;
data[1] = 0xfe;
ASSERT.equal(0xfefe, data.readUInt16BE(0));
ASSERT.equal(0xfefe, data.readUInt16LE(0));
assert.equal(0xfefe, data.readUInt16BE(0));
assert.equal(0xfefe, data.readUInt16LE(0));
}
@ -75,12 +75,12 @@ function test32(clazz) {
data[3] = 0x56;
data[4] = 0x23;
data[5] = 0xff;
ASSERT.equal(0x32654256, data.readUInt32BE(0));
ASSERT.equal(0x65425623, data.readUInt32BE(1));
ASSERT.equal(0x425623ff, data.readUInt32BE(2));
ASSERT.equal(0x56426532, data.readUInt32LE(0));
ASSERT.equal(0x23564265, data.readUInt32LE(1));
ASSERT.equal(0xff235642, data.readUInt32LE(2));
assert.equal(0x32654256, data.readUInt32BE(0));
assert.equal(0x65425623, data.readUInt32BE(1));
assert.equal(0x425623ff, data.readUInt32BE(2));
assert.equal(0x56426532, data.readUInt32LE(0));
assert.equal(0x23564265, data.readUInt32LE(1));
assert.equal(0xff235642, data.readUInt32LE(2));
}

270
test/parallel/test-writedouble.js

@ -3,173 +3,173 @@
* Tests to verify we're writing doubles correctly
*/
require('../common');
var ASSERT = require('assert');
const assert = require('assert');
function test(clazz) {
var buffer = new clazz(16);
buffer.writeDoubleBE(2.225073858507201e-308, 0);
buffer.writeDoubleLE(2.225073858507201e-308, 8);
ASSERT.equal(0x00, buffer[0]);
ASSERT.equal(0x0f, buffer[1]);
ASSERT.equal(0xff, buffer[2]);
ASSERT.equal(0xff, buffer[3]);
ASSERT.equal(0xff, buffer[4]);
ASSERT.equal(0xff, buffer[5]);
ASSERT.equal(0xff, buffer[6]);
ASSERT.equal(0xff, buffer[7]);
ASSERT.equal(0xff, buffer[8]);
ASSERT.equal(0xff, buffer[9]);
ASSERT.equal(0xff, buffer[10]);
ASSERT.equal(0xff, buffer[11]);
ASSERT.equal(0xff, buffer[12]);
ASSERT.equal(0xff, buffer[13]);
ASSERT.equal(0x0f, buffer[14]);
ASSERT.equal(0x00, buffer[15]);
assert.equal(0x00, buffer[0]);
assert.equal(0x0f, buffer[1]);
assert.equal(0xff, buffer[2]);
assert.equal(0xff, buffer[3]);
assert.equal(0xff, buffer[4]);
assert.equal(0xff, buffer[5]);
assert.equal(0xff, buffer[6]);
assert.equal(0xff, buffer[7]);
assert.equal(0xff, buffer[8]);
assert.equal(0xff, buffer[9]);
assert.equal(0xff, buffer[10]);
assert.equal(0xff, buffer[11]);
assert.equal(0xff, buffer[12]);
assert.equal(0xff, buffer[13]);
assert.equal(0x0f, buffer[14]);
assert.equal(0x00, buffer[15]);
buffer.writeDoubleBE(1.0000000000000004, 0);
buffer.writeDoubleLE(1.0000000000000004, 8);
ASSERT.equal(0x3f, buffer[0]);
ASSERT.equal(0xf0, buffer[1]);
ASSERT.equal(0x00, buffer[2]);
ASSERT.equal(0x00, buffer[3]);
ASSERT.equal(0x00, buffer[4]);
ASSERT.equal(0x00, buffer[5]);
ASSERT.equal(0x00, buffer[6]);
ASSERT.equal(0x02, buffer[7]);
ASSERT.equal(0x02, buffer[8]);
ASSERT.equal(0x00, buffer[9]);
ASSERT.equal(0x00, buffer[10]);
ASSERT.equal(0x00, buffer[11]);
ASSERT.equal(0x00, buffer[12]);
ASSERT.equal(0x00, buffer[13]);
ASSERT.equal(0xf0, buffer[14]);
ASSERT.equal(0x3f, buffer[15]);
assert.equal(0x3f, buffer[0]);
assert.equal(0xf0, buffer[1]);
assert.equal(0x00, buffer[2]);
assert.equal(0x00, buffer[3]);
assert.equal(0x00, buffer[4]);
assert.equal(0x00, buffer[5]);
assert.equal(0x00, buffer[6]);
assert.equal(0x02, buffer[7]);
assert.equal(0x02, buffer[8]);
assert.equal(0x00, buffer[9]);
assert.equal(0x00, buffer[10]);
assert.equal(0x00, buffer[11]);
assert.equal(0x00, buffer[12]);
assert.equal(0x00, buffer[13]);
assert.equal(0xf0, buffer[14]);
assert.equal(0x3f, buffer[15]);
buffer.writeDoubleBE(-2, 0);
buffer.writeDoubleLE(-2, 8);
ASSERT.equal(0xc0, buffer[0]);
ASSERT.equal(0x00, buffer[1]);
ASSERT.equal(0x00, buffer[2]);
ASSERT.equal(0x00, buffer[3]);
ASSERT.equal(0x00, buffer[4]);
ASSERT.equal(0x00, buffer[5]);
ASSERT.equal(0x00, buffer[6]);
ASSERT.equal(0x00, buffer[7]);
ASSERT.equal(0x00, buffer[8]);
ASSERT.equal(0x00, buffer[9]);
ASSERT.equal(0x00, buffer[10]);
ASSERT.equal(0x00, buffer[11]);
ASSERT.equal(0x00, buffer[12]);
ASSERT.equal(0x00, buffer[13]);
ASSERT.equal(0x00, buffer[14]);
ASSERT.equal(0xc0, buffer[15]);
assert.equal(0xc0, buffer[0]);
assert.equal(0x00, buffer[1]);
assert.equal(0x00, buffer[2]);
assert.equal(0x00, buffer[3]);
assert.equal(0x00, buffer[4]);
assert.equal(0x00, buffer[5]);
assert.equal(0x00, buffer[6]);
assert.equal(0x00, buffer[7]);
assert.equal(0x00, buffer[8]);
assert.equal(0x00, buffer[9]);
assert.equal(0x00, buffer[10]);
assert.equal(0x00, buffer[11]);
assert.equal(0x00, buffer[12]);
assert.equal(0x00, buffer[13]);
assert.equal(0x00, buffer[14]);
assert.equal(0xc0, buffer[15]);
buffer.writeDoubleBE(1.7976931348623157e+308, 0);
buffer.writeDoubleLE(1.7976931348623157e+308, 8);
ASSERT.equal(0x7f, buffer[0]);
ASSERT.equal(0xef, buffer[1]);
ASSERT.equal(0xff, buffer[2]);
ASSERT.equal(0xff, buffer[3]);
ASSERT.equal(0xff, buffer[4]);
ASSERT.equal(0xff, buffer[5]);
ASSERT.equal(0xff, buffer[6]);
ASSERT.equal(0xff, buffer[7]);
ASSERT.equal(0xff, buffer[8]);
ASSERT.equal(0xff, buffer[9]);
ASSERT.equal(0xff, buffer[10]);
ASSERT.equal(0xff, buffer[11]);
ASSERT.equal(0xff, buffer[12]);
ASSERT.equal(0xff, buffer[13]);
ASSERT.equal(0xef, buffer[14]);
ASSERT.equal(0x7f, buffer[15]);
assert.equal(0x7f, buffer[0]);
assert.equal(0xef, buffer[1]);
assert.equal(0xff, buffer[2]);
assert.equal(0xff, buffer[3]);
assert.equal(0xff, buffer[4]);
assert.equal(0xff, buffer[5]);
assert.equal(0xff, buffer[6]);
assert.equal(0xff, buffer[7]);
assert.equal(0xff, buffer[8]);
assert.equal(0xff, buffer[9]);
assert.equal(0xff, buffer[10]);
assert.equal(0xff, buffer[11]);
assert.equal(0xff, buffer[12]);
assert.equal(0xff, buffer[13]);
assert.equal(0xef, buffer[14]);
assert.equal(0x7f, buffer[15]);
buffer.writeDoubleBE(0 * -1, 0);
buffer.writeDoubleLE(0 * -1, 8);
ASSERT.equal(0x80, buffer[0]);
ASSERT.equal(0x00, buffer[1]);
ASSERT.equal(0x00, buffer[2]);
ASSERT.equal(0x00, buffer[3]);
ASSERT.equal(0x00, buffer[4]);
ASSERT.equal(0x00, buffer[5]);
ASSERT.equal(0x00, buffer[6]);
ASSERT.equal(0x00, buffer[7]);
ASSERT.equal(0x00, buffer[8]);
ASSERT.equal(0x00, buffer[9]);
ASSERT.equal(0x00, buffer[10]);
ASSERT.equal(0x00, buffer[11]);
ASSERT.equal(0x00, buffer[12]);
ASSERT.equal(0x00, buffer[13]);
ASSERT.equal(0x00, buffer[14]);
ASSERT.equal(0x80, buffer[15]);
assert.equal(0x80, buffer[0]);
assert.equal(0x00, buffer[1]);
assert.equal(0x00, buffer[2]);
assert.equal(0x00, buffer[3]);
assert.equal(0x00, buffer[4]);
assert.equal(0x00, buffer[5]);
assert.equal(0x00, buffer[6]);
assert.equal(0x00, buffer[7]);
assert.equal(0x00, buffer[8]);
assert.equal(0x00, buffer[9]);
assert.equal(0x00, buffer[10]);
assert.equal(0x00, buffer[11]);
assert.equal(0x00, buffer[12]);
assert.equal(0x00, buffer[13]);
assert.equal(0x00, buffer[14]);
assert.equal(0x80, buffer[15]);
buffer.writeDoubleBE(Infinity, 0);
buffer.writeDoubleLE(Infinity, 8);
ASSERT.equal(0x7F, buffer[0]);
ASSERT.equal(0xF0, buffer[1]);
ASSERT.equal(0x00, buffer[2]);
ASSERT.equal(0x00, buffer[3]);
ASSERT.equal(0x00, buffer[4]);
ASSERT.equal(0x00, buffer[5]);
ASSERT.equal(0x00, buffer[6]);
ASSERT.equal(0x00, buffer[7]);
ASSERT.equal(0x00, buffer[8]);
ASSERT.equal(0x00, buffer[9]);
ASSERT.equal(0x00, buffer[10]);
ASSERT.equal(0x00, buffer[11]);
ASSERT.equal(0x00, buffer[12]);
ASSERT.equal(0x00, buffer[13]);
ASSERT.equal(0xF0, buffer[14]);
ASSERT.equal(0x7F, buffer[15]);
ASSERT.equal(Infinity, buffer.readDoubleBE(0));
ASSERT.equal(Infinity, buffer.readDoubleLE(8));
assert.equal(0x7F, buffer[0]);
assert.equal(0xF0, buffer[1]);
assert.equal(0x00, buffer[2]);
assert.equal(0x00, buffer[3]);
assert.equal(0x00, buffer[4]);
assert.equal(0x00, buffer[5]);
assert.equal(0x00, buffer[6]);
assert.equal(0x00, buffer[7]);
assert.equal(0x00, buffer[8]);
assert.equal(0x00, buffer[9]);
assert.equal(0x00, buffer[10]);
assert.equal(0x00, buffer[11]);
assert.equal(0x00, buffer[12]);
assert.equal(0x00, buffer[13]);
assert.equal(0xF0, buffer[14]);
assert.equal(0x7F, buffer[15]);
assert.equal(Infinity, buffer.readDoubleBE(0));
assert.equal(Infinity, buffer.readDoubleLE(8));
buffer.writeDoubleBE(-Infinity, 0);
buffer.writeDoubleLE(-Infinity, 8);
ASSERT.equal(0xFF, buffer[0]);
ASSERT.equal(0xF0, buffer[1]);
ASSERT.equal(0x00, buffer[2]);
ASSERT.equal(0x00, buffer[3]);
ASSERT.equal(0x00, buffer[4]);
ASSERT.equal(0x00, buffer[5]);
ASSERT.equal(0x00, buffer[6]);
ASSERT.equal(0x00, buffer[7]);
ASSERT.equal(0x00, buffer[8]);
ASSERT.equal(0x00, buffer[9]);
ASSERT.equal(0x00, buffer[10]);
ASSERT.equal(0x00, buffer[11]);
ASSERT.equal(0x00, buffer[12]);
ASSERT.equal(0x00, buffer[13]);
ASSERT.equal(0xF0, buffer[14]);
ASSERT.equal(0xFF, buffer[15]);
ASSERT.equal(-Infinity, buffer.readDoubleBE(0));
ASSERT.equal(-Infinity, buffer.readDoubleLE(8));
assert.equal(0xFF, buffer[0]);
assert.equal(0xF0, buffer[1]);
assert.equal(0x00, buffer[2]);
assert.equal(0x00, buffer[3]);
assert.equal(0x00, buffer[4]);
assert.equal(0x00, buffer[5]);
assert.equal(0x00, buffer[6]);
assert.equal(0x00, buffer[7]);
assert.equal(0x00, buffer[8]);
assert.equal(0x00, buffer[9]);
assert.equal(0x00, buffer[10]);
assert.equal(0x00, buffer[11]);
assert.equal(0x00, buffer[12]);
assert.equal(0x00, buffer[13]);
assert.equal(0xF0, buffer[14]);
assert.equal(0xFF, buffer[15]);
assert.equal(-Infinity, buffer.readDoubleBE(0));
assert.equal(-Infinity, buffer.readDoubleLE(8));
buffer.writeDoubleBE(NaN, 0);
buffer.writeDoubleLE(NaN, 8);
// Darwin ia32 does the other kind of NaN.
// Compiler bug. No one really cares.
ASSERT(0x7F === buffer[0] || 0xFF === buffer[0]);
assert(0x7F === buffer[0] || 0xFF === buffer[0]);
// mips processors use a slightly different NaN
ASSERT(0xF8 === buffer[1] || 0xF7 === buffer[1]);
ASSERT(0x00 === buffer[2] || 0xFF === buffer[2]);
ASSERT(0x00 === buffer[3] || 0xFF === buffer[3]);
ASSERT(0x00 === buffer[4] || 0xFF === buffer[4]);
ASSERT(0x00 === buffer[5] || 0xFF === buffer[5]);
ASSERT(0x00 === buffer[6] || 0xFF === buffer[6]);
ASSERT(0x00 === buffer[7] || 0xFF === buffer[7]);
ASSERT(0x00 === buffer[8] || 0xFF === buffer[8]);
ASSERT(0x00 === buffer[9] || 0xFF === buffer[9]);
ASSERT(0x00 === buffer[10] || 0xFF === buffer[10]);
ASSERT(0x00 === buffer[11] || 0xFF === buffer[11]);
ASSERT(0x00 === buffer[12] || 0xFF === buffer[12]);
ASSERT(0x00 === buffer[13] || 0xFF === buffer[13]);
ASSERT(0xF8 === buffer[14] || 0xF7 === buffer[14]);
assert(0xF8 === buffer[1] || 0xF7 === buffer[1]);
assert(0x00 === buffer[2] || 0xFF === buffer[2]);
assert(0x00 === buffer[3] || 0xFF === buffer[3]);
assert(0x00 === buffer[4] || 0xFF === buffer[4]);
assert(0x00 === buffer[5] || 0xFF === buffer[5]);
assert(0x00 === buffer[6] || 0xFF === buffer[6]);
assert(0x00 === buffer[7] || 0xFF === buffer[7]);
assert(0x00 === buffer[8] || 0xFF === buffer[8]);
assert(0x00 === buffer[9] || 0xFF === buffer[9]);
assert(0x00 === buffer[10] || 0xFF === buffer[10]);
assert(0x00 === buffer[11] || 0xFF === buffer[11]);
assert(0x00 === buffer[12] || 0xFF === buffer[12]);
assert(0x00 === buffer[13] || 0xFF === buffer[13]);
assert(0xF8 === buffer[14] || 0xF7 === buffer[14]);
// Darwin ia32 does the other kind of NaN.
// Compiler bug. No one really cares.
ASSERT(0x7F === buffer[15] || 0xFF === buffer[15]);
ASSERT.ok(isNaN(buffer.readDoubleBE(0)));
ASSERT.ok(isNaN(buffer.readDoubleLE(8)));
assert(0x7F === buffer[15] || 0xFF === buffer[15]);
assert.ok(isNaN(buffer.readDoubleBE(0)));
assert.ok(isNaN(buffer.readDoubleLE(8)));
}

142
test/parallel/test-writefloat.js

@ -3,111 +3,111 @@
* Tests to verify we're writing floats correctly
*/
require('../common');
var ASSERT = require('assert');
const assert = require('assert');
function test(clazz) {
var buffer = new clazz(8);
buffer.writeFloatBE(1, 0);
buffer.writeFloatLE(1, 4);
ASSERT.equal(0x3f, buffer[0]);
ASSERT.equal(0x80, buffer[1]);
ASSERT.equal(0x00, buffer[2]);
ASSERT.equal(0x00, buffer[3]);
ASSERT.equal(0x00, buffer[4]);
ASSERT.equal(0x00, buffer[5]);
ASSERT.equal(0x80, buffer[6]);
ASSERT.equal(0x3f, buffer[7]);
assert.equal(0x3f, buffer[0]);
assert.equal(0x80, buffer[1]);
assert.equal(0x00, buffer[2]);
assert.equal(0x00, buffer[3]);
assert.equal(0x00, buffer[4]);
assert.equal(0x00, buffer[5]);
assert.equal(0x80, buffer[6]);
assert.equal(0x3f, buffer[7]);
buffer.writeFloatBE(1 / 3, 0);
buffer.writeFloatLE(1 / 3, 4);
ASSERT.equal(0x3e, buffer[0]);
ASSERT.equal(0xaa, buffer[1]);
ASSERT.equal(0xaa, buffer[2]);
ASSERT.equal(0xab, buffer[3]);
ASSERT.equal(0xab, buffer[4]);
ASSERT.equal(0xaa, buffer[5]);
ASSERT.equal(0xaa, buffer[6]);
ASSERT.equal(0x3e, buffer[7]);
assert.equal(0x3e, buffer[0]);
assert.equal(0xaa, buffer[1]);
assert.equal(0xaa, buffer[2]);
assert.equal(0xab, buffer[3]);
assert.equal(0xab, buffer[4]);
assert.equal(0xaa, buffer[5]);
assert.equal(0xaa, buffer[6]);
assert.equal(0x3e, buffer[7]);
buffer.writeFloatBE(3.4028234663852886e+38, 0);
buffer.writeFloatLE(3.4028234663852886e+38, 4);
ASSERT.equal(0x7f, buffer[0]);
ASSERT.equal(0x7f, buffer[1]);
ASSERT.equal(0xff, buffer[2]);
ASSERT.equal(0xff, buffer[3]);
ASSERT.equal(0xff, buffer[4]);
ASSERT.equal(0xff, buffer[5]);
ASSERT.equal(0x7f, buffer[6]);
ASSERT.equal(0x7f, buffer[7]);
assert.equal(0x7f, buffer[0]);
assert.equal(0x7f, buffer[1]);
assert.equal(0xff, buffer[2]);
assert.equal(0xff, buffer[3]);
assert.equal(0xff, buffer[4]);
assert.equal(0xff, buffer[5]);
assert.equal(0x7f, buffer[6]);
assert.equal(0x7f, buffer[7]);
buffer.writeFloatLE(1.1754943508222875e-38, 0);
buffer.writeFloatBE(1.1754943508222875e-38, 4);
ASSERT.equal(0x00, buffer[0]);
ASSERT.equal(0x00, buffer[1]);
ASSERT.equal(0x80, buffer[2]);
ASSERT.equal(0x00, buffer[3]);
ASSERT.equal(0x00, buffer[4]);
ASSERT.equal(0x80, buffer[5]);
ASSERT.equal(0x00, buffer[6]);
ASSERT.equal(0x00, buffer[7]);
assert.equal(0x00, buffer[0]);
assert.equal(0x00, buffer[1]);
assert.equal(0x80, buffer[2]);
assert.equal(0x00, buffer[3]);
assert.equal(0x00, buffer[4]);
assert.equal(0x80, buffer[5]);
assert.equal(0x00, buffer[6]);
assert.equal(0x00, buffer[7]);
buffer.writeFloatBE(0 * -1, 0);
buffer.writeFloatLE(0 * -1, 4);
ASSERT.equal(0x80, buffer[0]);
ASSERT.equal(0x00, buffer[1]);
ASSERT.equal(0x00, buffer[2]);
ASSERT.equal(0x00, buffer[3]);
ASSERT.equal(0x00, buffer[4]);
ASSERT.equal(0x00, buffer[5]);
ASSERT.equal(0x00, buffer[6]);
ASSERT.equal(0x80, buffer[7]);
assert.equal(0x80, buffer[0]);
assert.equal(0x00, buffer[1]);
assert.equal(0x00, buffer[2]);
assert.equal(0x00, buffer[3]);
assert.equal(0x00, buffer[4]);
assert.equal(0x00, buffer[5]);
assert.equal(0x00, buffer[6]);
assert.equal(0x80, buffer[7]);
buffer.writeFloatBE(Infinity, 0);
buffer.writeFloatLE(Infinity, 4);
ASSERT.equal(0x7F, buffer[0]);
ASSERT.equal(0x80, buffer[1]);
ASSERT.equal(0x00, buffer[2]);
ASSERT.equal(0x00, buffer[3]);
ASSERT.equal(0x00, buffer[4]);
ASSERT.equal(0x00, buffer[5]);
ASSERT.equal(0x80, buffer[6]);
ASSERT.equal(0x7F, buffer[7]);
ASSERT.equal(Infinity, buffer.readFloatBE(0));
ASSERT.equal(Infinity, buffer.readFloatLE(4));
assert.equal(0x7F, buffer[0]);
assert.equal(0x80, buffer[1]);
assert.equal(0x00, buffer[2]);
assert.equal(0x00, buffer[3]);
assert.equal(0x00, buffer[4]);
assert.equal(0x00, buffer[5]);
assert.equal(0x80, buffer[6]);
assert.equal(0x7F, buffer[7]);
assert.equal(Infinity, buffer.readFloatBE(0));
assert.equal(Infinity, buffer.readFloatLE(4));
buffer.writeFloatBE(-Infinity, 0);
buffer.writeFloatLE(-Infinity, 4);
// Darwin ia32 does the other kind of NaN.
// Compiler bug. No one really cares.
ASSERT(0xFF === buffer[0] || 0x7F === buffer[0]);
ASSERT.equal(0x80, buffer[1]);
ASSERT.equal(0x00, buffer[2]);
ASSERT.equal(0x00, buffer[3]);
ASSERT.equal(0x00, buffer[4]);
ASSERT.equal(0x00, buffer[5]);
ASSERT.equal(0x80, buffer[6]);
ASSERT.equal(0xFF, buffer[7]);
ASSERT.equal(-Infinity, buffer.readFloatBE(0));
ASSERT.equal(-Infinity, buffer.readFloatLE(4));
assert(0xFF === buffer[0] || 0x7F === buffer[0]);
assert.equal(0x80, buffer[1]);
assert.equal(0x00, buffer[2]);
assert.equal(0x00, buffer[3]);
assert.equal(0x00, buffer[4]);
assert.equal(0x00, buffer[5]);
assert.equal(0x80, buffer[6]);
assert.equal(0xFF, buffer[7]);
assert.equal(-Infinity, buffer.readFloatBE(0));
assert.equal(-Infinity, buffer.readFloatLE(4));
buffer.writeFloatBE(NaN, 0);
buffer.writeFloatLE(NaN, 4);
// Darwin ia32 does the other kind of NaN.
// Compiler bug. No one really cares.
ASSERT(0x7F === buffer[0] || 0xFF === buffer[0]);
assert(0x7F === buffer[0] || 0xFF === buffer[0]);
// mips processors use a slightly different NaN
ASSERT(0xC0 === buffer[1] || 0xBF === buffer[1]);
ASSERT(0x00 === buffer[2] || 0xFF === buffer[2]);
ASSERT(0x00 === buffer[3] || 0xFF === buffer[3]);
ASSERT(0x00 === buffer[4] || 0xFF === buffer[4]);
ASSERT(0x00 === buffer[5] || 0xFF === buffer[5]);
ASSERT(0xC0 === buffer[6] || 0xBF === buffer[6]);
assert(0xC0 === buffer[1] || 0xBF === buffer[1]);
assert(0x00 === buffer[2] || 0xFF === buffer[2]);
assert(0x00 === buffer[3] || 0xFF === buffer[3]);
assert(0x00 === buffer[4] || 0xFF === buffer[4]);
assert(0x00 === buffer[5] || 0xFF === buffer[5]);
assert(0xC0 === buffer[6] || 0xBF === buffer[6]);
// Darwin ia32 does the other kind of NaN.
// Compiler bug. No one really cares.
ASSERT(0x7F === buffer[7] || 0xFF === buffer[7]);
ASSERT.ok(isNaN(buffer.readFloatBE(0)));
ASSERT.ok(isNaN(buffer.readFloatLE(4)));
assert(0x7F === buffer[7] || 0xFF === buffer[7]);
assert.ok(isNaN(buffer.readFloatBE(0)));
assert.ok(isNaN(buffer.readFloatLE(4)));
}

154
test/parallel/test-writeint.js

@ -3,7 +3,7 @@
* Tests to verify we're writing signed integers correctly
*/
require('../common');
var ASSERT = require('assert');
const assert = require('assert');
function test8(clazz) {
var buffer = new clazz(2);
@ -11,14 +11,14 @@ function test8(clazz) {
buffer.writeInt8(0x23, 0);
buffer.writeInt8(-5, 1);
ASSERT.equal(0x23, buffer[0]);
ASSERT.equal(0xfb, buffer[1]);
assert.equal(0x23, buffer[0]);
assert.equal(0xfb, buffer[1]);
/* Make sure we handle truncation correctly */
ASSERT.throws(function() {
assert.throws(function() {
buffer.writeInt8(0xabc, 0);
});
ASSERT.throws(function() {
assert.throws(function() {
buffer.writeInt8(0xabc, 0);
});
@ -26,12 +26,12 @@ function test8(clazz) {
buffer.writeInt8(0x7f, 0);
buffer.writeInt8(-0x80, 1);
ASSERT.equal(0x7f, buffer[0]);
ASSERT.equal(0x80, buffer[1]);
ASSERT.throws(function() {
assert.equal(0x7f, buffer[0]);
assert.equal(0x80, buffer[1]);
assert.throws(function() {
buffer.writeInt8(0x7f + 1, 0);
});
ASSERT.throws(function() {
assert.throws(function() {
buffer.writeInt8(-0x80 - 1, 0);
});
}
@ -42,49 +42,49 @@ function test16(clazz) {
buffer.writeInt16BE(0x0023, 0);
buffer.writeInt16LE(0x0023, 2);
ASSERT.equal(0x00, buffer[0]);
ASSERT.equal(0x23, buffer[1]);
ASSERT.equal(0x23, buffer[2]);
ASSERT.equal(0x00, buffer[3]);
assert.equal(0x00, buffer[0]);
assert.equal(0x23, buffer[1]);
assert.equal(0x23, buffer[2]);
assert.equal(0x00, buffer[3]);
buffer.writeInt16BE(-5, 0);
buffer.writeInt16LE(-5, 2);
ASSERT.equal(0xff, buffer[0]);
ASSERT.equal(0xfb, buffer[1]);
ASSERT.equal(0xfb, buffer[2]);
ASSERT.equal(0xff, buffer[3]);
assert.equal(0xff, buffer[0]);
assert.equal(0xfb, buffer[1]);
assert.equal(0xfb, buffer[2]);
assert.equal(0xff, buffer[3]);
buffer.writeInt16BE(-1679, 1);
buffer.writeInt16LE(-1679, 3);
ASSERT.equal(0xf9, buffer[1]);
ASSERT.equal(0x71, buffer[2]);
ASSERT.equal(0x71, buffer[3]);
ASSERT.equal(0xf9, buffer[4]);
assert.equal(0xf9, buffer[1]);
assert.equal(0x71, buffer[2]);
assert.equal(0x71, buffer[3]);
assert.equal(0xf9, buffer[4]);
/* Make sure we handle min/max correctly */
buffer.writeInt16BE(0x7fff, 0);
buffer.writeInt16BE(-0x8000, 2);
ASSERT.equal(0x7f, buffer[0]);
ASSERT.equal(0xff, buffer[1]);
ASSERT.equal(0x80, buffer[2]);
ASSERT.equal(0x00, buffer[3]);
ASSERT.throws(function() {
assert.equal(0x7f, buffer[0]);
assert.equal(0xff, buffer[1]);
assert.equal(0x80, buffer[2]);
assert.equal(0x00, buffer[3]);
assert.throws(function() {
buffer.writeInt16BE(0x7fff + 1, 0);
});
ASSERT.throws(function() {
assert.throws(function() {
buffer.writeInt16BE(-0x8000 - 1, 0);
});
buffer.writeInt16LE(0x7fff, 0);
buffer.writeInt16LE(-0x8000, 2);
ASSERT.equal(0xff, buffer[0]);
ASSERT.equal(0x7f, buffer[1]);
ASSERT.equal(0x00, buffer[2]);
ASSERT.equal(0x80, buffer[3]);
ASSERT.throws(function() {
assert.equal(0xff, buffer[0]);
assert.equal(0x7f, buffer[1]);
assert.equal(0x00, buffer[2]);
assert.equal(0x80, buffer[3]);
assert.throws(function() {
buffer.writeInt16LE(0x7fff + 1, 0);
});
ASSERT.throws(function() {
assert.throws(function() {
buffer.writeInt16LE(-0x8000 - 1, 0);
});
}
@ -95,69 +95,69 @@ function test32(clazz) {
buffer.writeInt32BE(0x23, 0);
buffer.writeInt32LE(0x23, 4);
ASSERT.equal(0x00, buffer[0]);
ASSERT.equal(0x00, buffer[1]);
ASSERT.equal(0x00, buffer[2]);
ASSERT.equal(0x23, buffer[3]);
ASSERT.equal(0x23, buffer[4]);
ASSERT.equal(0x00, buffer[5]);
ASSERT.equal(0x00, buffer[6]);
ASSERT.equal(0x00, buffer[7]);
assert.equal(0x00, buffer[0]);
assert.equal(0x00, buffer[1]);
assert.equal(0x00, buffer[2]);
assert.equal(0x23, buffer[3]);
assert.equal(0x23, buffer[4]);
assert.equal(0x00, buffer[5]);
assert.equal(0x00, buffer[6]);
assert.equal(0x00, buffer[7]);
buffer.writeInt32BE(-5, 0);
buffer.writeInt32LE(-5, 4);
ASSERT.equal(0xff, buffer[0]);
ASSERT.equal(0xff, buffer[1]);
ASSERT.equal(0xff, buffer[2]);
ASSERT.equal(0xfb, buffer[3]);
ASSERT.equal(0xfb, buffer[4]);
ASSERT.equal(0xff, buffer[5]);
ASSERT.equal(0xff, buffer[6]);
ASSERT.equal(0xff, buffer[7]);
assert.equal(0xff, buffer[0]);
assert.equal(0xff, buffer[1]);
assert.equal(0xff, buffer[2]);
assert.equal(0xfb, buffer[3]);
assert.equal(0xfb, buffer[4]);
assert.equal(0xff, buffer[5]);
assert.equal(0xff, buffer[6]);
assert.equal(0xff, buffer[7]);
buffer.writeInt32BE(-805306713, 0);
buffer.writeInt32LE(-805306713, 4);
ASSERT.equal(0xcf, buffer[0]);
ASSERT.equal(0xff, buffer[1]);
ASSERT.equal(0xfe, buffer[2]);
ASSERT.equal(0xa7, buffer[3]);
ASSERT.equal(0xa7, buffer[4]);
ASSERT.equal(0xfe, buffer[5]);
ASSERT.equal(0xff, buffer[6]);
ASSERT.equal(0xcf, buffer[7]);
assert.equal(0xcf, buffer[0]);
assert.equal(0xff, buffer[1]);
assert.equal(0xfe, buffer[2]);
assert.equal(0xa7, buffer[3]);
assert.equal(0xa7, buffer[4]);
assert.equal(0xfe, buffer[5]);
assert.equal(0xff, buffer[6]);
assert.equal(0xcf, buffer[7]);
/* Make sure we handle min/max correctly */
buffer.writeInt32BE(0x7fffffff, 0);
buffer.writeInt32BE(-0x80000000, 4);
ASSERT.equal(0x7f, buffer[0]);
ASSERT.equal(0xff, buffer[1]);
ASSERT.equal(0xff, buffer[2]);
ASSERT.equal(0xff, buffer[3]);
ASSERT.equal(0x80, buffer[4]);
ASSERT.equal(0x00, buffer[5]);
ASSERT.equal(0x00, buffer[6]);
ASSERT.equal(0x00, buffer[7]);
ASSERT.throws(function() {
assert.equal(0x7f, buffer[0]);
assert.equal(0xff, buffer[1]);
assert.equal(0xff, buffer[2]);
assert.equal(0xff, buffer[3]);
assert.equal(0x80, buffer[4]);
assert.equal(0x00, buffer[5]);
assert.equal(0x00, buffer[6]);
assert.equal(0x00, buffer[7]);
assert.throws(function() {
buffer.writeInt32BE(0x7fffffff + 1, 0);
});
ASSERT.throws(function() {
assert.throws(function() {
buffer.writeInt32BE(-0x80000000 - 1, 0);
});
buffer.writeInt32LE(0x7fffffff, 0);
buffer.writeInt32LE(-0x80000000, 4);
ASSERT.equal(0xff, buffer[0]);
ASSERT.equal(0xff, buffer[1]);
ASSERT.equal(0xff, buffer[2]);
ASSERT.equal(0x7f, buffer[3]);
ASSERT.equal(0x00, buffer[4]);
ASSERT.equal(0x00, buffer[5]);
ASSERT.equal(0x00, buffer[6]);
ASSERT.equal(0x80, buffer[7]);
ASSERT.throws(function() {
assert.equal(0xff, buffer[0]);
assert.equal(0xff, buffer[1]);
assert.equal(0xff, buffer[2]);
assert.equal(0x7f, buffer[3]);
assert.equal(0x00, buffer[4]);
assert.equal(0x00, buffer[5]);
assert.equal(0x00, buffer[6]);
assert.equal(0x80, buffer[7]);
assert.throws(function() {
buffer.writeInt32LE(0x7fffffff + 1, 0);
});
ASSERT.throws(function() {
assert.throws(function() {
buffer.writeInt32LE(-0x80000000 - 1, 0);
});
}

106
test/parallel/test-writeuint.js

@ -3,7 +3,7 @@
* A battery of tests to help us read a series of uints
*/
require('../common');
var ASSERT = require('assert');
const assert = require('assert');
/*
* We need to check the following things:
@ -19,25 +19,25 @@ function test8(clazz) {
data.writeUInt8(23, 1);
data.writeUInt8(23, 2);
data.writeUInt8(23, 3);
ASSERT.equal(23, data[0]);
ASSERT.equal(23, data[1]);
ASSERT.equal(23, data[2]);
ASSERT.equal(23, data[3]);
assert.equal(23, data[0]);
assert.equal(23, data[1]);
assert.equal(23, data[2]);
assert.equal(23, data[3]);
data.writeUInt8(23, 0);
data.writeUInt8(23, 1);
data.writeUInt8(23, 2);
data.writeUInt8(23, 3);
ASSERT.equal(23, data[0]);
ASSERT.equal(23, data[1]);
ASSERT.equal(23, data[2]);
ASSERT.equal(23, data[3]);
assert.equal(23, data[0]);
assert.equal(23, data[1]);
assert.equal(23, data[2]);
assert.equal(23, data[3]);
data.writeUInt8(255, 0);
ASSERT.equal(255, data[0]);
assert.equal(255, data[0]);
data.writeUInt8(255, 0);
ASSERT.equal(255, data[0]);
assert.equal(255, data[0]);
}
@ -46,37 +46,37 @@ function test16(clazz) {
var data = new clazz(4);
data.writeUInt16BE(value, 0);
ASSERT.equal(0x23, data[0]);
ASSERT.equal(0x43, data[1]);
assert.equal(0x23, data[0]);
assert.equal(0x43, data[1]);
data.writeUInt16BE(value, 1);
ASSERT.equal(0x23, data[1]);
ASSERT.equal(0x43, data[2]);
assert.equal(0x23, data[1]);
assert.equal(0x43, data[2]);
data.writeUInt16BE(value, 2);
ASSERT.equal(0x23, data[2]);
ASSERT.equal(0x43, data[3]);
assert.equal(0x23, data[2]);
assert.equal(0x43, data[3]);
data.writeUInt16LE(value, 0);
ASSERT.equal(0x23, data[1]);
ASSERT.equal(0x43, data[0]);
assert.equal(0x23, data[1]);
assert.equal(0x43, data[0]);
data.writeUInt16LE(value, 1);
ASSERT.equal(0x23, data[2]);
ASSERT.equal(0x43, data[1]);
assert.equal(0x23, data[2]);
assert.equal(0x43, data[1]);
data.writeUInt16LE(value, 2);
ASSERT.equal(0x23, data[3]);
ASSERT.equal(0x43, data[2]);
assert.equal(0x23, data[3]);
assert.equal(0x43, data[2]);
value = 0xff80;
data.writeUInt16LE(value, 0);
ASSERT.equal(0xff, data[1]);
ASSERT.equal(0x80, data[0]);
assert.equal(0xff, data[1]);
assert.equal(0x80, data[0]);
data.writeUInt16BE(value, 0);
ASSERT.equal(0xff, data[0]);
ASSERT.equal(0x80, data[1]);
assert.equal(0xff, data[0]);
assert.equal(0x80, data[1]);
}
@ -85,40 +85,40 @@ function test32(clazz) {
var value = 0xe7f90a6d;
data.writeUInt32BE(value, 0);
ASSERT.equal(0xe7, data[0]);
ASSERT.equal(0xf9, data[1]);
ASSERT.equal(0x0a, data[2]);
ASSERT.equal(0x6d, data[3]);
assert.equal(0xe7, data[0]);
assert.equal(0xf9, data[1]);
assert.equal(0x0a, data[2]);
assert.equal(0x6d, data[3]);
data.writeUInt32BE(value, 1);
ASSERT.equal(0xe7, data[1]);
ASSERT.equal(0xf9, data[2]);
ASSERT.equal(0x0a, data[3]);
ASSERT.equal(0x6d, data[4]);
assert.equal(0xe7, data[1]);
assert.equal(0xf9, data[2]);
assert.equal(0x0a, data[3]);
assert.equal(0x6d, data[4]);
data.writeUInt32BE(value, 2);
ASSERT.equal(0xe7, data[2]);
ASSERT.equal(0xf9, data[3]);
ASSERT.equal(0x0a, data[4]);
ASSERT.equal(0x6d, data[5]);
assert.equal(0xe7, data[2]);
assert.equal(0xf9, data[3]);
assert.equal(0x0a, data[4]);
assert.equal(0x6d, data[5]);
data.writeUInt32LE(value, 0);
ASSERT.equal(0xe7, data[3]);
ASSERT.equal(0xf9, data[2]);
ASSERT.equal(0x0a, data[1]);
ASSERT.equal(0x6d, data[0]);
assert.equal(0xe7, data[3]);
assert.equal(0xf9, data[2]);
assert.equal(0x0a, data[1]);
assert.equal(0x6d, data[0]);
data.writeUInt32LE(value, 1);
ASSERT.equal(0xe7, data[4]);
ASSERT.equal(0xf9, data[3]);
ASSERT.equal(0x0a, data[2]);
ASSERT.equal(0x6d, data[1]);
assert.equal(0xe7, data[4]);
assert.equal(0xf9, data[3]);
assert.equal(0x0a, data[2]);
assert.equal(0x6d, data[1]);
data.writeUInt32LE(value, 2);
ASSERT.equal(0xe7, data[5]);
ASSERT.equal(0xf9, data[4]);
ASSERT.equal(0x0a, data[3]);
ASSERT.equal(0x6d, data[2]);
assert.equal(0xe7, data[5]);
assert.equal(0xf9, data[4]);
assert.equal(0x0a, data[3]);
assert.equal(0x6d, data[2]);
}
@ -129,10 +129,10 @@ function testUint(clazz) {
// Test 0 to 5 bytes.
for (var i = 0; i <= 5; i++) {
const errmsg = `byteLength: ${i}`;
ASSERT.throws(function() {
assert.throws(function() {
data.writeUIntBE(val, 0, i);
}, /"value" argument is out of bounds/, errmsg);
ASSERT.throws(function() {
assert.throws(function() {
data.writeUIntLE(val, 0, i);
}, /"value" argument is out of bounds/, errmsg);
val *= 0x100;

Loading…
Cancel
Save