Example #1
0
    it("should work with maximum value of 32767", function()
    {
      var builder = new BufferBuilder();

      builder.pushInt16(32767);

      expect(builder.toBuffer()).toBeEqualToBuffer([0x7F, 0xFF]);
    });
Example #2
0
    it("should append the specified string followed by byte 0 to the end of the result buffer", function()
    {
      var builder = new BufferBuilder();

      builder.pushZeroString('Łukasz').pushZeroString('Walukiewicz');

      expect(builder.toBuffer()).toBeEqualToBuffer(new Buffer('Łukasz\0Walukiewicz\0'));
    });
Example #3
0
    it("should work with minimum value of -128", function()
    {
      var builder = new BufferBuilder();

      builder.pushInt8(-128);

      expect(builder.toBuffer()).toBeEqualToBuffer([0x80]);
    });
Example #4
0
    it("should only append byte 0 if the specified string is empty", function()
    {
      var builder = new BufferBuilder();

      builder.pushZeroString('');

      expect(builder.toBuffer()).toBeEqualToBuffer([0]);
    });
Example #5
0
    it("should do nothing if the specified string is empty", function()
    {
      var builder = new BufferBuilder();

      builder.pushString('');

      expect(builder.length).toBe(0);
    });
Example #6
0
    it("should append the specified bytes to the end of the result buffer", function()
    {
      var builder = new BufferBuilder();

      builder.pushBuffer(new Buffer([0, 1, 2, 3, 4]));

      expect(builder.toBuffer()).toBeEqualToBuffer([0, 1, 2, 3, 4]);
    });
Example #7
0
    it("should do nothing if empty array is pushed", function()
    {
      var builder = new BufferBuilder();

      builder.pushBits([]);

      expect(builder.length).toBe(0);
    });
Example #8
0
    it("should work with maximum value of 255", function()
    {
      var builder = new BufferBuilder();

      builder.pushUInt8(255);

      expect(builder.toBuffer()).toBeEqualToBuffer([0xFF]);
    });
Example #9
0
    it("should work with maximum value of 3.4028234663852886e+38", function()
    {
      var builder = new BufferBuilder();

      builder.pushFloat(3.4028234663852886e+38);

      expect(builder.toBuffer()).toBeEqualToBuffer([0x7F, 0x7F, 0xFF, 0xFF]);
    });
Example #10
0
    it("should increase the length of the builder by 2", function()
    {
      var builder = new BufferBuilder();

      builder.pushUInt16(10);

      expect(builder.length).toBe(2);
    });
Example #11
0
    it("should increase the length of the builder by 4", function()
    {
      var builder = new BufferBuilder();

      builder.pushFloat(10.10);

      expect(builder.length).toBe(4);
    });
Example #12
0
    it("should convert 8 ones to 255 byte", function()
    {
      var builder = new BufferBuilder();

      builder.pushBits([1, 1, 1, 1, 1, 1, 1, 1]);

      expect(builder.toBuffer()).toBeEqualToBuffer([255]);
    });
Example #13
0
    it("should work with minimum value of 0", function()
    {
      var builder = new BufferBuilder();

      builder.pushUInt32(0);

      expect(builder.toBuffer()).toBeEqualToBuffer([0x00, 0x00, 0x00, 0x00]);
    });
Example #14
0
    it("should convert floats to integers by dropping fraction", function()
    {
      var builder = new BufferBuilder();

      builder.pushUInt32(12.34);

      expect(builder.toBuffer()).toBeEqualToBuffer([0x00, 0x00, 0x00, 0x0C]);
    });
Example #15
0
    it("should work with maximum value of 2147483647", function()
    {
      var builder = new BufferBuilder();

      builder.pushUInt32(0xFFFFFFFF);

      expect(builder.toBuffer()).toBeEqualToBuffer([0xFF, 0xFF, 0xFF, 0xFF]);
    });
Example #16
0
    it("should increase the length of the builder by 8", function()
    {
      var builder = new BufferBuilder();

      builder.pushDouble(10.10);

      expect(builder.length).toBe(8);
    });
Example #17
0
    it("should convert 8 zeros to 0 byte", function()
    {
      var builder = new BufferBuilder();

      builder.pushBits([0, 0, 0, 0, 0, 0, 0, 0]);

      expect(builder.toBuffer()).toBeEqualToBuffer([0]);
    });
Example #18
0
    it("should work with maximum value of 1.7976931348623157e+308", function()
    {
      var builder = new BufferBuilder();

      builder.pushDouble(1.7976931348623157e+308);

      expect(builder.toBuffer()).toBeEqualToBuffer([0x7F, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]);
    });
Example #19
0
    it("should work with minimum value of -2147483648", function()
    {
      var builder = new BufferBuilder();

      builder.pushInt32(-2147483648);

      expect(builder.toBuffer()).toBeEqualToBuffer([0x80, 0x00, 0x00, 0x00]);
    });
