lots of work fixing bugs with the command line, also removal of useless console.log

This commit is contained in:
Joe Walker 2010-12-11 19:01:02 +00:00
commit 9cff2e0908
10 changed files with 385 additions and 240 deletions

View file

@ -125,19 +125,19 @@ exports.testTokenize = function() {
exports.testSplit = function() {
var args = tokenize('s');
var command = split(args);
var conversion = split(args);
test.verifyEqual(1, args.length);
test.verifyEqual('s', args[0].text);
test.verifyUndefined(command);
test.verifyNull(conversion.value);
var args = tokenize('set');
var command = split(args);
var conversion = split(args);
test.verifyEqual([], args);
test.verifyEqual('set', command.name);
test.verifyEqual('set', conversion.value.name);
var args = tokenize('set a b');
var command = split(args);
test.verifyEqual('set', command.name);
var conversion = split(args);
test.verifyEqual('set', conversion.value.name);
test.verifyEqual(2, args.length);
test.verifyEqual('a', args[0].text);
test.verifyEqual('b', args[1].text);
@ -152,14 +152,26 @@ exports.testCli = function() {
var settingAssignment;
var valueAssignment;
var cli = new CliRequisition();
var debug = true;
function update(input) {
if (debug) {
console.log('####### TEST: typed="' + input.typed + '" cursor:', input.cursor);
}
cli.update(input);
hints = cli.getHints();
hint0 = (hints.length !== 0) ? hints[0] : undefined;
if (debug) {
console.log('cli=', cli);
console.log('hints=', hints);
}
if (cli.command && cli.command.name === 'set') {
settingAssignment = cli.getAssignment('setting');
valueAssignment = cli.getAssignment('value');
if (debug) {
console.log('settingAssignment=', settingAssignment);
console.log('valueAssignment=', valueAssignment);
}
}
else {
settingAssignment = undefined;
@ -167,6 +179,12 @@ exports.testCli = function() {
}
}
function verifyPredictionsContains(name, predictions) {
return predictions.every(function(prediction) {
return name === prediction || name === prediction.name;
}, this);
}
var historyLengthSetting = settings.getSetting('historyLength');
update({ typed: '', cursor: { start: 0, end: 0 } });
@ -184,8 +202,9 @@ exports.testCli = function() {
test.verifyEqual(1, hint0.end);
test.verifyTrue(hint0.predictions.length > 0);
// This is slightly fragile because it depends on the configuration
// TODO: Mock, but first we need a way to have a clear canon.
test.verifyTrue(hint0.predictions.length < 20);
test.verifyNotEqual(-1, hint0.predictions.indexOf('set'));
verifyPredictionsContains('set', hint0.predictions);
test.verifyNull(cli.command);
update({ typed: 'set', cursor: { start: 3, end: 3 } });
@ -196,73 +215,79 @@ exports.testCli = function() {
test.verifyEqual('set', cli.command.name);
update({ typed: 'set ', cursor: { start: 4, end: 4 } });
test.verifyEqual(1, hints.length);
test.verifyEqual(2, hints.length);
test.verifyEqual(Status.VALID, hint0.status);
test.verifyEqual(0, hint0.start);
// Technically the command ends at 3, but we're returning 4 currently.
// This is caused by us using the whole input to determine the length.
// Maybe one day we should fix this?
//test.verifyEqual(3, hint0.end);
test.verifyEqual(4, hint0.start);
test.verifyEqual(4, hint0.end);
test.verifyEqual(Status.VALID, hints[1].status);
test.verifyEqual(0, hints[1].start);
test.verifyEqual(3, hints[1].end);
test.verifyEqual('set', cli.command.name);
update({ typed: 'set h', cursor: { start: 5, end: 5 } });
test.verifyEqual(1, hints.length);
test.verifyEqual(2, hints.length);
test.verifyEqual(Status.INCOMPLETE, hint0.status);
test.verifyTrue(hint0.predictions.length > 0);
test.verifyEqual(4, hint0.start);
test.verifyEqual(5, hint0.end);
test.verifyNotEqual(-1, hint0.predictions.indexOf('historyLength'));
test.verifyTrue(hint0.predictions.length > 0);
verifyPredictionsContains('historyLength', hint0.predictions);
test.verifyEqual('set', cli.command.name);
test.verifyEqual('h', settingAssignment.arg.text);
test.verifyEqual(undefined, settingAssignment.value);
update({ typed: 'set historyLengt', cursor: { start: 16, end: 16 } });
test.verifyEqual(1, hints.length);
test.verifyEqual(2, hints.length);
test.verifyEqual(Status.INCOMPLETE, hint0.status);
test.verifyEqual(1, hint0.predictions.length);
test.verifyEqual(4, hint0.start);
test.verifyEqual(16, hint0.end);
test.verifyEqual('historyLength', hint0.predictions[0]);
test.verifyEqual(1, hint0.predictions.length);
verifyPredictionsContains('historyLength', hint0.predictions);
test.verifyEqual('set', cli.command.name);
test.verifyEqual('historyLengt', settingAssignment.arg.text);
test.verifyEqual(undefined, settingAssignment.value);
update({ typed: 'set historyLengt', cursor: { start: 1, end: 1 } });
test.verifyEqual(1, hints.length);
test.verifyEqual(Status.INVALID, hint0.status);
test.verifyEqual(4, hint0.start);
test.verifyEqual(16, hint0.end);
test.verifyEqual(1, hint0.predictions.length);
test.verifyEqual('historyLength', hint0.predictions[0]);
test.verifyEqual(2, hints.length);
test.verifyEqual(Status.VALID, hint0.status);
test.verifyEqual(0, hint0.start);
test.verifyEqual(3, hint0.end);
test.verifyEqual(Status.INVALID, hints[1].status);
test.verifyEqual(4, hints[1].start);
test.verifyEqual(16, hints[1].end);
test.verifyEqual(1, hints[1].predictions.length);
verifyPredictionsContains('historyLength', hints[1].predictions);
test.verifyEqual('set', cli.command.name);
test.verifyEqual('historyLengt', settingAssignment.arg.text);
test.verifyEqual(undefined, settingAssignment.value);
update({ typed: 'set historyLengt ', cursor: { start: 17, end: 17 } });
test.verifyEqual(1, hints.length);
test.verifyEqual(Status.INVALID, hint0.status);
test.verifyEqual(4, hint0.start);
test.verifyEqual(16, hint0.end);
test.verifyEqual(1, hint0.predictions.length);
test.verifyEqual('historyLength', hint0.predictions[0]);
test.verifyEqual(3, hints.length);
test.verifyEqual(Status.VALID, hint0.status);
test.verifyEqual(17, hint0.start);
test.verifyEqual(17, hint0.end);
test.verifyEqual(Status.INVALID, hints[1].status);
test.verifyEqual(4, hints[1].start);
test.verifyEqual(16, hints[1].end);
test.verifyEqual(1, hints[1].predictions.length);
verifyPredictionsContains('historyLength', hints[1].predictions);
test.verifyEqual('set', cli.command.name);
test.verifyEqual('historyLengt', settingAssignment.arg.text);
test.verifyEqual(undefined, settingAssignment.value);
update({ typed: 'set historyLength', cursor: { start: 17, end: 17 } });
test.verifyEqual(0, hints.length);
test.verifyEqual(2, hints.length);
test.verifyEqual('set', cli.command.name);
test.verifyEqual('historyLength', settingAssignment.arg.text);
test.verifyEqual(historyLengthSetting, settingAssignment.value);
update({ typed: 'set historyLength ', cursor: { start: 18, end: 18 } });
test.verifyEqual(0, hints.length);
test.verifyEqual(3, hints.length);
test.verifyEqual('set', cli.command.name);
test.verifyEqual('historyLength', settingAssignment.arg.text);
test.verifyEqual(historyLengthSetting, settingAssignment.value);
update({ typed: 'set historyLength 6', cursor: { start: 19, end: 19 } });
test.verifyEqual(0, hints.length);
test.verifyEqual(3, hints.length);
test.verifyEqual('set', cli.command.name);
test.verifyEqual('historyLength', settingAssignment.arg.text);
test.verifyEqual(historyLengthSetting, settingAssignment.value);