Skip to content

Commit

Permalink
Fix parsing of some parameter formats in argscheck.checkArgs (#200)
Browse files Browse the repository at this point in the history
  • Loading branch information
raphinesse authored May 2, 2019
1 parent e1b2a49 commit f0dfd36
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/common/argscheck.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var typeMap = {
};

function extractParamName (callee, argIndex) {
return (/.*?\((.*?)\)/).exec(callee)[1].split(', ')[argIndex];
return (/\(\s*([^)]*?)\s*\)/).exec(callee)[1].split(/\s*,\s*/)[argIndex];
}

function checkArgs (spec, functionName, args, opt_callee) {
Expand Down
18 changes: 18 additions & 0 deletions test/test.argscheck.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,22 @@ describe('argscheck', function () {
argscheck.enableChecks = false;
testFunc();
});
it('Test#012 : should be able to extract from all kinds of parameter formats', () => {
const check = args => argscheck.checkArgs('ss', 'testFn', args);

function sparse (
a,
b
) { check(arguments); }
expect(() => sparse(null, '')).toThrowError(/parameter "a"/);
expect(() => sparse('', null)).toThrowError(/parameter "b"/);

// eslint-disable-next-line comma-spacing
function dense (a,b) { check(arguments); }
expect(() => dense('', null)).toThrowError(/parameter "b"/);

// eslint-disable-next-line comma-spacing, space-in-parens
function funky ( a ,b ) { check(arguments); }
expect(() => funky(null, '')).toThrowError(/parameter "a"/);
});
});

0 comments on commit f0dfd36

Please sign in to comment.