diff --git a/spec/api/plugin-api.spec.js b/spec/api/plugin-api.spec.js index 92b2e41..73eb7f8 100644 --- a/spec/api/plugin-api.spec.js +++ b/spec/api/plugin-api.spec.js @@ -56,8 +56,6 @@ describe("plugin API", function() { it("receives configuration", function() { var plugin = { use: function(config) { - var i; - expect(config).toBeObject(); expect(config.parser).toBeObject(); @@ -66,19 +64,19 @@ describe("plugin API", function() { expect(config.passes).toBeObject(); expect(config.passes.check).toBeArray(); - for (i = 0; i < config.passes.check.length; i++) { - expect(config.passes.check[i]).toBeFunction(); - } + config.passes.check.forEach(function(pass) { + expect(pass).toBeFunction(); + }); expect(config.passes.transform).toBeArray(); - for (i = 0; i < config.passes.transform.length; i++) { - expect(config.passes.transform[i]).toBeFunction(); - } + config.passes.transform.forEach(function(pass) { + expect(pass).toBeFunction(); + }); expect(config.passes.generate).toBeArray(); - for (i = 0; i < config.passes.generate.length; i++) { - expect(config.passes.generate[i]).toBeFunction(); - } + config.passes.generate.forEach(function(pass) { + expect(pass).toBeFunction(); + }); } }; diff --git a/spec/behavior/generated-parser-behavior.spec.js b/spec/behavior/generated-parser-behavior.spec.js index f78be29..503dcca 100644 --- a/spec/behavior/generated-parser-behavior.spec.js +++ b/spec/behavior/generated-parser-behavior.spec.js @@ -26,15 +26,14 @@ describe("generated parser behavior", function() { { cache: true, optimize: "speed", trace: true }, { cache: true, optimize: "size", trace: false }, { cache: true, optimize: "size", trace: true } - ], - i; + ]; - for (i = 0; i < optionsVariants.length; i++) { + optionsVariants.forEach(function(variant) { describe( - "with options " + jasmine.pp(optionsVariants[i]), - function() { block(clone(optionsVariants[i])); } + "with options " + jasmine.pp(variant), + function() { block(clone(variant)); } ); - } + }); } beforeEach(function() { @@ -512,12 +511,12 @@ describe("generated parser behavior", function() { input: "b" } ], - parser, i; + parser; - for (i = 0; i < testcases.length; i++) { - parser = peg.generate(testcases[i].grammar, options); - expect(parser).toFailToParse(testcases[i].input); - } + testcases.forEach(function(testcase) { + parser = peg.generate(testcase.grammar, options); + expect(parser).toFailToParse(testcase.input); + }); }); }); @@ -708,12 +707,12 @@ describe("generated parser behavior", function() { input: "b" } ], - parser, i; + parser; - for (i = 0; i < testcases.length; i++) { - parser = peg.generate(testcases[i].grammar, options); - expect(parser).toFailToParse(testcases[i].input); - } + testcases.forEach(function(testcase) { + parser = peg.generate(testcase.grammar, options); + expect(parser).toFailToParse(testcase.input); + }); }); }); @@ -1077,12 +1076,12 @@ describe("generated parser behavior", function() { input: "b" } ], - parser, i; + parser; - for (i = 0; i < testcases.length; i++) { - parser = peg.generate(testcases[i].grammar, options); - expect(parser).toFailToParse(testcases[i].input); - } + testcases.forEach(function(testcase) { + parser = peg.generate(testcase.grammar, options); + expect(parser).toFailToParse(testcase.input); + }); }); }); @@ -1497,20 +1496,16 @@ describe("generated parser behavior", function() { var parser = peg.generate([ 'Expr = Sum', 'Sum = first:Product rest:(("+" / "-") Product)* {', - ' var result = first, i;', - ' for (i = 0; i < rest.length; i++) {', - ' if (rest[i][0] == "+") { result += rest[i][1]; }', - ' if (rest[i][0] == "-") { result -= rest[i][1]; }', - ' }', - ' return result;', + ' return rest.reduce(function(result, element) {', + ' if (element[0] == "+") { return result + element[1]; }', + ' if (element[0] == "-") { return result - element[1]; }', + ' }, first);', ' }', 'Product = first:Value rest:(("*" / "/") Value)* {', - ' var result = first, i;', - ' for (i = 0; i < rest.length; i++) {', - ' if (rest[i][0] == "*") { result *= rest[i][1]; }', - ' if (rest[i][0] == "/") { result /= rest[i][1]; }', - ' }', - ' return result;', + ' return rest.reduce(function(result, element) {', + ' if (element[0] == "*") { return result * element[1]; }', + ' if (element[0] == "/") { return result / element[1]; }', + ' }, first);', ' }', 'Value = digits:[0-9]+ { return parseInt(digits.join(""), 10); }', ' / "(" expr:Expr ")" { return expr; }' diff --git a/spec/unit/parser.spec.js b/spec/unit/parser.spec.js index d01b664..c83eb12 100644 --- a/spec/unit/parser.spec.js +++ b/spec/unit/parser.spec.js @@ -122,29 +122,20 @@ describe("PEG.js grammar parser", function() { function stripChildren(property) { return function(node) { - var i; - delete node.location; - for (i = 0; i < node[property].length; i++) { - strip(node[property][i]); - } + node[property].forEach(strip); }; } var strip = buildVisitor({ grammar: function(node) { - var i; - delete node.location; if (node.initializer) { strip(node.initializer); } - - for (i = 0; i < node.rules.length; i++) { - strip(node.rules[i]); - } + node.rules.forEach(strip); }, initializer: stripLeaf,