summaryrefslogtreecommitdiffstats
path: root/llparse/test/resumption-test.ts
blob: 438b7fd6b7fe8e879034e70465a73a0e3db1d351 (plain)
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
import * as assert from 'assert';

import { LLParse } from '../src/api';

import { build, ERROR_PAUSE, printMatch, printOff } from './fixtures';

describe('llparse/resumption', () => {
  let p: LLParse;

  beforeEach(() => {
    p = new LLParse();
  });

  it('should resume after span end pause', async () => {
    const start = p.node('start');
    const a = p.node('a');
    const span = p.span(p.code.span('llparse__pause_once'));

    start
      .peek('a', span.start(a))
      .skipTo(start);

    a
      .match('a', a)
      .otherwise(span.end(start));

    const binary = await build(p, start, 'resume-span');

    await binary.check('baaab',
      new RegExp(
        '^(' +
          'off=\\d+ pause\\noff=1 len=3 span\\[pause\\]="aaa"' +
          '|' +
          'off=1 len=3 span\\[pause\\]="aaa"\noff=4 pause' +
          ')\\n$'
        , 'g'));
  });

  it('should resume after `pause` node', async () => {
    const start = p.node('start');
    const pause = p.pause(ERROR_PAUSE, 'paused');

    start
      .match('p', pause)
      .skipTo(start);

    pause
      .otherwise(printOff(p, start));

    const binary = await build(p, start, 'resume-pause');

    await binary.check('..p....p..',
      'off=3 pause\noff=3\noff=8 pause\noff=8\n');
  });
});