From 022a51f94e32a76e726a14b74da9d111f32dd0f4 Mon Sep 17 00:00:00 2001 From: David Majda Date: Sun, 22 Apr 2012 17:01:02 +0200 Subject: [PATCH] Jasmine: Convert cache tests --- spec/generated-parser.spec.js | 24 ++++++++++++++++++++++++ test/compiler-test.js | 20 -------------------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/spec/generated-parser.spec.js b/spec/generated-parser.spec.js index 4c58ef5..1d39cfa 100644 --- a/spec/generated-parser.spec.js +++ b/spec/generated-parser.spec.js @@ -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() { diff --git a/test/compiler-test.js b/test/compiler-test.js index 3ff968b..7915317 100644 --- a/test/compiler-test.js +++ b/test/compiler-test.js @@ -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);