Specs cleanup: Rename & simplify |varyAll|

Rename |varyAll| to |varyOptimizationOptions|, because that's what the
function does. Simplify as we don't need a fully generic solution.
redux
David Majda 10 years ago
parent 3d637173ee
commit 0306a76152

@ -1,43 +1,31 @@
describe("generated parser", function() { describe("generated parser", function() {
function vary(names, block) { function varyOptimizationOptions(block) {
var values = { function clone(object) {
cache: [false, true], var result = {}, key;
optimize: ["speed", "size"]
};
function varyStep(names, options) { for (key in object) {
var clonedOptions = {}, key, name, i; if (object.hasOwnProperty(key)) {
result[key] = object[key];
if (names.length === 0) {
/*
* We have to clone the options so that the block can save them safely
* (e.g. by capturing in a closure) without the risk that they will be
* changed later.
*/
for (key in options) {
if (options.hasOwnProperty(key)) {
clonedOptions[key] = options[key];
}
}
describe(
"with options " + jasmine.pp(clonedOptions),
function() { block(clonedOptions); }
);
} else {
name = names[0];
for (i = 0; i < values[name].length; i++) {
options[name] = values[name][i];
varyStep(names.slice(1), options);
} }
} }
}
varyStep(names, {}); return result;
} }
function varyAll(block) { var optionsVariants = [
vary(["cache", "optimize"], block); { cache: false, optimize: "speed" },
{ cache: false, optimize: "size" },
{ cache: true, optimize: "speed" },
{ cache: true, optimize: "size" },
],
i;
for (i = 0; i < optionsVariants.length; i++) {
describe(
"with options " + jasmine.pp(optionsVariants[i]),
function() { block(clone(optionsVariants[i])); }
);
}
} }
beforeEach(function() { beforeEach(function() {
@ -164,7 +152,7 @@ describe("generated parser", function() {
}); });
}); });
varyAll(function(options) { varyOptimizationOptions(function(options) {
describe("initializer code", function() { describe("initializer code", function() {
it("runs before the parsing begins", function() { it("runs before the parsing begins", function() {
var parser = PEG.buildParser([ var parser = PEG.buildParser([

Loading…
Cancel
Save