-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.js
53 lines (45 loc) · 1.13 KB
/
tests.js
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
var _ = require("lodash");
var test = require("tape");
var nearley = require("nearley");
var grammar = require("./test-grammar");
var unparse = require("./");
var parse = function(src, start){
start = start || grammar.ParserStart;
var p = new nearley.Parser(grammar.ParserRules, start);
p.feed(src);
if(p.results.length !== 1){
throw new Error(
"Parsing Ambiguity: " + p.results.length + " parsings found"
);
}
return p.results[0];
};
var reparseNTimes = function(t, n_runs, opts){
opts = opts || {};
};
test("it", function(t){
t.equals(unparse(grammar, {
start: "bar"
}), "bar");
t.equals(unparse(grammar, {
start: "bar",
override_rule: {bar: function(){return "baz";}}
}), "baz");
_.each(_.range(0, 1000), function(){
var src = unparse(grammar);
try{
parse(src);
t.ok(true);
}catch(e){
t.fail(e + '');
}
});
var max_len = 0;
_.each(_.range(0, 1000), function(){
var src = unparse(grammar, {start: "foo"});
t.ok(/^foo[0-9]+/.test(src));
max_len = Math.max(max_len, src.length);
});
t.ok(max_len > 4, "regex is not recursing");
t.end();
});