into_buffer.js 832 B

1234567891011121314151617181920212223242526272829303132333435
  1. var binary = require('../');
  2. var test = require('tap').test;
  3. test('intoBuffer', function (t) {
  4. t.plan(3);
  5. var buf = new Buffer([ 1, 2, 3, 4, 5, 6 ])
  6. binary.parse(buf)
  7. .into('moo', function () {
  8. this
  9. .word8('x')
  10. .word8('y')
  11. .word8('z')
  12. ;
  13. })
  14. .tap(function (vars) {
  15. t.same(vars, { moo : { x : 1, y : 2, z : 3 } });
  16. })
  17. .word8('w')
  18. .tap(function (vars) {
  19. t.same(vars, {
  20. moo : { x : 1, y : 2, z : 3 },
  21. w : 4,
  22. });
  23. })
  24. .word8('x')
  25. .tap(function (vars) {
  26. t.same(vars, {
  27. moo : { x : 1, y : 2, z : 3 },
  28. w : 4,
  29. x : 5,
  30. });
  31. })
  32. ;
  33. });