Jasmine: Convert cache tests

redux
David Majda 12 years ago
parent e9f7255d47
commit 022a51f94e

@ -104,6 +104,30 @@ describe("generated parser", function() {
});
});
describe("rule matching", function() {
varyAll(function(options) {
var grammar = [
'{ var n = 0; }',
'start = (a "b") / (a "c") { return n; }',
'a = "a" { n++; }'
].join("\n");
if (options.cache) {
it("caches rule match results", function() {
var parser = PEG.buildParser(grammar, options);
expect(parser).toParse("ac", 1);
});
} else {
it("does not cache rule match results", function() {
var parser = PEG.buildParser(grammar, options);
expect(parser).toParse("ac", 2);
});
}
});
});
describe("choice matching", function() {
varyAll(function(options) {
it("matches correctly", function() {

@ -13,26 +13,6 @@ function testWithVaryingTrackLineAndColumn(name, callback) {
);
}
testWithVaryingTrackLineAndColumn("cache", function(options) {
var grammar = [
'{ var n = 0; }',
'start = (a "b") / (a "c") { return n; }',
'a = "a" { n++; }'
].join("\n");
/* Without cache */
parses(PEG.buildParser(grammar, options), "ac", 2);
options.cache = false;
parses(PEG.buildParser(grammar, options), "ac", 2);
/* With cache */
options.cache = true;
parses(PEG.buildParser(grammar, options), "ac", 1);
});
testWithVaryingTrackLineAndColumn("indempotence", function(options) {
var parser1 = PEG.buildParser('start = "abcd"', options);
var parser2 = PEG.buildParser('start = "abcd"', options);

Loading…
Cancel
Save