PHP 8.2.30
Preview: Boolean.js Size: 1.15 KB
/home/byroehnu/.trash/node_modules11/restructure/test/Boolean.js

import assert from 'assert';
import {Boolean, uint8, DecodeStream, EncodeStream} from 'restructure';

describe('Boolean', function() {
  describe('decode', function() {
    it('should decode 0 as false', function() {
      const buffer = new Uint8Array([0]);
      const boolean = new Boolean(uint8);
      assert.deepEqual(boolean.fromBuffer(buffer), false);
    });

    it('should decode 1 as true', function() {
      const buffer = new Uint8Array([1]);
      const boolean = new Boolean(uint8);
      assert.deepEqual(boolean.fromBuffer(buffer), true);
    });
  });

  describe('size', () =>
    it('should return given type size', function() {
      const boolean = new Boolean(uint8);
      assert.deepEqual(boolean.size(), 1);
    })
  );

  describe('encode', function() {
    it('should encode false as 0', function() {
      const boolean = new Boolean(uint8);
      const buffer = boolean.toBuffer(false);
      assert.deepEqual(buffer, Buffer.from([0]));
    });

    it('should encode true as 1', function() {
      const boolean = new Boolean(uint8);
      const buffer = boolean.toBuffer(true);
      assert.deepEqual(buffer, Buffer.from([1]));
    });
  });
});

Directory Contents

Dirs: 0 × Files: 15

Name Size Perms Modified Actions
3.97 KB lrw-r--r-- 2026-02-14 19:19:14
Edit Download
1.04 KB lrw-r--r-- 2026-02-14 19:19:14
Edit Download
1.15 KB lrw-r--r-- 2026-02-14 19:19:16
Edit Download
1.53 KB lrw-r--r-- 2026-02-14 19:19:16
Edit Download
3.53 KB lrw-r--r-- 2026-02-14 19:19:16
Edit Download
3.74 KB lrw-r--r-- 2026-02-14 19:19:16
Edit Download
831 B lrw-r--r-- 2026-02-14 19:19:16
Edit Download
1.87 KB lrw-r--r-- 2026-02-14 19:19:18
Edit Download
11.03 KB lrw-r--r-- 2026-02-14 19:19:18
Edit Download
3.83 KB lrw-r--r-- 2026-02-14 19:19:18
Edit Download
9.48 KB lrw-r--r-- 2026-02-14 19:19:18
Edit Download
820 B lrw-r--r-- 2026-02-14 19:19:18
Edit Download
5.61 KB lrw-r--r-- 2026-02-14 19:19:18
Edit Download
3.45 KB lrw-r--r-- 2026-02-14 19:19:18
Edit Download
11.37 KB lrw-r--r-- 2026-02-14 19:19:18
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).