Sha256: 36026254525c9309c0ef701e650880bac9309b3d9288cd8b0675def1cd9c1195

Contents?: true

Size: 1.23 KB

Versions: 69

Compression:

Stored size: 1.23 KB

Contents

var binary = require('../');
var test = require('tap').test;

test('parse', function (t) {
    t.plan(6);
    var res = binary.parse(new Buffer([ 97, 98, 99, 99, 99, 99, 1, 2, 3 ]))
        .word8('a')
        .word16be('bc')
        .skip(3)
        .buffer('def', 3)
        .tap(function (vars) {
            t.equal(vars.a, 97);
            t.equal(vars.bc, 25187);
            t.same(
                [].slice.call(vars.def),
                [].slice.call(new Buffer([ 1, 2, 3]))
            );
        })
        .vars
    ;
    t.equal(res.a, 97);
    t.equal(res.bc, 25187);
    t.same(
        [].slice.call(res.def),
        [].slice.call(new Buffer([ 1, 2, 3 ]))
    );
});

test('loop', function (t) {
    t.plan(2);
    var res = binary.parse(new Buffer([ 97, 98, 99, 4, 5, 2, -3, 9 ]))
        .word8('a')
        .word16be('bc')
        .loop(function (end) {
            var x = this.word8s('x').vars.x;
            if (x < 0) end();
        })
        .tap(function (vars) {
            t.same(vars, {
                a : 97,
                bc : 25187,
                x : -3,
            });
        })
        .word8('y')
        .vars
    ;
    t.same(res, {
        a : 97,
        bc : 25187,
        x : -3,
        y : 9,
    });
});

Version data entries

69 entries across 69 versions & 2 rubygems

Version Path
trusty-festivity-extension-2.6.3 node_modules/bower/node_modules/decompress-zip/node_modules/binary/test/parse.js
trusty-festivity-extension-2.6.2 node_modules/bower/node_modules/decompress-zip/node_modules/binary/test/parse.js
trusty-festivity-extension-2.6.1 node_modules/bower/node_modules/decompress-zip/node_modules/binary/test/parse.js
trusty-festivity-extension-2.6 node_modules/bower/node_modules/decompress-zip/node_modules/binary/test/parse.js
trusty-festivity-extension-2.5.19 node_modules/bower/node_modules/decompress-zip/node_modules/binary/test/parse.js
trusty-festivity-extension-2.5.18 node_modules/bower/node_modules/decompress-zip/node_modules/binary/test/parse.js
trusty-festivity-extension-2.5.17 node_modules/bower/node_modules/decompress-zip/node_modules/binary/test/parse.js
trusty-festivity-extension-2.5.16 node_modules/bower/node_modules/decompress-zip/node_modules/binary/test/parse.js
trusty-festivity-extension-2.5.15 node_modules/bower/node_modules/decompress-zip/node_modules/binary/test/parse.js
trusty-festivity-extension-2.5.14 node_modules/bower/node_modules/decompress-zip/node_modules/binary/test/parse.js
trusty-festivity-extension-2.5.13 node_modules/bower/node_modules/decompress-zip/node_modules/binary/test/parse.js
trusty-festivity-extension-2.5.12 node_modules/bower/node_modules/decompress-zip/node_modules/binary/test/parse.js
trusty-festivity-extension-2.5.11 node_modules/bower/node_modules/decompress-zip/node_modules/binary/test/parse.js
trusty-festivity-extension-2.5.10 node_modules/bower/node_modules/decompress-zip/node_modules/binary/test/parse.js
trusty-festivity-extension-2.5.9 node_modules/bower/node_modules/decompress-zip/node_modules/binary/test/parse.js
trusty-festivity-extension-2.5.8 node_modules/bower/node_modules/decompress-zip/node_modules/binary/test/parse.js
trusty-festivity-extension-2.5.7 node_modules/bower/node_modules/decompress-zip/node_modules/binary/test/parse.js
trusty-festivity-extension-2.5.6 node_modules/bower/node_modules/decompress-zip/node_modules/binary/test/parse.js
trusty-festivity-extension-2.5.5 node_modules/bower/node_modules/decompress-zip/node_modules/binary/test/parse.js
trusty-festivity-extension-2.5.4 node_modules/bower/node_modules/decompress-zip/node_modules/binary/test/parse.js