-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrace.js
More file actions
63 lines (54 loc) · 2.07 KB
/
Copy pathtrace.js
File metadata and controls
63 lines (54 loc) · 2.07 KB
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
import { assert } from 'chai';
import { Trace } from 'apg-lite';
import { parse } from '../../src/index.js';
describe('parse', function () {
context('trace', function () {
specify('should not produce trace by default', function () {
const parseResult = parse('/a/b');
assert.isUndefined(parseResult.trace);
});
specify('should produce stats when requested', function () {
const parseResult = parse('/a/b', { trace: true });
assert.instanceOf(parseResult.trace, Trace);
});
specify('should provide trace', function () {
const parseResult = parse('/a', { trace: true });
const expected =
'|-|[RNM(json-pointer)]/a\n' +
'.|-|[REP(0,inf)]/a\n' +
'..|-|[CAT]/a\n' +
'...|-|[RNM(slash)]/a\n' +
'....|-|[TLS(/)]/a\n' +
"....|M|[TLS(/)]'/'\n" +
"...|M|[RNM(slash)]'/'\n" +
'...|-|[RNM(reference-token)]a\n' +
'....|-|[REP(0,inf)]a\n' +
'....||-|[ALT]a\n' +
'....|.|-|[RNM(unescaped)]a\n' +
'....|..|-|[ALT]a\n' +
'....|...|-|[TRG(0,46)]a\n' +
'....|...|N|[TRG(0,46)]\n' +
'....|...|-|[TRG(48,125)]a\n' +
"....|...|M|[TRG(48,125)]'a'\n" +
"....|..|M|[ALT]'a'\n" +
"....|.|M|[RNM(unescaped)]'a'\n" +
"....||M|[ALT]'a'\n" +
"....|M|[REP(0,inf)]'a'\n" +
"...|M|[RNM(reference-token)]'a'\n" +
"..|M|[CAT]'/a'\n" +
".|M|[REP(0,inf)]'/a'\n" +
"|M|[RNM(json-pointer)]'/a'\n";
assert.strictEqual(parseResult.trace.displayTrace(), expected);
});
specify('should be able to create human-readable trace message', function () {
const { result, trace } = parse('1', { trace: true });
const expectations = trace.inferExpectations();
const errorMessage = `Invalid JSON Pointer: "1". Syntax error at position ${result.maxMatched}, expected ${expectations}`;
assert.isFalse(result.success);
assert.strictEqual(
errorMessage,
'Invalid JSON Pointer: "1". Syntax error at position 0, expected "/"',
);
});
});
});