New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

completion

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

completion - npm Package Compare versions

Comparing version
0.3.1
to
0.3.2
+30
test/utils/cursor.js
// Load in dependencies
var assert = require('assert');
/**
* Takes a command and breaks it down to its `completion` parameters
* 'git ad|README' -> {line: 'git adREADME', cursor: 6}
*/
// TODO: We should break this into another lib
exports.splitAtCursor = function (cmd) {
var parts = cmd.split('|');
return {
cursor: parts[0].length,
line: parts.join('')
};
};
// DEV: Internal util test
// TODO: We should break this into another lib
describe('A command', function () {
var command = 'git ad|README';
describe('broken down into parameters', function () {
it('is as expected', function () {
var actualParams = exports.splitAtCursor(command);
assert.deepEqual(actualParams, {
cursor: 6,
line: 'git adREADME'
});
});
});
});
+2
-0
# completion changelog
0.3.2 - Refactored tests to be more utility based
0.3.1 - Fixed node@0.8 for Travis CI

@@ -3,0 +5,0 @@

+1
-1
{
"name": "completion",
"description": "Completion library for words, commands, and sentences",
"version": "0.3.1",
"version": "0.3.2",
"homepage": "https://github.com/twolfson/completion",

@@ -6,0 +6,0 @@ "author": {

@@ -0,52 +1,44 @@

// Load in dependencies
var assert = require('assert');
var Completion = require('../');
var testUtils = require('./utils/index');
var cursorUtils = require('./utils/cursor');
// DEV: Internal util test
// TODO: We should break this into another lib
describe('A command', function () {
before(function () {
this.command = 'git ad|README';
});
describe('broken down into parameters', function () {
before(function () {
this.params = testUtils.commandToParams(this.command);
});
it('is as expected', function () {
assert.deepEqual(this.params, {
cursor: 6,
line: 'git adREADME'
// Define set of utilities for `completion`
var completionUtils = {
completeCommand: function (command) {
before(function (done) {
var params = cursorUtils.splitAtCursor(command);
var that = this;
this.completion.complete(params, function (err, results) {
that.results = results;
done(err);
});
});
});
});
function completeCommand() {
before(function (done) {
var that = this;
this.completion.complete(this.params, function (err, results) {
that.actual = results;
done(err);
after(function () {
delete this.results;
});
});
}
},
init: function (params) {
before(function initCompletion () {
this.completion = new Completion(params);
});
after(function cleanupCompletion () {
delete this.completion;
});
}
};
function assertExpected() {
assert.deepEqual(this.actual, this.expected);
}
describe('A partial command with one completion match', function () {
before(function () {
this.params = testUtils.commandToParams('npm pub|');
this.expected = ['publish'];
this.completion = new Completion({
npm: {
publish: null
}
});
completionUtils.init({
npm: {
publish: null
}
});
describe('being completed', function () {
completeCommand();
it('returns its match', assertExpected);
completionUtils.completeCommand('npm pub|');
it('returns its match', function () {
assert.deepEqual(this.results, ['publish']);
});
});

@@ -56,20 +48,19 @@ });

describe('A partial command with multiple completions', function () {
before(function () {
this.params = testUtils.commandToParams('git ch|');
this.expected = ['checkout', 'cherry-pick'];
this.completion = new Completion({
git: {
checkout: function (params, cb) {
cb(null, ['hello.world']);
},
'cherry-pick': function (params, cb) {
cb(null, ['maraschino']);
}
completionUtils.init({
git: {
checkout: function (params, cb) {
cb(null, ['hello.world']);
},
'cherry-pick': function (params, cb) {
cb(null, ['maraschino']);
}
});
}
});
describe('being completed', function () {
completeCommand();
it('returns all of its matches', assertExpected);
completionUtils.completeCommand('git ch|');
it('returns all of its matches', function () {
assert.deepEqual(this.results, ['checkout', 'cherry-pick']);
});
});

@@ -79,20 +70,19 @@ });

describe('A partial command in junction with the item', function () {
before(function () {
this.params = testUtils.commandToParams('git che|world');
this.expected = ['checkout', 'cherry-pick'];
this.completion = new Completion({
git: {
checkout: function (params, cb) {
cb(null, ['hello.world']);
},
'cherry-pick': function (params, cb) {
cb(null, ['maraschino']);
}
completionUtils.init({
git: {
checkout: function (params, cb) {
cb(null, ['hello.world']);
},
'cherry-pick': function (params, cb) {
cb(null, ['maraschino']);
}
});
}
});
describe('being completed', function () {
completeCommand();
it('returns the command\'s match', assertExpected);
completionUtils.completeCommand('git che|world');
it('returns the command\'s match', function () {
assert.deepEqual(this.results, ['checkout', 'cherry-pick']);
});
});

@@ -102,15 +92,14 @@ });

describe('A terminal command', function () {
before(function () {
this.params = testUtils.commandToParams('npm publish|');
this.expected = ['publish'];
this.completion = new Completion({
npm: {
publish: null
}
});
completionUtils.init({
npm: {
publish: null
}
});
describe('being completed', function () {
completeCommand();
it('returns the command (for spacing)', assertExpected);
completionUtils.completeCommand('npm publish|');
it('returns the command (for spacing)', function () {
assert.deepEqual(this.results, ['publish']);
});
});

@@ -120,15 +109,14 @@ });

describe('A terminal command with whitespace', function () {
before(function () {
this.params = testUtils.commandToParams('npm publish |');
this.expected = [];
this.completion = new Completion({
npm: {
publish: null
}
});
completionUtils.init({
npm: {
publish: null
}
});
describe('being completed', function () {
completeCommand();
it('returns nothing', assertExpected);
completionUtils.completeCommand('npm publish |');
it('returns nothing', function () {
assert.deepEqual(this.results, []);
});
});

@@ -138,18 +126,17 @@ });

describe('A terminal command with a completion function', function () {
before(function () {
this.params = testUtils.commandToParams('git checkout hello|');
this.expected = ['hello-world', 'hello-there'];
this.completion = new Completion({
git: {
checkout: function (params, cb) {
cb(null, ['hello-world', 'hello-there']);
}
completionUtils.init({
git: {
checkout: function (params, cb) {
cb(null, ['hello-world', 'hello-there']);
}
});
}
});
describe('being completed', function () {
completeCommand();
it('returns the results of the completion', assertExpected);
completionUtils.completeCommand('git checkout hello|');
it('returns the results of the completion', function () {
assert.deepEqual(this.results, ['hello-world', 'hello-there']);
});
});
});
/**
* Takes a command and breaks it down to its `completion` parameters
* 'git ad|README' -> {line: 'git adREADME', cursor: 6}
*/
// TODO: We should break this into another lib
exports.commandToParams = function (cmd) {
var parts = cmd.split('|');
return {
cursor: parts[0].length,
line: parts.join('')
};
};