Skip to content

Commit

Permalink
Make CommandTypes a const enum and use allCommandTypes for unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Hanson committed May 22, 2017
1 parent c6e69dd commit f6240cb
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 5 deletions.
77 changes: 73 additions & 4 deletions src/harness/unittests/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,81 @@ namespace ts.server {
});

describe("onMessage", () => {
const allCommandNames: CommandNames[] = [
CommandNames.Brace,
CommandNames.BraceFull,
CommandNames.BraceCompletion,
CommandNames.Change,
CommandNames.Close,
CommandNames.Completions,
CommandNames.CompletionsFull,
CommandNames.CompletionDetails,
CommandNames.CompileOnSaveAffectedFileList,
CommandNames.Configure,
CommandNames.Definition,
CommandNames.DefinitionFull,
CommandNames.Implementation,
CommandNames.ImplementationFull,
CommandNames.Exit,
CommandNames.Format,
CommandNames.Formatonkey,
CommandNames.FormatFull,
CommandNames.FormatonkeyFull,
CommandNames.FormatRangeFull,
CommandNames.Geterr,
CommandNames.GeterrForProject,
CommandNames.SemanticDiagnosticsSync,
CommandNames.SyntacticDiagnosticsSync,
CommandNames.NavBar,
CommandNames.NavBarFull,
CommandNames.Navto,
CommandNames.NavtoFull,
CommandNames.NavTree,
CommandNames.NavTreeFull,
CommandNames.Occurrences,
CommandNames.DocumentHighlights,
CommandNames.DocumentHighlightsFull,
CommandNames.Open,
CommandNames.Quickinfo,
CommandNames.QuickinfoFull,
CommandNames.References,
CommandNames.ReferencesFull,
CommandNames.Reload,
CommandNames.Rename,
CommandNames.RenameInfoFull,
CommandNames.RenameLocationsFull,
CommandNames.Saveto,
CommandNames.SignatureHelp,
CommandNames.SignatureHelpFull,
CommandNames.TypeDefinition,
CommandNames.ProjectInfo,
CommandNames.ReloadProjects,
CommandNames.Unknown,
CommandNames.OpenExternalProject,
CommandNames.CloseExternalProject,
CommandNames.SynchronizeProjectList,
CommandNames.ApplyChangedToOpenFiles,
CommandNames.EncodedSemanticClassificationsFull,
CommandNames.Cleanup,
CommandNames.OutliningSpans,
CommandNames.TodoComments,
CommandNames.Indentation,
CommandNames.DocCommentTemplate,
CommandNames.CompilerOptionsDiagnosticsFull,
CommandNames.NameOrDottedNameSpan,
CommandNames.BreakpointStatement,
CommandNames.CompilerOptionsForInferredProjects,
CommandNames.GetCodeFixes,
CommandNames.GetCodeFixesFull,
CommandNames.GetSupportedCodeFixes,
CommandNames.GetApplicableRefactors,
CommandNames.GetRefactorCodeActions,
CommandNames.GetRefactorCodeActionsFull,
];

it("should not throw when commands are executed with invalid arguments", () => {
let i = 0;
for (const name in CommandNames) {
if (!Object.prototype.hasOwnProperty.call(CommandNames, name)) {
continue;
}
for (const name of allCommandNames) {
const req: protocol.Request = {
command: name,
seq: i,
Expand Down
3 changes: 2 additions & 1 deletion src/server/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
* Declaration module describing the TypeScript Server protocol
*/
namespace ts.server.protocol {
export enum CommandTypes {
// NOTE: If updating this, be sure to also update `allCommandNames` in `harness/unittests/session.ts`.
export const enum CommandTypes {
Brace = "brace",
/* @internal */
BraceFull = "brace-full",
Expand Down

0 comments on commit f6240cb

Please sign in to comment.