-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.example2.test.js
More file actions
38 lines (35 loc) · 959 Bytes
/
index.example2.test.js
File metadata and controls
38 lines (35 loc) · 959 Bytes
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
let _ = require('lodash');
let PEG = require('pegjs');
let plugin = require('./');
describe('example2 - convenience makeGenerate', function() {
it('should work', function() {
let generate = plugin.makeGenerate({
PEG,
grammar: "start = 'a' / 'b' / 'c' / 'd' { return 'd' } / 'e'",
initializer: "var _ = require('lodash');",
rules: {
start: [
function() {
return 'b';
},
"return 'a';",
undefined,
undefined,
function() {
return _.VERSION;
}
]
},
mixins: {} // list of default rules
});
let parser = generate({
startRule: 'start',
options: {}
});
expect(parser.parse('a')).toEqual('b');
expect(parser.parse('b')).toEqual('a');
expect(parser.parse('c')).toEqual('c');
expect(parser.parse('d')).toEqual('d');
expect(parser.parse('e')).toEqual(_.VERSION);
});
});