PHP 8.2.30
Preview: Enum.js Size: 831 B
/home/byroehnu/.trash/node_modules11/restructure/test/Enum.js

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

describe('Enum', function() {
  const e = new Enum(uint8, ['foo', 'bar', 'baz']);
  it('should have the right size', () => assert.equal(e.size(), 1));

  it('should decode', function() {
    const stream = new DecodeStream(new Uint8Array([1, 2, 0]));
    assert.equal(e.decode(stream), 'bar');
    assert.equal(e.decode(stream), 'baz');
    assert.equal(e.decode(stream), 'foo');
  });

  it('should encode', function() {
    assert.deepEqual(e.toBuffer('bar'), new Uint8Array([1]));
    assert.deepEqual(e.toBuffer('baz'), new Uint8Array([2]));
    assert.deepEqual(e.toBuffer('foo'), new Uint8Array([0]));
  });

  it('should throw on unknown option', function() {
    return assert.throws(() => e.toBuffer('unknown'));
  });
});

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).