-
Notifications
You must be signed in to change notification settings - Fork 29.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add tests for terminal suggest widget, fix some bugs #234445
Open
meganrogge
wants to merge
18
commits into
main
Choose a base branch
from
merogge/suggest-w-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+112
−17
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
1c8802b
add tests for suggest widget
meganrogge 030c180
rm some things
meganrogge 58abb90
add icon
meganrogge 1c94ea0
get tests to work, catch bug and fix it
meganrogge 2844562
follow up
meganrogge a274e01
revert changes to terminal-suggest-tests
meganrogge bfe7c02
get tests in good format
meganrogge 97ec177
get tests to pass
meganrogge 32f1bef
fix issues
meganrogge 2216159
further simplify
meganrogge 8ec79e3
rm space
meganrogge acc93c4
fix dir bug
meganrogge 02b84da
Update scripts/test-integration.sh
meganrogge 8ae0c39
add more tests
meganrogge 076ba1d
fix duplicate bug
meganrogge 32ebfb4
discover and fix another bug
meganrogge 3d712ae
move function inside
meganrogge f785cd8
fix another bug
meganrogge File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
extensions/terminal-suggest/src/terminalSuggestMain.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { deepStrictEqual, strictEqual } from 'assert'; | ||
import 'mocha'; | ||
import { availableSpecs, getCompletionItemsFromSpecs } from './terminalSuggestMain'; | ||
|
||
suite('Terminal Suggest', () => { | ||
|
||
const availableCommands = ['cd', 'code', 'code-insiders']; | ||
const codeOptions = ['-', '--add', '--category', '--diff', '--disable-extension', '--disable-extensions', '--disable-gpu', '--enable-proposed-api', '--extensions-dir', '--goto', '--help', '--inspect-brk-extensions', '--inspect-extensions', '--install-extension', '--list-extensions', '--locale', '--log', '--max-memory', '--merge', '--new-window', '--pre-release', '--prof-startup', '--profile', '--reuse-window', '--show-versions', '--status', '--sync', '--telemetry', '--uninstall-extension', '--user-data-dir', '--verbose', '--version', '--wait', '-a', '-d', '-g', '-h', '-m', '-n', '-r', '-s', '-v', '-w']; | ||
|
||
suite('Cursor at the end of the command line', () => { | ||
createTestCase('|', availableCommands, 'neither', availableSpecs); | ||
createTestCase('c|', availableCommands, 'neither', availableSpecs); | ||
createTestCase('ls && c|', availableCommands, 'neither', availableSpecs); | ||
createTestCase('cd |', ['~', '-'], 'folders', availableSpecs); | ||
createTestCase('code|', ['code-insiders'], 'neither', availableSpecs); | ||
createTestCase('code-insiders|', [], 'neither', availableSpecs); | ||
createTestCase('code |', codeOptions, 'neither', availableSpecs); | ||
createTestCase('code --locale |', ['bg', 'de', 'en', 'es', 'fr', 'hu', 'it', 'ja', 'ko', 'pt-br', 'ru', 'tr', 'zh-CN', 'zh-TW'], 'neither', availableSpecs); | ||
createTestCase('code --diff |', [], 'files', availableSpecs); | ||
createTestCase('code -di|', codeOptions.filter(o => o.startsWith('di')), 'neither', availableSpecs); | ||
createTestCase('code --diff ./file1 |', [], 'files', availableSpecs); | ||
createTestCase('code --merge |', [], 'files', availableSpecs); | ||
createTestCase('code --merge ./file1 ./file2 |', [], 'files', availableSpecs); | ||
createTestCase('code --merge ./file1 ./file2 ./base |', [], 'files', availableSpecs); | ||
createTestCase('code --goto |', [], 'files', availableSpecs); | ||
createTestCase('code --user-data-dir |', [], 'folders', availableSpecs); | ||
createTestCase('code --profile |', [], 'neither', availableSpecs); | ||
createTestCase('code --install-extension |', [], 'neither', availableSpecs); | ||
createTestCase('code --uninstall-extension |', [], 'neither', availableSpecs); | ||
createTestCase('code --log |', ['critical', 'error', 'warn', 'info', 'debug', 'trace', 'off'], 'neither', availableSpecs); | ||
createTestCase('code --sync |', ['on', 'off'], 'neither', availableSpecs); | ||
createTestCase('code --extensions-dir |', [], 'folders', availableSpecs); | ||
createTestCase('code --list-extensions |', codeOptions, 'neither', availableSpecs); | ||
createTestCase('code --show-versions |', codeOptions, 'neither', availableSpecs); | ||
createTestCase('code --category |', ['azure', 'data science', 'debuggers', 'extension packs', 'education', 'formatters', 'keymaps', 'language packs', 'linters', 'machine learning', 'notebooks', 'programming languages', 'scm providers', 'snippets', 'testing', 'themes', 'visualization', 'other'], 'neither', availableSpecs); | ||
createTestCase('code --category a|', ['azure'], 'neither', availableSpecs); | ||
createTestCase('code-insiders --list-extensions |', codeOptions, 'neither', availableSpecs); | ||
createTestCase('code-insiders --show-versions |', codeOptions, 'neither', availableSpecs); | ||
createTestCase('code-insiders --category |', ['azure', 'data science', 'debuggers', 'extension packs', 'education', 'formatters', 'keymaps', 'language packs', 'linters', 'machine learning', 'notebooks', 'programming languages', 'scm providers', 'snippets', 'testing', 'themes', 'visualization', 'other'], 'neither', availableSpecs); | ||
createTestCase('code-insiders --category a|', ['azure'], 'neither', availableSpecs); | ||
createTestCase('code-insiders --category azure |', [], 'neither', availableSpecs); | ||
}); | ||
suite('Cursor not at the end of the line', () => { | ||
createTestCase('code | --locale', codeOptions, 'neither', availableSpecs); | ||
createTestCase('code --locale | && ls', ['bg', 'de', 'en', 'es', 'fr', 'hu', 'it', 'ja', 'ko', 'pt-br', 'ru', 'tr', 'zh-CN', 'zh-TW'], 'neither', availableSpecs); | ||
createTestCase('code-insiders | --locale', codeOptions, 'neither', availableSpecs); | ||
createTestCase('code-insiders --locale | && ls', ['bg', 'de', 'en', 'es', 'fr', 'hu', 'it', 'ja', 'ko', 'pt-br', 'ru', 'tr', 'zh-CN', 'zh-TW'], 'neither', availableSpecs); | ||
}); | ||
|
||
function createTestCase(commandLineWithCursor: string, expectedCompletionLabels: string[], resourcesRequested: 'files' | 'folders' | 'both' | 'neither', availableSpecs: Fig.Spec[]): void { | ||
const commandLine = commandLineWithCursor.split('|')[0]; | ||
const cursorPosition = commandLineWithCursor.indexOf('|'); | ||
const prefix = commandLine.slice(0, cursorPosition).split(' ').pop() || ''; | ||
const filesRequested = resourcesRequested === 'files' || resourcesRequested === 'both'; | ||
const foldersRequested = resourcesRequested === 'folders' || resourcesRequested === 'both'; | ||
test(commandLineWithCursor, function () { | ||
const result = getCompletionItemsFromSpecs(availableSpecs, { commandLine, cursorPosition }, availableCommands, prefix); | ||
deepStrictEqual(result.items.map(i => i.label).sort(), expectedCompletionLabels.sort()); | ||
strictEqual(result.filesRequested, filesRequested); | ||
strictEqual(result.foldersRequested, foldersRequested); | ||
}); | ||
} | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Best to stick expected as the last arg