Lines Matching refs:assert
4 const assert = require('assert'); constant
11 assert.throws(
17 assert.strictEqual(b.length, 1024);
20 assert.strictEqual(b[0], 255);
27 assert.strictEqual(i % 256, b[i]);
31 assert.strictEqual(c.length, 512);
34 assert.strictEqual(d.length, 0);
39 assert.strictEqual(b.length, 128);
40 assert.strictEqual(b.byteOffset, 0);
41 assert.strictEqual(b.offset, 0);
49 assert.strictEqual(value, ui8[index]);
57 assert.strictEqual(value, ui8[key]);
67 assert.strictEqual(value, ui32[index]);
76 assert.strictEqual(value, ui32[key]);
81 assert.throws(() => b.toString('invalid'),
84 assert.throws(() => b.write('test string', 0, 5, 'invalid'),
87 assert.throws(() => b.write('test', 'utf8', 0),
108 assert.throws(() => b.write('', 2048), outOfRangeError);
111 assert.throws(() => b.write('a', -1), outOfRangeError);
114 assert.throws(() => b.write('a', 2048), outOfRangeError);
117 assert.throws(() => b.write('a', -1), outOfRangeError);
133 assert.throws(
141 assert.strictEqual(writeTest.toString(), 'nodejs');
156 assert.strictEqual(asciiString, asciiSlice);
163 assert.strictEqual(asciiString.length, b.write(asciiString, offset, 'ascii'));
165 assert.strictEqual(asciiString, asciiSlice);
175 assert.strictEqual(sliceA[i], sliceB[i]);
186 assert.strictEqual(utf8String, utf8Slice);
188 assert.strictEqual(Buffer.byteLength(utf8String),
192 assert.strictEqual(utf8String, utf8Slice);
197 assert.strictEqual(sliceA[i], sliceB[i]);
203 assert.strictEqual(slice.length, 50);
205 assert.strictEqual(b[100 + i], slice[i]);
214 assert.strictEqual(b.parent, c.parent);
215 assert.strictEqual(b.parent, d.parent);
223 assert.strictEqual(c.parent, d.parent);
232 assert.strictEqual(slice, testValue);
240 assert.strictEqual(b[0], 4);
241 assert.strictEqual(b[1], 5);
242 assert.strictEqual(b[2], 6);
243 assert.strictEqual(b[3], 7);
245 assert.strictEqual(c[0], 6);
246 assert.strictEqual(c[1], 7);
251 assert.strictEqual(d.length, 3);
252 assert.strictEqual(d[0], 23);
253 assert.strictEqual(d[1], 42);
254 assert.strictEqual(d[2], 255);
255 assert.deepStrictEqual(d, Buffer.from(d));
261 assert.deepStrictEqual(e, Buffer.from([195, 188, 98, 101, 114]));
267 assert.deepStrictEqual(f, Buffer.from([252, 98, 101, 114]));
274 assert.deepStrictEqual(f, Buffer.from([252, 0, 98, 0, 101, 0, 114, 0]));
280 assert.deepStrictEqual(
283 assert.strictEqual(f.toString(encoding), 'привет');
288 assert.strictEqual(f.length, 5);
290 assert.strictEqual(size, 4);
291 assert.deepStrictEqual(f, Buffer.from([0x42, 0x30, 0x44, 0x30, 0x00]));
297 assert.strictEqual(f.length, 4);
298 assert.deepStrictEqual(f, Buffer.from('3DD84DDC', 'hex'));
305 assert.deepStrictEqual(g, Buffer.from([0, 1, 2, 3]));
308 assert.deepStrictEqual(g, Buffer.from([0, 1, 2, 3]));
314 assert.strictEqual((Buffer.from('Man')).toString('base64'), 'TWFu');
315 assert.strictEqual((Buffer.from('Woman')).toString('base64'), 'V29tYW4=');
320 assert.strictEqual((Buffer.from('Man')).toString('base64url'), 'TWFu');
321 assert.strictEqual((Buffer.from('Woman')).toString('base64url'), 'V29tYW4');
326 assert.deepStrictEqual(Buffer.from('//++/++/++//', 'base64'),
328 assert.deepStrictEqual(Buffer.from('__--_--_--__', 'base64'),
330 assert.deepStrictEqual(Buffer.from('//++/++/++//', 'base64url'),
332 assert.deepStrictEqual(Buffer.from('__--_--_--__', 'base64url'),
341 assert.deepStrictEqual(Buffer.from('//++/++/++//+w==', 'base64'),
343 assert.deepStrictEqual(Buffer.from('//++/++/++//+w==', 'base64'),
345 assert.deepStrictEqual(Buffer.from('//++/++/++//+w==', 'base64url'),
347 assert.deepStrictEqual(Buffer.from('//++/++/++//+w==', 'base64url'),
365 assert.strictEqual(Buffer.from(quote).toString('base64'), expected);
366 assert.strictEqual(
374 assert.strictEqual(quote.length, bytesWritten);
375 assert.strictEqual(quote, b.toString('ascii', 0, quote.length));
386 assert.strictEqual(quote.length, bytesWritten);
387 assert.strictEqual(quote, b.toString('ascii', 0, quote.length));
392 assert.strictEqual(quote.length, b.length);
393 assert.strictEqual(quote, b.toString('ascii', 0, quote.length));
403 assert.strictEqual(quote.length, b.length);
404 assert.strictEqual(quote, b.toString('ascii', 0, quote.length));
409 assert.strictEqual(Buffer.from('', encoding).toString(), '');
410 assert.strictEqual(Buffer.from('K', encoding).toString(), '');
413 assert.strictEqual(Buffer.from('Kg==', encoding).toString(), '*');
414 assert.strictEqual(Buffer.from('Kio=', encoding).toString(), '*'.repeat(2));
415 assert.strictEqual(Buffer.from('Kioq', encoding).toString(), '*'.repeat(3));
416 assert.strictEqual(
418 assert.strictEqual(
420 assert.strictEqual(
422 assert.strictEqual(Buffer.from('KioqKioqKg==', encoding).toString(),
424 assert.strictEqual(Buffer.from('KioqKioqKio=', encoding).toString(),
426 assert.strictEqual(Buffer.from('KioqKioqKioq', encoding).toString(),
428 assert.strictEqual(Buffer.from('KioqKioqKioqKg==', encoding).toString(),
430 assert.strictEqual(Buffer.from('KioqKioqKioqKio=', encoding).toString(),
432 assert.strictEqual(Buffer.from('KioqKioqKioqKioq', encoding).toString(),
434 assert.strictEqual(Buffer.from('KioqKioqKioqKioqKg==', encoding).toString(),
436 assert.strictEqual(Buffer.from('KioqKioqKioqKioqKio=', encoding).toString(),
438 assert.strictEqual(Buffer.from('KioqKioqKioqKioqKioq', encoding).toString(),
440 assert.strictEqual(
443 assert.strictEqual(
446 assert.strictEqual(
449 assert.strictEqual(Buffer.from('KioqKioqKioqKioqKioqKioqKg==',
452 assert.strictEqual(Buffer.from('KioqKioqKioqKioqKioqKioqKio=',
457 assert.strictEqual(Buffer.from('Kg', encoding).toString(), '*');
458 assert.strictEqual(Buffer.from('Kio', encoding).toString(), '*'.repeat(2));
459 assert.strictEqual(Buffer.from('KioqKg', encoding).toString(), '*'.repeat(4));
460 assert.strictEqual(
462 assert.strictEqual(Buffer.from('KioqKioqKg', encoding).toString(),
464 assert.strictEqual(Buffer.from('KioqKioqKio', encoding).toString(),
466 assert.strictEqual(Buffer.from('KioqKioqKioqKg', encoding).toString(),
468 assert.strictEqual(Buffer.from('KioqKioqKioqKio', encoding).toString(),
470 assert.strictEqual(Buffer.from('KioqKioqKioqKioqKg', encoding).toString(),
472 assert.strictEqual(Buffer.from('KioqKioqKioqKioqKio', encoding).toString(),
474 assert.strictEqual(Buffer.from('KioqKioqKioqKioqKioqKg', encoding).toString(),
476 assert.strictEqual(
479 assert.strictEqual(
482 assert.strictEqual(
488 assert.strictEqual(
492 assert.strictEqual(
497 assert.strictEqual(
501 assert.strictEqual(
506 assert.strictEqual(
510 assert.strictEqual(
515 assert.strictEqual(
519 assert.strictEqual(
524 assert.strictEqual(
528 assert.strictEqual(
533 assert.strictEqual(
537 assert.strictEqual(
545 assert.strictEqual(dot[0], 0xff);
546 assert.strictEqual(dot[1], 0xfe);
547 assert.strictEqual(dot[2], 0x2e);
548 assert.strictEqual(dot[3], 0x00);
549 assert.strictEqual(dot.toString('base64'), '//4uAA==');
555 assert.strictEqual(dot[0], 0xff);
556 assert.strictEqual(dot[1], 0xfe);
557 assert.strictEqual(dot[2], 0x2e);
558 assert.strictEqual(dot[3], 0x00);
559 assert.strictEqual(dot.toString('base64url'), '__4uAA');
573 assert.strictEqual(b.toString('latin1', 0, pos),
588 assert.strictEqual(b.toString('latin1', 0, pos),
593 assert.strictEqual(Buffer.from('=bad'.repeat(1e4), 'base64').length, 0);
596 assert.deepStrictEqual(Buffer.from('w0 ', 'base64'),
600 assert.deepStrictEqual(Buffer.from(' YWJvcnVtLg', 'base64'),
610 assert.strictEqual(b[i], 'h'.charCodeAt(0));
614 assert.strictEqual(sb.length, s.length);
615 assert.strictEqual(sb, s);
625 assert.strictEqual(hexStr,
645 assert.strictEqual(hexb2[i], hexb[i]);
650 assert.strictEqual(Buffer.from('A', 'hex').length, 0);
653 assert.deepStrictEqual(Buffer.from('Abx', 'hex'), Buffer.from('Ab', 'hex'));
656 assert.strictEqual(Buffer.from('A', 'base64').length, 0);
665 assert.strictEqual(b2, b3);
666 assert.strictEqual(b2, b4);
680 assert.strictEqual(x.inspect(), '<Buffer 81 a3 66 6f 6f a3 62 61 72>');
684 assert.strictEqual(z.length, 5);
685 assert.strictEqual(z[0], 0x6f);
686 assert.strictEqual(z[1], 0xa3);
687 assert.strictEqual(z[2], 0x62);
688 assert.strictEqual(z[3], 0x61);
689 assert.strictEqual(z[4], 0x72);
694 assert.strictEqual(z.length, x.length);
699 assert.strictEqual(z.length, 4);
700 assert.strictEqual(z[0], 0x81);
701 assert.strictEqual(z[1], 0xa3);
706 assert.strictEqual(z.length, 9);
711 assert.strictEqual(z.length, 3);
712 assert.strictEqual(z[0], 0xa3);
717 assert.strictEqual(z.length, 2);
718 assert.strictEqual(z[0], 0x66);
719 assert.strictEqual(z[1], 0x6f);
725 assert.strictEqual(b.toString(encoding), 'あいうえお');
731 assert.strictEqual(b.toString(encoding, 1), 'あいうえお');
739 assert.strictEqual(b[0], 0xff);
740 assert.strictEqual(b[1], 0xad);
741 assert.strictEqual(b[2], 0xbe);
742 assert.strictEqual(b[3], 0xef);
745 assert.strictEqual(b[0], 0xee);
746 assert.strictEqual(b[1], 0xad);
747 assert.strictEqual(b[2], 0xbe);
748 assert.strictEqual(b[3], 0xef);
756 assert.strictEqual(b[0], 0xff);
757 assert.strictEqual(b[1], 0xad);
758 assert.strictEqual(b[2], 0xbe);
759 assert.strictEqual(b[3], 0xef);
762 assert.strictEqual(b[0], 0xee);
763 assert.strictEqual(b[1], 0xad);
764 assert.strictEqual(b[2], 0xbe);
765 assert.strictEqual(b[3], 0xef);
772 assert.strictEqual(buf.length, 1);
774 assert.strictEqual(buf.length, 2);
779 assert.strictEqual(buf.write(''), 0); // 0bytes
780 assert.strictEqual(buf.write('\0'), 1); // 1byte (v8 adds null terminator)
781 assert.strictEqual(buf.write('a\0'), 2); // 1byte * 2
782 assert.strictEqual(buf.write('あ'), 0); // 3bytes
783 assert.strictEqual(buf.write('\0あ'), 1); // 1byte + 3bytes
784 assert.strictEqual(buf.write('\0\0あ'), 2); // 1byte * 2 + 3bytes
789 assert.strictEqual(buf.write('あいう'), 9); // 3bytes * 3 (v8 adds null term.)
790 assert.strictEqual(buf.write('あいう\0'), 10); // 3bytes * 3 + 1byte
798 assert.strictEqual(buf.write('abcd', 1, 2, 'utf8'), 2);
799 assert.strictEqual(buf[0], 0xFF);
800 assert.strictEqual(buf[1], 0x61);
801 assert.strictEqual(buf[2], 0x62);
802 assert.strictEqual(buf[3], 0xFF);
805 assert.strictEqual(buf.write('abcd', 1, 4), 3);
806 assert.strictEqual(buf[0], 0xFF);
807 assert.strictEqual(buf[1], 0x61);
808 assert.strictEqual(buf[2], 0x62);
809 assert.strictEqual(buf[3], 0x63);
812 assert.strictEqual(buf.write('abcd', 1, 2, 'utf8'), 2);
813 assert.strictEqual(buf[0], 0xFF);
814 assert.strictEqual(buf[1], 0x61);
815 assert.strictEqual(buf[2], 0x62);
816 assert.strictEqual(buf[3], 0xFF);
819 assert.strictEqual(buf.write('abcdef', 1, 2, 'hex'), 2);
820 assert.strictEqual(buf[0], 0xFF);
821 assert.strictEqual(buf[1], 0xAB);
822 assert.strictEqual(buf[2], 0xCD);
823 assert.strictEqual(buf[3], 0xFF);
827 assert.strictEqual(buf.write('abcd', 0, 2, encoding), 2);
828 assert.strictEqual(buf[0], 0x61);
829 assert.strictEqual(buf[1], 0x00);
830 assert.strictEqual(buf[2], 0xFF);
831 assert.strictEqual(buf[3], 0xFF);
838 assert.strictEqual(b.writeUInt32LE(0, 0), 4);
839 assert.strictEqual(b.writeUInt16LE(0, 4), 6);
840 assert.strictEqual(b.writeUInt8(0, 6), 7);
841 assert.strictEqual(b.writeInt8(0, 7), 8);
842 assert.strictEqual(b.writeDoubleLE(0, 8), 16);
850 assert.strictEqual(buf[0], 0x61);
851 assert.strictEqual(buf[1], 0x62);
852 assert.strictEqual(buf[2], 0xef);
853 assert.strictEqual(buf[3], 0xbf);
854 assert.strictEqual(buf[4], 0xbd);
855 assert.strictEqual(buf[5], 0x63);
856 assert.strictEqual(buf[6], 0x64);
863 assert.strictEqual(sub.write('12345', 'latin1'), 4);
864 assert.strictEqual(buf[4], 0);
865 assert.strictEqual(sub.write('12345', 'binary'), 4);
866 assert.strictEqual(buf[4], 0);
872 assert.strictEqual(buf[0], 128);
873 assert.strictEqual(buf[1], 10);
874 assert.strictEqual(buf[2], 128);
875 assert.strictEqual(buf[3], 10);
876 assert.strictEqual(buf[4], 128);
887 assert.strictEqual(Buffer.allocUnsafe(3.3).length, 3);
888 assert.strictEqual(Buffer.from({ length: 3.3 }).length, 3);
889 assert.strictEqual(Buffer.from({ length: 'BAM' }).length, 0);
892 assert.strictEqual(Buffer.from('99').length, 2);
893 assert.strictEqual(Buffer.from('13.37').length, 5);
897 assert.strictEqual(Buffer.allocUnsafe(1).write('aaaaaa', 0, 1, enc), 1);
905 assert.strictEqual(b.toString(), 'xxx');
912 assert.throws(
916 assert.throws(
922 assert.throws(
926 assert.throws(
932 assert.throws(
936 assert.throws(
945 assert.deepStrictEqual(buf.toJSON().data, [0x56, 0x34, 0x12]);
946 assert.strictEqual(buf.readUIntLE(0, 3), 0x123456);
950 assert.deepStrictEqual(buf.toJSON().data, [0x12, 0x34, 0x56]);
951 assert.strictEqual(buf.readUIntBE(0, 3), 0x123456);
955 assert.deepStrictEqual(buf.toJSON().data, [0x56, 0x34, 0x12]);
956 assert.strictEqual(buf.readIntLE(0, 3), 0x123456);
960 assert.deepStrictEqual(buf.toJSON().data, [0x12, 0x34, 0x56]);
961 assert.strictEqual(buf.readIntBE(0, 3), 0x123456);
965 assert.deepStrictEqual(buf.toJSON().data, [0xaa, 0xcb, 0xed]);
966 assert.strictEqual(buf.readIntLE(0, 3), -0x123456);
970 assert.deepStrictEqual(buf.toJSON().data, [0xed, 0xcb, 0xaa]);
971 assert.strictEqual(buf.readIntBE(0, 3), -0x123456);
975 assert.deepStrictEqual(buf.toJSON().data, [0x00, 0xcc, 0xed]);
976 assert.strictEqual(buf.readIntLE(0, 3), -0x123400);
980 assert.deepStrictEqual(buf.toJSON().data, [0xed, 0xcc, 0x00]);
981 assert.strictEqual(buf.readIntBE(0, 3), -0x123400);
985 assert.deepStrictEqual(buf.toJSON().data, [0x00, 0x00, 0xee]);
986 assert.strictEqual(buf.readIntLE(0, 3), -0x120000);
990 assert.deepStrictEqual(buf.toJSON().data, [0xee, 0x00, 0x00]);
991 assert.strictEqual(buf.readIntBE(0, 3), -0x120000);
995 assert.deepStrictEqual(buf.toJSON().data, [0x90, 0x78, 0x56, 0x34, 0x12]);
996 assert.strictEqual(buf.readUIntLE(0, 5), 0x1234567890);
1000 assert.deepStrictEqual(buf.toJSON().data, [0x12, 0x34, 0x56, 0x78, 0x90]);
1001 assert.strictEqual(buf.readUIntBE(0, 5), 0x1234567890);
1005 assert.deepStrictEqual(buf.toJSON().data, [0x90, 0x78, 0x56, 0x34, 0x12]);
1006 assert.strictEqual(buf.readIntLE(0, 5), 0x1234567890);
1010 assert.deepStrictEqual(buf.toJSON().data, [0x12, 0x34, 0x56, 0x78, 0x90]);
1011 assert.strictEqual(buf.readIntBE(0, 5), 0x1234567890);
1015 assert.deepStrictEqual(buf.toJSON().data, [0x70, 0x87, 0xa9, 0xcb, 0xed]);
1016 assert.strictEqual(buf.readIntLE(0, 5), -0x1234567890);
1020 assert.deepStrictEqual(buf.toJSON().data, [0xed, 0xcb, 0xa9, 0x87, 0x70]);
1021 assert.strictEqual(buf.readIntBE(0, 5), -0x1234567890);
1025 assert.deepStrictEqual(buf.toJSON().data, [0x00, 0x00, 0x00, 0xee, 0xff]);
1026 assert.strictEqual(buf.readIntLE(0, 5), -0x0012000000);
1030 assert.deepStrictEqual(buf.toJSON().data, [0xff, 0xee, 0x00, 0x00, 0x00]);
1031 assert.strictEqual(buf.readIntBE(0, 5), -0x0012000000);
1036 assert.throws(
1052 assert.strictEqual(b.length, a.length);
1053 assert.strictEqual(c.length, a.length);
1055 assert.strictEqual(a[i], i);
1056 assert.strictEqual(b[i], i);
1057 assert.strictEqual(c[i], i);
1068 assert.strictEqual(
1078 assert(Buffer.allocUnsafe(1).parent instanceof ArrayBuffer);
1081 assert.throws(
1090 assert.throws(() => Buffer.from(), {
1095 assert.throws(() => Buffer.from(null), {
1102 assert.strictEqual(Buffer.prototype.parent, undefined);
1103 assert.strictEqual(Buffer.prototype.offset, undefined);
1104 assert.strictEqual(SlowBuffer.prototype.parent, undefined);
1105 assert.strictEqual(SlowBuffer.prototype.offset, undefined);
1112 assert.deepStrictEqual(Buffer.from({ length: -Buffer.poolSize }),
1114 assert.deepStrictEqual(Buffer.from({ length: -100 }),
1129 assert.throws(() => Buffer.from(new ArrayBuffer(0), -1 >>> 0), errMsg);
1133 assert.throws(() => {
1142 assert(ubuf);
1143 assert(ubuf.buffer);
1144 assert.strictEqual(ubuf.buffer.byteLength, 10);
1155 assert.throws(() => Buffer.alloc({ valueOf: () => 1 }),
1157 assert.throws(() => Buffer.alloc({ valueOf: () => -1 }),
1160 assert.strictEqual(Buffer.prototype.toLocaleString, Buffer.prototype.toString);
1163 assert.strictEqual(buf.toLocaleString(), buf.toString());
1166 assert.throws(() => {
1173 assert.throws(() => {
1180 assert.throws(() => {
1187 assert.throws(() => {