From b623396cb8732f4612e11f8219d3e2bb72afd9f2 Mon Sep 17 00:00:00 2001 From: David Majda Date: Mon, 26 Jan 2015 07:44:51 +0100 Subject: [PATCH] Behavior specs cleanup: Improve initializer specs Note that use of |text|, |offset|, |line|, and |column| inside initializer code is no longer tested and officially supported. --- .../generated-parser-behavior.spec.js | 57 ++++++------------- 1 file changed, 16 insertions(+), 41 deletions(-) diff --git a/spec/behavior/generated-parser-behavior.spec.js b/spec/behavior/generated-parser-behavior.spec.js index 29895c4..e22968c 100644 --- a/spec/behavior/generated-parser-behavior.spec.js +++ b/spec/behavior/generated-parser-behavior.spec.js @@ -127,7 +127,7 @@ describe("generated parser behavior", function() { varyOptimizationOptions(function(options) { describe("initializer", function() { - it("runs before the parsing begins", function() { + it("executes the code before parsing starts", function() { var parser = PEG.buildParser([ '{ var result = 42; }', 'start = "a" { return result; }' @@ -136,49 +136,24 @@ describe("generated parser behavior", function() { expect(parser).toParse("a", 42); }); - it("can use the |text| function", function() { - var parser = PEG.buildParser([ - '{ var result = text(); }', - 'start = "a" { return result; }' - ].join("\n"), options); - - expect(parser).toParse("a", ""); - }); - - it("can use the |offset| function to get the current parse position", function() { - var parser = PEG.buildParser([ - '{ var result = offset(); }', - 'start = "a" { return result; }' - ].join("\n"), options); - - expect(parser).toParse("a", 0); - }); - - it("can use the |line| and |column| functions to get the current line and column", function() { - var parser = PEG.buildParser([ - '{ var result = [line(), column()]; }', - 'start = "a" { return result; }' - ].join("\n"), options); - - expect(parser).toParse("a", [1, 1]); - }); - - it("can use the |parser| variable to access the parser object", function() { - var parser = PEG.buildParser([ - '{ var result = parser; }', - 'start = "a" { return result; }' - ].join("\n"), options); + describe("available variables and functions", function() { + it("|parser| contains the parser object", function() { + var parser = PEG.buildParser([ + '{ var result = parser; }', + 'start = "a" { return result; }' + ].join("\n"), options); - expect(parser).toParse("a", parser); - }); + expect(parser).toParse("a", parser); + }); - it("can use options passed to the parser", function() { - var parser = PEG.buildParser([ - '{ var result = options; }', - 'start = "a" { return result; }' - ].join("\n"), options); + it("|options| contains options", function() { + var parser = PEG.buildParser([ + '{ var result = options; }', + 'start = "a" { return result; }' + ].join("\n"), options); - expect(parser).toParse("a", { a: 42 }, { a: 42 }); + expect(parser).toParse("a", { a: 42 }, { a: 42 }); + }); }); });