Skip to content

Commit

Permalink
Rename _export to export where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
nfischer committed Feb 28, 2016
1 parent b02983a commit 991b60e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion dist/commands/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ module.exports = function (vorpal) {
if (vorpal === undefined) {
return _export;
}
vorpal.api._export = _export;
vorpal.api.export = _export;
vorpal.command('export [name...]').parse(preparser).option('-p', 'print all defined aliases in a reusable format').action(function (args, callback) {
args.options = args.options || {};
return interfacer.call(this, {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ module.exports = function (vorpal) {
if (vorpal === undefined) {
return _export;
}
vorpal.api._export = _export;
vorpal.api.export = _export;
vorpal
.command('export [name...]')
.parse(preparser)
Expand Down
46 changes: 23 additions & 23 deletions test/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,86 +20,86 @@ describe('export', function () {
});

it('should exist and be a function', function () {
should.exist(cash._export);
should.exist(cash.export);
});

it('should create an export with an equal symbol', function () {
(function () {
cash._export(['foo=bar']);
cash.export(['foo=bar']);
}).should.not.throw();
cash('echo $foo').should.equal('bar\n');
});

it('should accept a string argument', function () {
(function () {
cash._export('foo=bar');
cash.export('foo=bar');
}).should.not.throw();
cash('echo $foo').should.equal('bar\n');
});

it('should print msg when reading an invalid export', function () {
cash._export(['1lalalala']).should.equal('-cash: export: `1lalalala\': not a valid identifier\n');
cash._export(['la@lalala']).should.equal('-cash: export: `la@lalala\': not a valid identifier\n');
cash.export(['1lalalala']).should.equal('-cash: export: `1lalalala\': not a valid identifier\n');
cash.export(['la@lalala']).should.equal('-cash: export: `la@lalala\': not a valid identifier\n');
});

it('should reassign an export', function () {
(function () {
cash._export(['foo=cows']);
cash._export(['foo=dogs']);
cash.export(['foo=cows']);
cash.export(['foo=dogs']);
}).should.not.throw();
cash('echo $foo').should.equal('dogs\n');
});

it('should do nothing if already exported', function () {
(function () {
cash._export(['PATH=/usr/bin']);
cash._export(['PATH']);
cash.export(['PATH=/usr/bin']);
cash.export(['PATH']);
}).should.not.throw();
cash('echo $PATH').should.equal(`${process.env.PATH}\n`);
cash('echo $PATH').should.equal('/usr/bin\n');
});

it('should work without surrounding quotes', function () {
cash._export(['foo=bar']);
cash.export(['foo=bar']);
cash('echo $foo').should.equal('bar\n');
});

it('should deal with surrounding single quotes', function () {
cash._export(['foo=\'bar tender nice to meet you\'']);
cash.export(['foo=\'bar tender nice to meet you\'']);
cash('echo $foo').should.equal('bar tender nice to meet you\n');
});

it('should deal with surrounding double quotes', function () {
cash._export(['foo="bar tender nice to meet you"']);
cash.export(['foo="bar tender nice to meet you"']);
cash('echo $foo').should.equal('bar tender nice to meet you\n');
});

it('should handle multiple exports', function () {
(function () {
cash._export(['a="A"']);
cash._export(['b=\'B\'']);
cash._export(['c="C"']);
cash.export(['a="A"']);
cash.export(['b=\'B\'']);
cash.export(['c="C"']);
}).should.not.throw();
cash('echo $a $b $c').should.equal('A B C\n');
});

it('should list all registered aliases', function () {
(function () {
cash._export(['a="A"']);
cash._export(['b=\'B\'']);
cash._export(['c="C"']);
cash.export(['a="A"']);
cash.export(['b=\'B\'']);
cash.export(['c="C"']);
}).should.not.throw();
cash._export().should.equal('declare -x a="A"\ndeclare -x b="B"\ndeclare -x c="C"\n');
cash.export().should.equal('declare -x a="A"\ndeclare -x b="B"\ndeclare -x c="C"\n');
});

describe('-p', function () {
it('should list all registered exports', function () {
(function () {
cash._export(['a="A"']);
cash._export(['b=\'B\'']);
cash._export(['c="C"']);
cash.export(['a="A"']);
cash.export(['b=\'B\'']);
cash.export(['c="C"']);
}).should.not.throw();
cash._export(undefined, {p: true}).should.equal('declare -x a="A"\ndeclare -x b="B"\ndeclare -x c="C"\n');
cash.export(undefined, {p: true}).should.equal('declare -x a="A"\ndeclare -x b="B"\ndeclare -x c="C"\n');
});
});
});

0 comments on commit 991b60e

Please sign in to comment.