Skip to content

Commit

Permalink
Added first unit tests for getSubgenBaseName() #11
Browse files Browse the repository at this point in the history
  • Loading branch information
sthzg committed Jul 8, 2016
1 parent 65d0684 commit 9d9dbb0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 14 additions & 1 deletion test/utils/utilsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('populatePkgStoreFromPaths()', () => {
chai.isOk(res.length === 6, 'Expected number of entries to be 6');
chai.isOk(
res.every(x => typeof x.path === 'string' && x.path !== ''),
'Expected all items to have a non-empty path prop '
'Expected all items to have a non-empty path prop'
);
});

Expand Down Expand Up @@ -85,3 +85,16 @@ describe('getPkgInfo()', () => {
});
});
});


describe('getSubgenBaseName()', () => {
it('returns expected basename for contrib-subgen-foobar-helloworld', function () {
let bn = utils.getSubgenBaseName('foobar', ['contrib-subgen-', 'subgen-'], 'contrib-subgen-foobar-helloworld');
chai.equal(bn, 'helloworld');
});

it('returns expected basename for subgen-foobar-helloworld', function () {
let bn = utils.getSubgenBaseName('foobar', ['contrib-subgen-', 'subgen-'], 'subgen-foobar-helloworld');
chai.equal(bn, 'helloworld');
});
});
2 changes: 2 additions & 0 deletions utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ function buildPrefixRegexps(patterns, host) {
* @returns {string|void|XML|*}
*/
function getSubgenBaseName(host, patterns, pkgName) {
// TODO gh_issue 13, return Success or Error record
const sorted = sortCharArrByLength(patterns);
const regexps = buildPrefixRegexps(sorted, host);
const prefix = regexps.find(regex => regex.exec(pkgName) !== null);
Expand Down Expand Up @@ -227,6 +228,7 @@ module.exports = {
checkPkgExists,
getPkgInfo,
getInstalledPkgPaths,
getSubgenBaseName,
findExternalSubgens,
populatePkgStoreFromPaths
};

0 comments on commit 9d9dbb0

Please sign in to comment.