-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrepotests.js
107 lines (93 loc) · 2.99 KB
/
repotests.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*globals module, require, console, exports*/
var fs = require('fs');
var nu = require('nodeunit');
var load = require('./load');
var pegjs = require('pegjs');
var ref = fs.readFileSync("bm.scm", "utf8");
var parserTests = {
basics: function (test) {
var par = this.par;
test.expect(6);
test.equal(par(""), undefined, "don't parse empty string");
test.deepEqual(par("@"), "@", "single char @");
test.deepEqual(par("atom"), "atom", "word");
test.deepEqual(par("(a b c)"), ["a", "b", "c"], "abc");
test.deepEqual(par("(+ x 3)"), ["+", "x", "3"], "parse (+ x 3)");
test.deepEqual(par("(+ 1 (f x 3 y))"), ["+", "1", ["f", "x", "3", "y"]], "parse (+ 1 (f x 3 y))");
test.done();
}
, space : function (test) {
var par = this.par;
test.expect(6);
test.equal(par(" "), undefined, "don't parse white space only string");
test.deepEqual(par(" @"), "@", " @");
test.deepEqual(par("atom "), "atom", "atom ");
test.deepEqual(par(" ( a b c ) "), ["a", "b", "c"], " ( a b c ) ");
test.deepEqual(par("(+ \t x \n 3)"), ["+", "x", "3"], "parse (+ \t x \n 3)");
test.deepEqual(par("(+ 1 \n \t (f x 3 y) \n)"), ["+", "1", ["f", "x", "3", "y"]], "(+ 1 \n \t (f x 3 y) \n)");
test.done();
}
, quote : function (test) {
var par = this.par;
test.expect(3);
test.deepEqual(par("'x"), ["quote", "x"], "'x");
test.deepEqual(par("'(1 2 3)"), ["quote", ["1", "2", "3"]]);
test.deepEqual(par("(+ '1 \n \t (f x 3 y) \n)"), ["+", ["quote", "1"], ["f", "x", "3", "y"]], "(+ '1 \n \t (f x 3 y) \n)");
test.done();
}
, comments : function (test) {
var par = this.par;
test.expect(3);
test.equal(par(";; this is a comment"), undefined, "don't parse comment only");
test.deepEqual(par(";; first comment\nx"), "x", ";; first comment\n x");
test.deepEqual(par("x\n;; later comment"), "x", "x\n;; later comment");
test.done();
}
, reference : function (test) {
var par = this.par;
test.expect(1);
test.deepEqual(par(ref), ["+", "1", "2", "f", ["x", "y", "z", ["quote", ["1", "2", "3"]]], "g", ["1", "2", "atome", "just", "kidding"]], "reference one");
test.done();
}
};
var clone = function (obj) {
var ret = {};
var key;
for (key in obj) {
if (obj.hasOwnProperty(key)) {
ret[key] = obj[key];
}
}
return ret;
};
var tests = {};
load(function (par, name) {
var t = tests[name] = clone(parserTests);
t.setUp = function (cb) {
this.par = par;
cb();
};
try{
nu.runSuite(name, t, {}, function (a, b) {
var i
, count = 0
, failed = 0
, n = b.length
;
for (i = 0; i < n; i += 1 ){
count += 1;
if (b[i].failed() ) {
failed += 1;
//console.log(name, b[i].error);
}
}
if (failed > 0) {
console.log(name, failed, "failed out of", count );
}
});
} catch (e) {
console.log(name, "error");
}
}, function () {
;
});