Start working on better tab completion
Code is not used anywhere yet, but the end goal is: * Replace the bash-style algorithm with a less kludgy one * Add the ability to customize tab completion method (will also include default zsh-style completion) * Abstract tab completion so it can be shared for chat and emote names as available options
This commit is contained in:
parent
34ca5e12af
commit
dfdc07cbfa
3 changed files with 156 additions and 0 deletions
73
test/www/tabcomplete.js
Normal file
73
test/www/tabcomplete.js
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
const assert = require('assert');
|
||||
global.CyTube = {};
|
||||
require('../../www/js/tabcomplete');
|
||||
|
||||
const testcases = [
|
||||
{
|
||||
input: 'and his name is j',
|
||||
position: 17,
|
||||
options: ['johncena', 'johnstamos', 'johto'],
|
||||
output: {
|
||||
text: 'and his name is joh',
|
||||
newPosition: 19
|
||||
},
|
||||
description: 'completes the longest unique substring'
|
||||
},
|
||||
{
|
||||
input: 'and his name is johnc',
|
||||
position: 21,
|
||||
options: ['johncena', 'johnstamos', 'johto'],
|
||||
output: {
|
||||
text: 'and his name is johncena ',
|
||||
newPosition: 25
|
||||
},
|
||||
description: 'completes a unique match'
|
||||
},
|
||||
{
|
||||
input: 'and his name is johnc',
|
||||
position: 21,
|
||||
options: ['asdf'],
|
||||
output: {
|
||||
text: 'and his name is johnc',
|
||||
newPosition: 21
|
||||
},
|
||||
description: 'does not complete when there is no match'
|
||||
},
|
||||
{
|
||||
input: 'and his name is johnc',
|
||||
position: 21,
|
||||
options: [],
|
||||
output: {
|
||||
text: 'and his name is johnc',
|
||||
newPosition: 21
|
||||
},
|
||||
description: 'does not complete when there are no options'
|
||||
},
|
||||
{
|
||||
input: ' ',
|
||||
position: 1,
|
||||
options: ['abc', 'def', 'ghi'],
|
||||
output: {
|
||||
text: ' ',
|
||||
newPosition: 1
|
||||
},
|
||||
description: 'does not complete when the input is empty'
|
||||
}
|
||||
];
|
||||
|
||||
describe('CyTube.tabCompletionMethods', () => {
|
||||
describe('#Longest unique prefix', () => {
|
||||
testcases.forEach(test => {
|
||||
it(test.description, () => {
|
||||
assert.deepEqual(test.output,
|
||||
CyTube.tabCompleteMethods['Longest unique prefix'](
|
||||
test.input,
|
||||
test.position,
|
||||
test.options,
|
||||
{}
|
||||
)
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue