ls spec unit tests

This commit is contained in:
Daniel Imms
2025-02-04 06:39:02 -08:00
parent 3cfef4555d
commit 6d43829c8d
2 changed files with 107 additions and 0 deletions

View File

@@ -0,0 +1,101 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import 'mocha';
import { testPaths, type ISuiteSpec } from '../../helpers';
import lsSpec from '../../../completions/upstream/ls';
const allOptions = [
'-%',
'-,',
'--color',
'-1',
'-@',
'-A',
'-B',
'-C',
'-F',
'-G',
'-H',
'-L',
'-O',
'-P',
'-R',
'-S',
'-T',
'-U',
'-W',
'-a',
'-b',
'-c',
'-d',
'-e',
'-f',
'-g',
'-h',
'-i',
'-k',
'-l',
'-m',
'-n',
'-o',
'-p',
'-q',
'-r',
'-s',
'-t',
'-u',
'-v',
'-w',
'-x',
];
export function removeEntry<T>(array: T[], element: T): T[] {
const index = array.indexOf(element);
if (index > -1) {
array.splice(index, 1);
}
return array;
}
export const lsTestSuiteSpec: ISuiteSpec = {
name: 'ls',
completionSpecs: lsSpec,
availableCommands: 'ls',
testSpecs: [
// Empty input
{ input: '|', expectedCompletions: ['ls'], expectedResourceRequests: { type: 'both', cwd: testPaths.cwd } },
// Typing the command
{ input: 'l|', expectedCompletions: ['ls'], expectedResourceRequests: { type: 'both', cwd: testPaths.cwd } },
{ input: 'ls|', expectedCompletions: ['ls'], expectedResourceRequests: { type: 'both', cwd: testPaths.cwd } },
// Basic options
// TODO: The spec wants file paths and folders (which seems like it should only be folders),
// but neither are requested
{ input: 'ls |', expectedCompletions: allOptions, expectedResourceRequests: undefined }, // { type: 'folders', cwd: testPaths.cwd }
{ input: 'ls -|', expectedCompletions: allOptions, expectedResourceRequests: undefined }, // { type: 'folders', cwd: testPaths.cwd }
// Filtering options should request all options so client side can filter
{ input: 'ls -a|', expectedCompletions: allOptions, expectedResourceRequests: undefined }, // { type: 'folders', cwd: testPaths.cwd }
// Duplicate option
// TODO: Duplicate options should not be presented
// { input: 'ls -a -|', expectedCompletions: removeEntry(allOptions, '-a'), expectedResourceRequests: undefined }, // { type: 'folders', cwd: testPaths.cwd }
// Relative paths
{ input: 'ls c|', expectedCompletions: allOptions, expectedResourceRequests: undefined }, // { type: 'folders', cwd: testPaths.cwd }
{ input: 'ls child|', expectedCompletions: allOptions, expectedResourceRequests: undefined }, // { type: 'folders', cwd: testPaths.cwd }
{ input: 'ls .|', expectedCompletions: allOptions, expectedResourceRequests: undefined }, // { type: 'folders', cwd: testPaths.cwd }
{ input: 'ls ./|', expectedCompletions: allOptions, expectedResourceRequests: undefined }, // { type: 'folders', cwd: testPaths.cwd }
{ input: 'ls ./child|', expectedCompletions: allOptions, expectedResourceRequests: undefined }, // { type: 'folders', cwd: testPaths.cwd }
{ input: 'ls ..|', expectedCompletions: allOptions, expectedResourceRequests: undefined }, // { type: 'folders', cwd: testPaths.cwd }
// Relative directories (changes cwd due to /)
{ input: 'ls child/|', expectedCompletions: allOptions, expectedResourceRequests: undefined }, // { type: 'folders', cwd: testPaths.cwdChild }
{ input: 'ls ../|', expectedCompletions: allOptions, expectedResourceRequests: undefined }, // { type: 'folders', cwd: testPaths.cwdParent }
{ input: 'ls ../sibling|', expectedCompletions: allOptions, expectedResourceRequests: undefined }, // { type: 'folders', cwd: testPaths.cwdParent }
]
};

View File

@@ -12,6 +12,7 @@ import { cdTestSuiteSpec as cdTestSuite } from './completions/cd.test';
import { codeTestSuite } from './completions/code.test';
import { testPaths, type ISuiteSpec } from './helpers';
import { codeInsidersTestSuite } from './completions/code-insiders.test';
import { lsTestSuiteSpec } from './completions/upstream/ls.test';
const testSpecs2: ISuiteSpec[] = [
{
@@ -25,9 +26,14 @@ const testSpecs2: ISuiteSpec[] = [
{ input: 'fakecommand |', expectedCompletions: [], expectedResourceRequests: { type: 'both', cwd: testPaths.cwd } },
]
},
// completions/
cdTestSuite,
codeTestSuite,
codeInsidersTestSuite,
// completions/upstream/
lsTestSuiteSpec,
];
suite('Terminal Suggest', () => {