REDROOM
PHP 8.2.30
Path:
Logout
Edit File
Size: 3.83 KB
Close
/home/byroehnu/easepaybiz.easetack.com/node_modules/restructure/test/Optional.js
Text
Base64
import assert from 'assert'; import {Optional, uint8, DecodeStream, EncodeStream} from 'restructure'; describe('Optional', function() { describe('decode', function() { it('should not decode when condition is falsy', function() { const stream = new DecodeStream(new Uint8Array([0])); const optional = new Optional(uint8, false); assert.equal(optional.decode(stream), null); assert.equal(stream.pos, 0); }); it('should not decode when condition is a function and falsy', function() { const stream = new DecodeStream(new Uint8Array([0])); const optional = new Optional(uint8, function() { return false; }); assert.equal(optional.decode(stream), null); assert.equal(stream.pos, 0); }); it('should decode when condition is omitted', function() { const stream = new DecodeStream(new Uint8Array([0])); const optional = new Optional(uint8); assert(optional.decode(stream) != null); assert.equal(stream.pos, 1); }); it('should decode when condition is truthy', function() { const stream = new DecodeStream(new Uint8Array([0])); const optional = new Optional(uint8, true); assert(optional.decode(stream) != null); assert.equal(stream.pos, 1); }); it('should decode when condition is a function and truthy', function() { const stream = new DecodeStream(new Uint8Array([0])); const optional = new Optional(uint8, function() { return true; }); assert(optional.decode(stream) != null); assert.equal(stream.pos, 1); }); }); describe('size', function() { it('should return 0 when condition is falsy', function() { const stream = new DecodeStream(new Uint8Array([0])); const optional = new Optional(uint8, false); assert.equal(optional.size(), 0); }); it('should return 0 when condition is a function and falsy', function() { const stream = new DecodeStream(new Uint8Array([0])); const optional = new Optional(uint8, function() { return false; }); assert.equal(optional.size(), 0); }); it('should return given type size when condition is omitted', function() { const stream = new DecodeStream(new Uint8Array([0])); const optional = new Optional(uint8); assert.equal(optional.size(), 1); }); it('should return given type size when condition is truthy', function() { const stream = new DecodeStream(new Uint8Array([0])); const optional = new Optional(uint8, true); assert.equal(optional.size(), 1); }); it('should return given type size when condition is a function and truthy', function() { const stream = new DecodeStream(new Uint8Array([0])); const optional = new Optional(uint8, function() { return true; }); assert.equal(optional.size(), 1); }); }); describe('encode', function() { it('should not encode when condition is falsy', function() { const optional = new Optional(uint8, false); assert.deepEqual(optional.toBuffer(128), new Uint8Array(0)); }); it('should not encode when condition is a function and falsy', function() { const optional = new Optional(uint8, function() { return false; }); assert.deepEqual(optional.toBuffer(128), new Uint8Array(0)); }); it('should encode when condition is omitted', function() { const optional = new Optional(uint8); assert.deepEqual(optional.toBuffer(128), new Uint8Array([128])); }); it('should encode when condition is truthy', function() { const optional = new Optional(uint8, true); assert.deepEqual(optional.toBuffer(128), new Uint8Array([128])); }); it('should encode when condition is a function and truthy', function() { const optional = new Optional(uint8, function() { return true; }); assert.deepEqual(optional.toBuffer(128), new Uint8Array([128])); }); }); });
Save
Close
Exit & Reset
Text mode: syntax highlighting auto-detects file type.
Directory Contents
Dirs: 0 × Files: 16
Delete Selected
Select All
Select None
Sort:
Name
Size
Modified
Enable drag-to-move
Name
Size
Perms
Modified
Actions
.htaccess
127 B
lr--r--r--
2026-03-14 01:49:07
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
Array.js
3.97 KB
lrw-r--r--
2026-03-05 00:19:58
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
Bitfield.js
1.04 KB
lrw-r--r--
2026-03-05 00:20:00
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
Boolean.js
1.15 KB
lrw-r--r--
2026-03-05 00:20:01
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
Buffer.js
1.53 KB
lrw-r--r--
2026-03-05 00:20:02
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
DecodeStream.js
3.53 KB
lrw-r--r--
2026-03-05 00:20:03
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
EncodeStream.js
3.74 KB
lrw-r--r--
2026-03-05 00:20:04
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
Enum.js
831 B
lrw-r--r--
2026-03-05 00:20:06
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
LazyArray.js
1.87 KB
lrw-r--r--
2026-03-05 00:20:08
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
Number.js
11.03 KB
lrw-r--r--
2026-03-05 00:20:09
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
Optional.js
3.83 KB
lrw-r--r--
2026-03-05 00:20:09
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
Pointer.js
9.48 KB
lrw-r--r--
2026-03-05 00:20:10
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
Reserved.js
820 B
lrw-r--r--
2026-03-05 00:20:10
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
String.js
5.61 KB
lrw-r--r--
2026-03-05 00:20:11
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
Struct.js
3.45 KB
lrw-r--r--
2026-03-05 00:20:11
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
VersionedStruct.js
11.37 KB
lrw-r--r--
2026-03-05 00:20:11
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
Zip Selected
If ZipArchive is unavailable, a
.tar
will be created (no compression).