1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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');
});
});
|