TypeScript/tests/cases/unittests/commandLineParsing.ts
Yui 171ab06cf0 [Transforms] Merge master 06/14/2016 (#9169)
* Remove check narrowing only certain types, add test showing issues with this

* string literal case test

* Reconcile fix with CFA work

* Defaultable -> NotNarrowable to align with use

* Missed a defaultable in comments

* Add test for narrowing to unions of string literals

* Rewrite isInStringLiteral to accomodate for unterminated strings

* Refactor signatureHelp to expose helper functions

* Add support for completion in string literals

* Remove unused check

* Use const instead of let

* Fix error

* Formatting changes

* Use shorthand properties

* Add failing test for #8738

* Sort baseline reference identifier by name

* Detects assignment to internal module export clause, fixes #8738

* add SharedArrayBuffer

fix

* Factor out assignment op check

* Add test for composite assignment

* Factor out the behaviour and handles x++ and ++x

* Handles ES3 default as identifier name

* Fix missing else statement

* isNameOfExportedDeclarationInNonES6Module

* Reorder options alphabetically

* Mark diagnostics, and skipDefaultLibCheck as internal

* Allow an import of "foo.js" to be matched by a file "foo.ts"

* Improve loadModuleFromFile code

* Respond to PR comments

* Respond to more PR comments

* Fix test

* Actually merge from master

* Revert to old tryLoad implementation

* Run fixupParentReferences when parsing isolated jsDocComment

* initial revision of unit test support for project system in tsserver

* Allow wildcard ("*") patterns in ambient module declarations

* Add non-widening forms of null and undefined

* Create separate control flows for property declarations with initializers

* Add regression test

* Allow trailing commas in function parameter and argument lists

* Add tests

* Remove unused variable

* Add null check and CR feedback

* Support shorthand ambient module declarations

* Revert "Merge pull request #7235 from weswigham/narrow-all-types"

This reverts commit ef0f6c8fe4, reversing
changes made to 9f087cb62a.

* reuse the fixupParentReferences function

* Improve typing of && operator with --strictNullChecks

* Add test

* Respond to PR comments

* Respond to PR comments

* Add merging tests

* Use a function `stringify` to simplify calls to `JSON.stringify(xyz, undefined, 2)`

* Update tests

* Fix mistake

* Include indent in navigation bar protocol

Previously navbar01 test had indents when run in the browser but not when run from node. Now they run the same.

* Remove unnecessary restrictions in property access narrowing

* Fix fourslash test

* Add regression test

* Consider property declarations to be control flow containers

* Adding regression test

* Remove restriction on --target es5 and --module es6

* change type definition for Object.create

* Fix signature help

* Add "implicit any" warning for shorthand ambient modules

* Remove trailing whitespace

* Support using string values in enums for CompilerOptions in transpile methods

* Remove trailing whitespace in jakefile

* Make `jake runtests-browser` support test regexes with spaces

For example: `jake runtests-browser t="transpile .js files"` now works.

* Add another test

* factor out isJsxOrTsxExtension

* Move to a conformance test

* Revert "Revert "Merge pull request #7235 from weswigham/narrow-all-types""

This reverts commit fc3e040c51.

* Use inclusive flag, as originally done, but include almost everything

* Add additional tests

* Respond to PR comments

* Fix typo

* add tests for tsserver project system

* Fix test

* Allow case comparison to undefined and null in strict null checking mode

* Remove incorrectly added tests

* check if moduleResolution when verifying that program can be reused

* more tests for module resolution change and exclude

* Fix linting issues

* Merge JSDoc of assignments from function expressions

* Allow nested assignments in type guards

* Add tests

* Improve order of parameter's merged jsdoc

* Force LF newlines for LKG builds/non debug builds
Fixes 6630

* Create intersection types in type guards for unrelated types

* Split commentsFunction test into expr/decl

And renumber.

* Remove TODO comments

* Accept new baselines

* Add tests

* Remove comments

* Fix test helper

* Recognize relative path using in outDir property (#9025)

* Recognize relative path using in outDir property

* Add projects tests

* Add project .json files

* Update baselines

* Add comments

* Add test case

The test passes in 1.8 and fails in master.

* Return trace when exception happens

* Remove Long-Done TODO

AFAIK, the harness sources have been concatenated into `run.js` for as long as I've known. This stops executing them twice (and in turn makes debugging tests much easier, since you no longer have to debug into eval'd code).

* Allow primitive type guards with typeof on right

Previously, only type guards of the form `typeof x === 'string'` were
allowed. Now you can write `'string' === typeof x`.

* Primitive type guards are now order independent

* Fix comments in tests

* Add handleing for classes

* Add more tests for target=es5 module=es6

* addExportToArgumentListKind

* Accept baseline

* Add more tests

* Adds progress indicators to the runtests-parallel build task.

* Fixed typo

* Fix comment

* Add test for out-of-range error

* Use proper method of not resolving alias

* Fix module loading error

(commandLineOptions_stringToEnum would be undefined if optionDeclarations wasn't loaded yet)

* Update tests

* Contextually type return statement in async function

* Remove stale files

* Undo change

* Improve perf

* Improve tests

* Fix sourcemaps for debugging tests

* Allow --sourceRoot with --inlineSources option
Fixes #8445

* this in parameter initializers resolves to class

Accept baselines now that the test passes.

* Add tests for more kinds of import/export

* Fix7334 Disallow async in functionExpression and ArrowFunction (#9062)

* Error when using async modifier in function-expression and arrow-function when target es5

* Add tests and baselines

* Resolve function-this in parameter initialisers when explicitly provided

* Allow null/undefined guard with null/undefined on left

Also add a test with baselines.

* Code review comments

* Update more diagnostic messages ES6->2015

Fix #8996 CC @mhegazy.

* Fixes an issue with runtests-parallel when global mocha is not installed.

* Update LKG

* Add tests

* fix baselines

* Salsa: get members of variables whose initialisers are functions

* Test adding members to JS variables whose initialisers are functions

* Recommend runtests-parallel in CONTRIBUTING

* Allow empty lists on command line

* Remove single-comma empty array form

* Remove trailing whitespace

* Implicit type inclusion changes

* Only inlineSourceMap when debugging through jake-browser (#9080)

* Only inlineSourceMap when debugging through jake-browser

* Address PR: fix typo in opt's property

* minor fix: add missing return clause

* Use camel-case instead of snake-case (#9134)

* Baseline fix, CR comments, lint

* CR changes

* Add test for jsdoc in navigation bar

* Fixes runtests-parallel not reporting failure for failed tests.

* Fix decorator metadata emit for rest arg with no type

* Add isDefinition to ReferenceEntry

Clients can now easily tell if the reference is to a definition or a
usage.

* Test isDefinition

* Add option to bail out of `jake runtests` when one test fails

* Absolute-ify paths in both places

* Refactor

* Add unit test

* lint

* Added tests.

* Accepted baselines.

* Emit 'exports.' if the shorthand is a general export.

* Accepted baselines.

* Emit 'Promise' decorator metadata return type for async methods

* Respond to PR comment

* Unescape identifiers used in code completion

* Make isDefinition required.

For the deprecated getOccurrencesAtPosition, isDefinition is always false.

* Add more isDefinition tests and fix computed property bug

* Fix bug: do unescaping in the right place, so that it only affects escaped javascript identifiers

* Use `isLiteralComputedPropertyDeclarationName`
2016-06-14 15:00:40 -07:00

343 lines
16 KiB
TypeScript

/// <reference path="..\..\..\src\harness\harness.ts" />
/// <reference path="..\..\..\src\compiler\commandLineParser.ts" />
namespace ts {
describe("parseCommandLine", () => {
function assertParseResult(commandLine: string[], expectedParsedCommandLine: ts.ParsedCommandLine) {
const parsed = ts.parseCommandLine(commandLine);
const parsedCompilerOptions = JSON.stringify(parsed.options);
const expectedCompilerOptions = JSON.stringify(expectedParsedCommandLine.options);
assert.equal(parsedCompilerOptions, expectedCompilerOptions);
const parsedErrors = parsed.errors;
const expectedErrors = expectedParsedCommandLine.errors;
assert.isTrue(parsedErrors.length === expectedErrors.length, `Expected error: ${JSON.stringify(expectedErrors)}. Actual error: ${JSON.stringify(parsedErrors)}.`);
for (let i = 0; i < parsedErrors.length; i++) {
const parsedError = parsedErrors[i];
const expectedError = expectedErrors[i];
assert.equal(parsedError.code, expectedError.code);
assert.equal(parsedError.category, expectedError.category);
assert.equal(parsedError.messageText, expectedError.messageText);
}
const parsedFileNames = parsed.fileNames;
const expectedFileNames = expectedParsedCommandLine.fileNames;
assert.isTrue(parsedFileNames.length === expectedFileNames.length, `Expected fileNames: [${JSON.stringify(expectedFileNames)}]. Actual fileNames: [${JSON.stringify(parsedFileNames)}].`);
for (let i = 0; i < parsedFileNames.length; i++) {
const parsedFileName = parsedFileNames[i];
const expectedFileName = expectedFileNames[i];
assert.equal(parsedFileName, expectedFileName);
}
}
it("Parse single option of library flag ", () => {
// --lib es6 0.ts
assertParseResult(["--lib", "es6", "0.ts"],
{
errors: [],
fileNames: ["0.ts"],
options: {
lib: ["lib.es2015.d.ts"]
}
});
});
it("Parse multiple options of library flags ", () => {
// --lib es5,es2015.symbol.wellknown 0.ts
assertParseResult(["--lib", "es5,es2015.symbol.wellknown", "0.ts"],
{
errors: [],
fileNames: ["0.ts"],
options: {
lib: ["lib.es5.d.ts", "lib.es2015.symbol.wellknown.d.ts"]
}
});
});
it("Parse invalid option of library flags ", () => {
// --lib es5,invalidOption 0.ts
assertParseResult(["--lib", "es5,invalidOption", "0.ts"],
{
errors: [{
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'",
category: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.category,
code: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.code,
file: undefined,
start: undefined,
length: undefined,
}],
fileNames: ["0.ts"],
options: {
lib: ["lib.es5.d.ts"]
}
});
});
it("Parse empty options of --jsx ", () => {
// 0.ts --jsx
assertParseResult(["0.ts", "--jsx"],
{
errors: [{
messageText: "Compiler option 'jsx' expects an argument.",
category: ts.Diagnostics.Compiler_option_0_expects_an_argument.category,
code: ts.Diagnostics.Compiler_option_0_expects_an_argument.code,
file: undefined,
start: undefined,
length: undefined,
}, {
messageText: "Argument for '--jsx' option must be: 'preserve', 'react'",
category: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.category,
code: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.code,
file: undefined,
start: undefined,
length: undefined,
}],
fileNames: ["0.ts"],
options: {}
});
});
it("Parse empty options of --module ", () => {
// 0.ts --
assertParseResult(["0.ts", "--module"],
{
errors: [{
messageText: "Compiler option 'module' expects an argument.",
category: ts.Diagnostics.Compiler_option_0_expects_an_argument.category,
code: ts.Diagnostics.Compiler_option_0_expects_an_argument.code,
file: undefined,
start: undefined,
length: undefined,
}, {
messageText: "Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015'",
category: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.category,
code: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.code,
file: undefined,
start: undefined,
length: undefined,
}],
fileNames: ["0.ts"],
options: {}
});
});
it("Parse empty options of --newLine ", () => {
// 0.ts --newLine
assertParseResult(["0.ts", "--newLine"],
{
errors: [{
messageText: "Compiler option 'newLine' expects an argument.",
category: ts.Diagnostics.Compiler_option_0_expects_an_argument.category,
code: ts.Diagnostics.Compiler_option_0_expects_an_argument.code,
file: undefined,
start: undefined,
length: undefined,
}, {
messageText: "Argument for '--newLine' option must be: 'crlf', 'lf'",
category: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.category,
code: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.code,
file: undefined,
start: undefined,
length: undefined,
}],
fileNames: ["0.ts"],
options: {}
});
});
it("Parse empty options of --target ", () => {
// 0.ts --target
assertParseResult(["0.ts", "--target"],
{
errors: [{
messageText: "Compiler option 'target' expects an argument.",
category: ts.Diagnostics.Compiler_option_0_expects_an_argument.category,
code: ts.Diagnostics.Compiler_option_0_expects_an_argument.code,
file: undefined,
start: undefined,
length: undefined,
}, {
messageText: "Argument for '--target' option must be: 'es3', 'es5', 'es6', 'es2015'",
category: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.category,
code: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.code,
file: undefined,
start: undefined,
length: undefined,
}],
fileNames: ["0.ts"],
options: {}
});
});
it("Parse empty options of --moduleResolution ", () => {
// 0.ts --moduleResolution
assertParseResult(["0.ts", "--moduleResolution"],
{
errors: [{
messageText: "Compiler option 'moduleResolution' expects an argument.",
category: ts.Diagnostics.Compiler_option_0_expects_an_argument.category,
code: ts.Diagnostics.Compiler_option_0_expects_an_argument.code,
file: undefined,
start: undefined,
length: undefined,
}, {
messageText: "Argument for '--moduleResolution' option must be: 'node', 'classic'",
category: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.category,
code: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.code,
file: undefined,
start: undefined,
length: undefined,
}],
fileNames: ["0.ts"],
options: {}
});
});
it("Parse empty options of --lib ", () => {
// 0.ts --lib
assertParseResult(["0.ts", "--lib"],
{
errors: [{
messageText: "Compiler option 'lib' expects an argument.",
category: ts.Diagnostics.Compiler_option_0_expects_an_argument.category,
code: ts.Diagnostics.Compiler_option_0_expects_an_argument.code,
file: undefined,
start: undefined,
length: undefined,
}],
fileNames: ["0.ts"],
options: {
lib: []
}
});
});
it("Parse empty string of --lib ", () => {
// 0.ts --lib
// This test is an error because the empty string is falsey
assertParseResult(["0.ts", "--lib", ""],
{
errors: [{
messageText: "Compiler option 'lib' expects an argument.",
category: ts.Diagnostics.Compiler_option_0_expects_an_argument.category,
code: ts.Diagnostics.Compiler_option_0_expects_an_argument.code,
file: undefined,
start: undefined,
length: undefined,
}],
fileNames: ["0.ts"],
options: {
lib: []
}
});
});
it("Parse immediately following command line argument of --lib ", () => {
// 0.ts --lib
assertParseResult(["0.ts", "--lib", "--sourcemap"],
{
errors: [],
fileNames: ["0.ts"],
options: {
lib: [],
sourceMap: true
}
});
});
it("Parse --lib option with extra comma ", () => {
// --lib es5, es7 0.ts
assertParseResult(["--lib", "es5,", "es7", "0.ts"],
{
errors: [{
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'",
category: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.category,
code: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.code,
file: undefined,
start: undefined,
length: undefined,
}],
fileNames: ["es7", "0.ts"],
options: {
lib: ["lib.es5.d.ts"]
}
});
});
it("Parse --lib option with trailing white-space ", () => {
// --lib es5, es7 0.ts
assertParseResult(["--lib", "es5, ", "es7", "0.ts"],
{
errors: [{
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'",
category: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.category,
code: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.code,
file: undefined,
start: undefined,
length: undefined,
}],
fileNames: ["es7", "0.ts"],
options: {
lib: ["lib.es5.d.ts"]
}
});
});
it("Parse multiple compiler flags with input files at the end", () => {
// --lib es5,es2015.symbol.wellknown --target es5 0.ts
assertParseResult(["--lib", "es5,es2015.symbol.wellknown", "--target", "es5", "0.ts"],
{
errors: [],
fileNames: ["0.ts"],
options: {
lib: ["lib.es5.d.ts", "lib.es2015.symbol.wellknown.d.ts"],
target: ts.ScriptTarget.ES5,
}
});
});
it("Parse multiple compiler flags with input files in the middle", () => {
// --module commonjs --target es5 0.ts --lib es5,es2015.symbol.wellknown
assertParseResult(["--module", "commonjs", "--target", "es5", "0.ts", "--lib", "es5,es2015.symbol.wellknown"],
{
errors: [],
fileNames: ["0.ts"],
options: {
module: ts.ModuleKind.CommonJS,
target: ts.ScriptTarget.ES5,
lib: ["lib.es5.d.ts", "lib.es2015.symbol.wellknown.d.ts"],
}
});
});
it("Parse multiple library compiler flags ", () => {
// --module commonjs --target es5 --lib es5 0.ts --library es2015.array,es2015.symbol.wellknown
assertParseResult(["--module", "commonjs", "--target", "es5", "--lib", "es5", "0.ts", "--lib", "es2015.core, es2015.symbol.wellknown "],
{
errors: [],
fileNames: ["0.ts"],
options: {
module: ts.ModuleKind.CommonJS,
target: ts.ScriptTarget.ES5,
lib: ["lib.es2015.core.d.ts", "lib.es2015.symbol.wellknown.d.ts"],
}
});
});
});
}