diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-21 20:56:19 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-21 20:56:19 +0000 |
commit | 0b6210cd37b68b94252cb798598b12974a20e1c1 (patch) | |
tree | e371686554a877842d95aa94f100bee552ff2a8e /llparse/test/consume-test.ts | |
parent | Initial commit. (diff) | |
download | node-undici-upstream.tar.xz node-undici-upstream.zip |
Adding upstream version 5.28.2+dfsg1+~cs23.11.12.3.upstream/5.28.2+dfsg1+_cs23.11.12.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'llparse/test/consume-test.ts')
-rw-r--r-- | llparse/test/consume-test.ts | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/llparse/test/consume-test.ts b/llparse/test/consume-test.ts new file mode 100644 index 0000000..f9fb383 --- /dev/null +++ b/llparse/test/consume-test.ts @@ -0,0 +1,69 @@ +import * as assert from 'assert'; + +import { LLParse } from '../src/api'; + +import { build, NUM_SELECT, printMatch, printOff } from './fixtures'; + +describe('llparse/consume', () => { + let p: LLParse; + + beforeEach(() => { + p = new LLParse(); + }); + + it('should consume bytes with i8 field', async () => { + p.property('i8', 'to_consume'); + + const start = p.node('start'); + const consume = p.consume('to_consume'); + + start.select(NUM_SELECT, p.invoke(p.code.store('to_consume'), consume)); + + start + .otherwise(p.error(1, 'unexpected')); + + consume + .otherwise(printOff(p, start)); + + const binary = await build(p, start, 'consume'); + await binary.check('3aaa2bb1a01b', 'off=4\noff=7\noff=9\noff=10\noff=12\n'); + }); + + it('should consume bytes with i64 field', async () => { + p.property('i64', 'to_consume'); + + const start = p.node('start'); + const consume = p.consume('to_consume'); + + start.select(NUM_SELECT, p.invoke(p.code.store('to_consume'), consume)); + + start + .otherwise(p.error(1, 'unexpected')); + + consume + .otherwise(printOff(p, start)); + + const binary = await build(p, start, 'consume-i64'); + await binary.check('3aaa2bb1a01b', 'off=4\noff=7\noff=9\noff=10\noff=12\n'); + }); + + it('should consume bytes with untruncated i64 field', async () => { + p.property('i64', 'to_consume'); + + const start = p.node('start'); + const consume = p.consume('to_consume'); + + start + .select( + NUM_SELECT, + p.invoke(p.code.mulAdd('to_consume', { base: 10 }), start) + ) + .skipTo(consume); + + consume + .otherwise(printOff(p, start)); + + const binary = await build(p, start, 'consume-untruncated-i64'); + await binary.check('4294967297.xxxxxxxx', '\n'); + }); +}); |