mirror of
https://github.com/bower/bower.git
synced 2026-02-03 10:34:59 -05:00
- results of the first lookup is cached to ~/.bower/completion/install.json - consider caching in ~/.bower/cache instead, so that cache-clean command also removes completion cache.
130 lines
3.3 KiB
JavaScript
130 lines
3.3 KiB
JavaScript
/*jshint plusplus:false*/
|
|
|
|
var fs = require('fs');
|
|
var path = require('path');
|
|
var assert = require('assert');
|
|
|
|
var complete = require('../lib/util/completion');
|
|
var command = require('../lib/commands/completion');
|
|
var commands = require('../lib/commands');
|
|
|
|
describe('completion', function () {
|
|
|
|
before(function () {
|
|
this.opts = complete(['bower', 'install'], {
|
|
COMP_CWORD: '2',
|
|
COMP_LINE: 'bower install',
|
|
COMP_POINT: '14'
|
|
});
|
|
});
|
|
|
|
beforeEach(function() {
|
|
this.log = complete.log;
|
|
});
|
|
|
|
afterEach(function () {
|
|
complete.log = this.log;
|
|
});
|
|
|
|
it('parses COMP_* in the env', function () {
|
|
assert.deepEqual(this.opts, {
|
|
w: 2,
|
|
words: [ 'bower', 'install' ],
|
|
word: 'install',
|
|
line: 'bower install',
|
|
point: 14,
|
|
length: 13,
|
|
partialLine: 'bower install',
|
|
partialWords: [ 'bower', 'install' ]
|
|
});
|
|
});
|
|
|
|
|
|
it('filters out completion results', function () {
|
|
var completed = [
|
|
'backbone',
|
|
'backbone-forms',
|
|
'backbone-paginator',
|
|
'backbone.forms',
|
|
'backbone.paginator'
|
|
];
|
|
|
|
var all = complete.abbrev({ word: 'ba' });
|
|
var none = complete.abbrev({ word: 'foobar' });
|
|
var form = complete.abbrev({ word: 'backbone-form' });
|
|
var dots = complete.abbrev({ word: 'backbone.' });
|
|
var dashed = complete.abbrev({ word: 'backbone-' });
|
|
|
|
assert.deepEqual(completed.filter(all), completed);
|
|
assert.deepEqual(completed.filter(none), []);
|
|
assert.deepEqual(completed.filter(form), ['backbone-forms']);
|
|
assert.deepEqual(completed.filter(dashed), ['backbone-forms', 'backbone-paginator']);
|
|
assert.deepEqual(completed.filter(dots), ['backbone.forms', 'backbone.paginator']);
|
|
});
|
|
|
|
|
|
it('dumps the script when COMP_* aren\'t in the env', function (done) {
|
|
command().on('end', function (data) {
|
|
var script = fs.readFileSync(path.join(__dirname, '../templates/completion.mustache'), 'utf8');
|
|
assert.equal(data, script);
|
|
done();
|
|
});
|
|
});
|
|
|
|
it('completes the list of command on first word', function () {
|
|
complete.log = function (results, opts) {
|
|
assert.deepEqual(results, Object.keys(commands));
|
|
};
|
|
|
|
command([''], {
|
|
COMP_CWORD: '1',
|
|
COMP_LINE: 'bower ',
|
|
COMP_POINT: '6'
|
|
});
|
|
});
|
|
|
|
it('completes the list of options on first word', function () {
|
|
complete.log = function (results, opts) {
|
|
assert.deepEqual(results, ['--no-color', '--help', '--version']);
|
|
};
|
|
|
|
command(['-'], {
|
|
COMP_CWORD: '1',
|
|
COMP_LINE: 'bower -',
|
|
COMP_POINT: '7'
|
|
});
|
|
});
|
|
|
|
it('completes the list of command on invalid command', function () {
|
|
complete.log = function (results, opts) {
|
|
assert.deepEqual(results, Object.keys(commands));
|
|
};
|
|
|
|
command(['foobar'], {
|
|
COMP_CWORD: '1',
|
|
COMP_LINE: 'bower foobar',
|
|
COMP_POINT: '12'
|
|
});
|
|
});
|
|
|
|
it('delegates to command.completion for each bower command', function (done) {
|
|
complete.log = function (results, opts) {
|
|
assert.ok(results.length);
|
|
|
|
var jq = results.filter(function (res) {
|
|
return res === 'jquery';
|
|
});
|
|
|
|
assert.equal(jq.length, 1);
|
|
};
|
|
|
|
var cmd = command(['install', 'jquery-'], {
|
|
COMP_CWORD: '2',
|
|
COMP_LINE: 'bower install jquery-',
|
|
COMP_POINT: '14'
|
|
});
|
|
|
|
cmd.on('end', done);
|
|
});
|
|
});
|