Bug 773254 - GCLI should match options case-insensitively; r=harth

This commit is contained in:
Joe Walker 2012-07-13 17:06:46 +01:00
Родитель 6a0deccf83
Коммит 956020f6a8
2 изменённых файлов: 33 добавлений и 8 удалений

Просмотреть файл

@ -1679,8 +1679,8 @@ exports.shutdown = function() {
* the associated name. However the name maybe available directly from the
* value using a property lookup. Setting 'stringifyProperty' allows
* SelectionType to take this shortcut.
* - cacheable : If lookup is a function, then we normally assume that
* the values fetched can change. Setting 'cacheable' enables internal
* - cacheable: If lookup is a function, then we normally assume that
* the values fetched can change. Setting 'cacheable:true' enables internal
* caching.
*/
function SelectionType(typeSpec) {
@ -1774,6 +1774,7 @@ SelectionType.prototype._findPredictions = function(arg) {
var lookup = this.getLookup();
var i, option;
var maxPredictions = Conversion.maxPredictions;
var match = arg.text.toLowerCase();
// If the arg has a suffix then we're kind of 'done'. Only an exact match
// will do.
@ -1788,10 +1789,18 @@ SelectionType.prototype._findPredictions = function(arg) {
return predictions;
}
// Cache lower case versions of all the option names
for (i = 0; i < lookup.length; i++) {
option = lookup[i];
if (option._gcliLowerName == null) {
option._gcliLowerName = option.name.toLowerCase();
}
}
// Start with prefix matching
for (i = 0; i < lookup.length && predictions.length < maxPredictions; i++) {
option = lookup[i];
if (option.name.indexOf(arg.text) === 0) {
if (option._gcliLowerName.indexOf(match) === 0) {
this._addToPredictions(predictions, option, arg);
}
}
@ -1800,7 +1809,7 @@ SelectionType.prototype._findPredictions = function(arg) {
if (predictions.length < (maxPredictions / 2)) {
for (i = 0; i < lookup.length && predictions.length < maxPredictions; i++) {
option = lookup[i];
if (option.name.indexOf(arg.text) !== -1) {
if (option._gcliLowerName.indexOf(match) !== -1) {
if (predictions.indexOf(option) === -1) {
this._addToPredictions(predictions, option, arg);
}
@ -1815,7 +1824,7 @@ SelectionType.prototype._findPredictions = function(arg) {
return opt.name;
});
speller.train(names);
var corrected = speller.correct(arg.text);
var corrected = speller.correct(match);
if (corrected) {
lookup.forEach(function(opt) {
if (opt.name === corrected) {
@ -1852,9 +1861,8 @@ SelectionType.prototype.parse = function(arg) {
this.noMatch();
}
var value = predictions[0].value;
if (predictions[0].name === arg.text) {
var value = predictions[0].value;
return new Conversion(value, arg, Status.VALID, '', predictions);
}

Просмотреть файл

@ -2960,8 +2960,25 @@ exports.testCompleted = function(options) {
secure: { value: false, status: 'VALID' }
}
});
};
// Expand out to christmas tree command line
exports.testCase = function(options) {
helpers.setInput('tsg AA');
helpers.check({
input: 'tsg AA',
markup: 'VVVVII',
directTabText: '',
arrowTabText: 'aaa',
status: 'ERROR',
emptyParameters: [ ],
args: {
solo: { value: undefined, text: 'AA', status: 'INCOMPLETE' },
txt1: { value: undefined, status: 'VALID' },
bool: { value: undefined, status: 'VALID' },
txt2: { value: undefined, status: 'VALID' },
num: { value: undefined, status: 'VALID' }
}
});
};
exports.testIncomplete = function(options) {