Skip to content

Commit

Permalink
#98 handle parameter mismatch
Browse files Browse the repository at this point in the history
Signed-off-by: NivedhaSenthil <nivedhasenthil@gmail.com>
  • Loading branch information
NivedhaSenthil committed Sep 28, 2020
1 parent 5cd2a06 commit dcf7885
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/gauge-global.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var step = function (stepName, options, stepFunction) {
if (typeof stepName === "object" && !!stepName.length) {
stepRegistry.addAlias(stepName, stepFunction, filepath, {}, options);
} else if (typeof stepName === "string") {
stepRegistry.add(stepName, stepFunction, filepath, {}, options);
stepRegistry.add(stepName, stepFunction, null, filepath, {}, options);
}
};

Expand Down
7 changes: 4 additions & 3 deletions src/static-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ function hasAliases(node) {
return node.type === "ArrayExpression" && !!node.elements.length;
}

function addStep(step, info) {
stepRegistry.add(step.value, null, info.filePath, info.span, null);
function addStep(step, info, params) {
stepRegistry.add(step.value, null, params, info.filePath, info.span, null);
}

function addAliases(aliases, info) {
Expand All @@ -23,6 +23,7 @@ function addAliases(aliases, info) {

function processNode(node, filePath) {
var stepNode = node.arguments[0];
var stepFunc = node.arguments[1] ? node.arguments[1]: null;
var span = {
start: node.loc.start.line,
end: node.loc.end.line,
Expand All @@ -33,7 +34,7 @@ function processNode(node, filePath) {
if (hasAliases(stepNode)) {
addAliases(stepNode.elements, { filePath: filePath, span: span });
} else if (stepNode.type === "Literal") {
addStep(stepNode, { filePath: filePath, span: span });
addStep(stepNode, { filePath: filePath, span: span }, stepFunc ? stepFunc.params.length : null);
}
} catch (e) {
logger.info(e);
Expand Down
6 changes: 5 additions & 1 deletion src/step-registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var StepRegistry = function () {
* @param options Optional parameters defined with the step.
* @returns The step added.
*/
StepRegistry.prototype.add = function (stepText, stepFunction, filePath, span, options) {
StepRegistry.prototype.add = function (stepText, stepFunction, stepFuncParams, filePath, span, options) {
if (!stepText.length) {
throw new Error("Step text cannot be empty.");
}
Expand All @@ -27,6 +27,7 @@ StepRegistry.prototype.add = function (stepText, stepFunction, filePath, span, o

this.registry[generalisedText] = {
fn: stepFunction,
fnParamsCount: stepFuncParams,
stepText: stepText,
generalisedText: generalisedText,
fileLocations: [
Expand Down Expand Up @@ -117,6 +118,9 @@ StepRegistry.prototype.validate = function (stepName) {
if (!step) {
return { valid: false, reason: "notfound", file: null };
}
if (step.fnParamsCount !== stepParser.getParams(step.stepText).length) {
return { valid: false, reason: "parameter mismatch", file: step.fileLocations[0].filePath };
}
if (step.fileLocations.length > 1) {
return { valid: false, reason: "duplicate", file: step.fileLocations[0].filePath };
}
Expand Down

0 comments on commit dcf7885

Please sign in to comment.