Skip to content

Commit

Permalink
test: recover some coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
mklabs committed Jul 22, 2018
1 parent c861535 commit 4c7bce2
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 8 deletions.
12 changes: 6 additions & 6 deletions lib/index.js
Expand Up @@ -66,11 +66,6 @@ tabtab.install = (options = { name: '', completer: '' }) => {
* Returns the data env object.
*/
tabtab.parseEnv = (options = {}, env) => {
// debug('COMP_CWORD', env.COMP_CWORD);
// debug('COMP_LINE', env.COMP_LINE);
// debug('COMP_POINT', env.COMP_POINT);

options = options || {};
const args = options._;

let cword = Number(env.COMP_CWORD);
Expand Down Expand Up @@ -128,7 +123,7 @@ tabtab.parseEnv = (options = {}, env) => {
**/
tabtab.log = (args, env) => {
if (!env) {
env = tabtab.parseEnv(process.env);
env = tabtab.parseEnv({ _: [] }, process.env);
}

const shell = tabtab.shell();
Expand All @@ -139,6 +134,11 @@ tabtab.log = (args, env) => {
for (const arg of args) {
console.log(`\n${arg}`);
}

return {
args,
env
};
};

module.exports = tabtab;
38 changes: 36 additions & 2 deletions test/basic.js
Expand Up @@ -10,12 +10,46 @@ describe('tabtab basic suite', () => {
it('has a tabtab.log function', () => {
assert.equal(typeof tabtab.log, 'function');

const env = Object.assign({}, process.env, {
const environment = Object.assign({}, process.env, {
COMP_CWORD: 2,
COMP_LINE: 'tabtab --foo',
COMP_POINT: 12
});

tabtab.log(['--foo', '--bar'], env);
const env = tabtab.parseEnv({ _: ['tabtab'] }, environment);

const result = tabtab.log(['--foo', '--bar'], env);
assert.deepEqual(result.args, ['--foo']);
assert.deepEqual(result.env, env);
});

it('has a tabtab.log function, without env', () => {
const result = tabtab.log(['--foo', '--bar']);
assert.deepEqual(result.args, ['--foo', '--bar']);
assert.deepEqual(result.env, {
args: [],
complete: false,
last: '',
lastPartial: '',
line: '',
partial: '',
point: 0,
prev: undefined,
words: 0
});
});

it('tabtab.shell()', () => {
let shell = tabtab.shell();
assert.equal(shell, 'bash');

shell = tabtab.shell({ SHELL: '/bin/bash' });
assert.equal(shell, 'bash');

shell = tabtab.shell({ SHELL: '/usr/bin/zsh'});
assert.equal(shell, 'zsh');

shell = tabtab.shell({ SHELL: '/usr/bin/fish'});
assert.equal(shell, 'fish');
});
});

0 comments on commit 4c7bce2

Please sign in to comment.