Skip to content

Commit 42612ee

Browse files
committed
Added a unit test for issue #23
1 parent 4733c3f commit 42612ee

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

lib/binary_parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ export class Parser {
434434
return this.seek(length, options);
435435
}
436436

437-
seek(relOffset: number|((item: any) => number), options?: ParserOptions) {
437+
seek(relOffset: number | ((item: any) => number), options?: ParserOptions) {
438438
if (options && options.assert) {
439439
throw new Error('assert option on seek is not allowed.');
440440
}

test/zz_encoder_bugs.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var assert = require('assert');
2+
const { SmartBuffer } = require('smart-buffer/build/smartbuffer');
23
var Parser = require('../dist/binary_parser').Parser;
34

45
describe('Specific bugs testing', function() {
@@ -398,4 +399,26 @@ describe('Specific bugs testing', function() {
398399
assert.deepEqual(encoded, buffer);
399400
});
400401
});
402+
403+
describe('Issue #23 Unable to encode uint64', function() {
404+
it('should not fail when encoding uint64', function() {
405+
let ipHeader = new Parser()
406+
.uint16('fragment_id')
407+
.uint16('fragment_total')
408+
.uint64('datetime');
409+
410+
let anIpHeader = {
411+
fragment_id: 1,
412+
fragment_total: 1,
413+
datetime: 4744430483355899789n,
414+
};
415+
416+
try {
417+
let result = ipHeader.encode(anIpHeader).toString('hex');
418+
assert.ok(true, 'No exception');
419+
} catch (ex) {
420+
assert.fail(ex);
421+
}
422+
});
423+
});
401424
});

0 commit comments

Comments
 (0)