Example #20
0
    it("should increase the length of the builder by the number of bytes that can contain the pushed bits", function()
    {
      var builder = new BufferBuilder();

      expect(builder.pushBits([1]).length).toBe(1);
      expect(builder.pushBits([1, 0, 1]).length).toBe(1 + 1);
      expect(builder.pushBits([1, 0, 1, 1, 0, 0, 0, 1]).length).toBe(2 + 1);
      expect(builder.pushBits([1, 0, 1, 1, 0, 0, 0, 1, 1]).length).toBe(3 + 2);
    });
Example #21
0
    it("should append the specified numbers in little endian to the end of the result buffer", function()
    {
      var builder = new BufferBuilder();

      builder
        .pushUInt32(0, true)
        .pushUInt32(50000, true);

      expect(builder.toBuffer()).toBeEqualToBuffer([0x00, 0x00, 0x00, 0x00, 0x50, 0xC3, 0x00, 0x00]);
    });
Example #22
0
    it("should append the specified numbers in big endian to the end of the result buffer", function()
    {
      var builder = new BufferBuilder();

      builder
        .pushUInt16(0)
        .pushUInt16(500);

      expect(builder.toBuffer()).toBeEqualToBuffer([0x00, 0x00, 0x01, 0xF4]);
    });
Example #23
0
    it("should append the specified numbers to the end of the result buffer", function()
    {
      var builder = new BufferBuilder();

      builder
        .pushUInt8(0)
        .pushUInt8(50);

      expect(builder.toBuffer()).toBeEqualToBuffer([0x00, 0x32]);
    });
Example #24
0
    it("should append the specified numbers in big endian to the end of the result buffer", function()
    {
      var builder = new BufferBuilder();

      builder
        .pushInt32(-50000)
        .pushInt32(50000);

      expect(builder.toBuffer()).toBeEqualToBuffer([0xFF, 0xFF, 0x3C, 0xB0, 0x00, 0x00, 0xC3, 0x50]);
    });
Example #25
0
    it("should append the specified numbers in little endian to the end of the result buffer", function()
    {
      var builder = new BufferBuilder();

      builder
        .pushInt16(-500, true)
        .pushInt16(500, true);

      expect(builder.toBuffer()).toBeEqualToBuffer([0x0C, 0xFE, 0xF4, 0x01]);
    });
Example #26
0
    it("should append the specified byte to the end of the result buffer", function()
    {
      var builder = new BufferBuilder();

      builder
        .pushByte(0x00)
        .pushByte(0xAB)
        .pushByte(0xFF);

      expect(builder.toBuffer()).toBeEqualToBuffer([0x00, 0xAB, 0xFF]);
    });
Example #27
0
    it("should append the specified character's code as byte to the end of the result buffer", function()
    {
      var builder = new BufferBuilder();

      builder
        .pushChar('2')
        .pushChar('+')
        .pushChar('2')
        .pushChar('=')
        .pushChar('4');

      expect(builder.toBuffer()).toBeEqualToBuffer([0x32, 0x2B, 0x32, 0x3D, 0x34]);
    });
Example #28
0
    it("should append the specified numbers in little endian to the end of the result buffer", function()
    {
      var builder = new BufferBuilder();

      builder
        .pushFloat(-1.23, true)
        .pushFloat(0, true)
        .pushFloat(4.56, true);

      expect(builder.toBuffer()).toBeEqualToBuffer(
        [0xA4, 0x70, 0x9D, 0xBF, 0x00, 0x00, 0x00, 0x00, 0x85, 0xEB, 0x91, 0x40]
      );
    });
Example #29
0
    it("should append the specified numbers in little endian to the end of the result buffer", function()
    {
      var builder = new BufferBuilder();

      builder
        .pushDouble(-1.23, true)
        .pushDouble(0, true)
        .pushDouble(4.56, true);

      expect(builder.toBuffer()).toBeEqualToBuffer([
        0xAE, 0x47, 0xE1, 0x7A, 0x14, 0xAE, 0xF3, 0xBF,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x3D, 0x0A, 0xD7, 0xA3, 0x70, 0x3D, 0x12, 0x40
      ]);
    });
Example #30
0
    it("should treat each eight elements as reversed bits in a byte", function()
    {
      var builder = new BufferBuilder();

      builder.pushBits([
        1, 0, 1, 1, 0, 0, 0, 1,
        1, 0, 1, 1, 0, 1, 1, 0,
        1, 0, 1, 0
      ]);

      expect(builder.toBuffer()).toBeEqualToBuffer([
        parseInt('10001101', 2),
        parseInt('01101101', 2),
        parseInt('0101', 2)
      ]);
    });