Add additional tests.

This commit is contained in:
Cyrus Najmabadi 2015-03-17 16:56:19 -07:00
parent 1eca182ceb
commit c69846555c
20 changed files with 248 additions and 24 deletions

View File

@ -492,15 +492,15 @@ module ts {
implements_clauses_can_only_be_used_in_TypeScript: { code: 8005, category: DiagnosticCategory.Error, key: "'implements clauses' can only be used in TypeScript." },
interface_declarations_can_only_be_used_in_TypeScript: { code: 8006, category: DiagnosticCategory.Error, key: "'interface declarations' can only be used in TypeScript." },
module_declarations_can_only_be_used_in_TypeScript: { code: 8007, category: DiagnosticCategory.Error, key: "'module declarations' can only be used in TypeScript." },
type_aliases_can_only_be_used_in_TypeScript: { code: 8007, category: DiagnosticCategory.Error, key: "'type aliases' can only be used in TypeScript." },
_0_can_only_be_used_in_TypeScript: { code: 8008, category: DiagnosticCategory.Error, key: "'{0}' can only be used in TypeScript." },
types_can_only_be_used_in_TypeScript: { code: 8009, category: DiagnosticCategory.Error, key: "'types' can only be used in TypeScript." },
type_arguments_can_only_be_used_in_TypeScript: { code: 8010, category: DiagnosticCategory.Error, key: "'type arguments' can only be used in TypeScript." },
parameter_modifiers_can_only_be_used_in_TypeScript: { code: 8011, category: DiagnosticCategory.Error, key: "'parameter modifiers' can only be used in TypeScript." },
can_only_be_used_in_TypeScript: { code: 8012, category: DiagnosticCategory.Error, key: "'?' can only be used in TypeScript." },
property_declarations_can_only_be_used_in_TypeScript: { code: 8013, category: DiagnosticCategory.Error, key: "'property declarations' can only be used in TypeScript." },
enum_declarations_can_only_be_used_in_TypeScript: { code: 8014, category: DiagnosticCategory.Error, key: "'enum declarations' can only be used in TypeScript." },
type_assertion_expressions_can_only_be_used_in_TypeScript: { code: 8014, category: DiagnosticCategory.Error, key: "'type assertion expressions' can only be used in TypeScript." },
type_aliases_can_only_be_used_in_TypeScript: { code: 8008, category: DiagnosticCategory.Error, key: "'type aliases' can only be used in TypeScript." },
_0_can_only_be_used_in_TypeScript: { code: 8009, category: DiagnosticCategory.Error, key: "'{0}' can only be used in TypeScript." },
types_can_only_be_used_in_TypeScript: { code: 8010, category: DiagnosticCategory.Error, key: "'types' can only be used in TypeScript." },
type_arguments_can_only_be_used_in_TypeScript: { code: 8011, category: DiagnosticCategory.Error, key: "'type arguments' can only be used in TypeScript." },
parameter_modifiers_can_only_be_used_in_TypeScript: { code: 8012, category: DiagnosticCategory.Error, key: "'parameter modifiers' can only be used in TypeScript." },
can_only_be_used_in_TypeScript: { code: 8013, category: DiagnosticCategory.Error, key: "'?' can only be used in TypeScript." },
property_declarations_can_only_be_used_in_TypeScript: { code: 8014, category: DiagnosticCategory.Error, key: "'property declarations' can only be used in TypeScript." },
enum_declarations_can_only_be_used_in_TypeScript: { code: 8015, category: DiagnosticCategory.Error, key: "'enum declarations' can only be used in TypeScript." },
type_assertion_expressions_can_only_be_used_in_TypeScript: { code: 8016, category: DiagnosticCategory.Error, key: "'type assertion expressions' can only be used in TypeScript." },
yield_expressions_are_not_currently_supported: { code: 9000, category: DiagnosticCategory.Error, key: "'yield' expressions are not currently supported." },
Generators_are_not_currently_supported: { code: 9001, category: DiagnosticCategory.Error, key: "Generators are not currently supported." },
The_arguments_object_cannot_be_referenced_in_an_arrow_function_Consider_using_a_standard_function_expression: { code: 9002, category: DiagnosticCategory.Error, key: "The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression." },

View File

@ -1964,39 +1964,39 @@
},
"'type aliases' can only be used in TypeScript.": {
"category": "Error",
"code": 8007
"code": 8008
},
"'{0}' can only be used in TypeScript.": {
"category": "Error",
"code": 8008
"code": 8009
},
"'types' can only be used in TypeScript.": {
"category": "Error",
"code": 8009
"code": 8010
},
"'type arguments' can only be used in TypeScript.": {
"category": "Error",
"code": 8010
"code": 8011
},
"'parameter modifiers' can only be used in TypeScript.": {
"category": "Error",
"code": 8011
"code": 8012
},
"'?' can only be used in TypeScript.": {
"category": "Error",
"code": 8012
"code": 8013
},
"'property declarations' can only be used in TypeScript.": {
"category": "Error",
"code": 8013
"code": 8014
},
"'enum declarations' can only be used in TypeScript.": {
"category": "Error",
"code": 8014
"code": 8015
},
"'type assertion expressions' can only be used in TypeScript.": {
"category": "Error",
"code": 8014
"code": 8016
},
"'yield' expressions are not currently supported.": {

View File

@ -797,9 +797,6 @@ module FourSlash {
var diagnostics = this.languageService.getSemanticDiagnostics(this.activeFile.fileName);
var realized = ts.realizeDiagnostics(diagnostics, "\r\n");
var actual = JSON.stringify(realized, null, " ");
if (actual !== expected) {
ts.sys.writeFile("c:\\temp\\out.txt", actual);
}
assert.equal(actual, expected);
}

View File

@ -2384,7 +2384,8 @@ module ts {
let targetSourceFile = getValidSourceFile(fileName);
// For JavaScript files, we don't want to report the normal typescript semantic errors.
// Instead, we just report errors for using TypeScript
// Instead, we just report errors for using TypeScript-only constructs from within a
// JavaScript file.
if (isJavaScript(fileName)) {
return getJavaScriptSemanticDiagnostics(targetSourceFile);
}
@ -2505,7 +2506,8 @@ module ts {
diagnostics.push(createDiagnosticForNode(node, Diagnostics.enum_declarations_can_only_be_used_in_TypeScript));
return;
case SyntaxKind.TypeAssertionExpression:
diagnostics.push(createDiagnosticForNode(node, Diagnostics.type_assertion_expressions_can_only_be_used_in_TypeScript));
let typeAssertionExpression = <TypeAssertion>node;
diagnostics.push(createDiagnosticForNode(typeAssertionExpression.type, Diagnostics.type_assertion_expressions_can_only_be_used_in_TypeScript));
return;
}

View File

@ -0,0 +1,15 @@
/// <reference path="fourslash.ts" />
// @allowNonTsExtensions: true
// @Filename: a.tsjs
//// function F<T>() { }
verify.getSemanticDiagnostics(`[
{
"message": "'type parameter declarations' can only be used in TypeScript.",
"start": 11,
"length": 1,
"category": "error",
"code": 8004
}
]`);

View File

@ -0,0 +1,15 @@
/// <reference path="fourslash.ts" />
// @allowNonTsExtensions: true
// @Filename: a.tsjs
//// function F(): number { }
verify.getSemanticDiagnostics(`[
{
"message": "'types' can only be used in TypeScript.",
"start": 14,
"length": 6,
"category": "error",
"code": 8010
}
]`);

View File

@ -0,0 +1,15 @@
/// <reference path="fourslash.ts" />
// @allowNonTsExtensions: true
// @Filename: a.tsjs
//// declare var v;
verify.getSemanticDiagnostics(`[
{
"message": "'declare' can only be used in TypeScript.",
"start": 0,
"length": 7,
"category": "error",
"code": 8009
}
]`);

View File

@ -0,0 +1,15 @@
/// <reference path="fourslash.ts" />
// @allowNonTsExtensions: true
// @Filename: a.tsjs
//// var v: () => number;
verify.getSemanticDiagnostics(`[
{
"message": "'types' can only be used in TypeScript.",
"start": 7,
"length": 12,
"category": "error",
"code": 8010
}
]`);

View File

@ -0,0 +1,15 @@
/// <reference path="fourslash.ts" />
// @allowNonTsExtensions: true
// @Filename: a.tsjs
//// Foo<number>();
verify.getSemanticDiagnostics(`[
{
"message": "'type arguments' can only be used in TypeScript.",
"start": 4,
"length": 6,
"category": "error",
"code": 8011
}
]`);

View File

@ -0,0 +1,15 @@
/// <reference path="fourslash.ts" />
// @allowNonTsExtensions: true
// @Filename: a.tsjs
//// function F(public p) { }
verify.getSemanticDiagnostics(`[
{
"message": "'parameter modifiers' can only be used in TypeScript.",
"start": 11,
"length": 6,
"category": "error",
"code": 8012
}
]`);

View File

@ -0,0 +1,15 @@
/// <reference path="fourslash.ts" />
// @allowNonTsExtensions: true
// @Filename: a.tsjs
//// function F(p?) { }
verify.getSemanticDiagnostics(`[
{
"message": "'?' can only be used in TypeScript.",
"start": 12,
"length": 1,
"category": "error",
"code": 8013
}
]`);

View File

@ -0,0 +1,15 @@
/// <reference path="fourslash.ts" />
// @allowNonTsExtensions: true
// @Filename: a.tsjs
//// function F(a: number) { }
verify.getSemanticDiagnostics(`[
{
"message": "'types' can only be used in TypeScript.",
"start": 14,
"length": 6,
"category": "error",
"code": 8010
}
]`);

View File

@ -0,0 +1,15 @@
/// <reference path="fourslash.ts" />
// @allowNonTsExtensions: true
// @Filename: a.tsjs
//// class C { v }
verify.getSemanticDiagnostics(`[
{
"message": "'property declarations' can only be used in TypeScript.",
"start": 10,
"length": 1,
"category": "error",
"code": 8014
}
]`);

View File

@ -0,0 +1,15 @@
/// <reference path="fourslash.ts" />
// @allowNonTsExtensions: true
// @Filename: a.tsjs
//// enum E { }
verify.getSemanticDiagnostics(`[
{
"message": "'enum declarations' can only be used in TypeScript.",
"start": 5,
"length": 1,
"category": "error",
"code": 8015
}
]`);

View File

@ -0,0 +1,15 @@
/// <reference path="fourslash.ts" />
// @allowNonTsExtensions: true
// @Filename: a.tsjs
//// var v = <string>undefined;
verify.getSemanticDiagnostics(`[
{
"message": "'type assertion expressions' can only be used in TypeScript.",
"start": 9,
"length": 6,
"category": "error",
"code": 8016
}
]`);

View File

@ -10,6 +10,6 @@ verify.getSemanticDiagnostics(`[
"start": 0,
"length": 6,
"category": "error",
"code": 8008
"code": 8009
}
]`);

View File

@ -0,0 +1,15 @@
/// <reference path="fourslash.ts" />
// @allowNonTsExtensions: true
// @Filename: a.tsjs
//// interface I { }
verify.getSemanticDiagnostics(`[
{
"message": "'interface declarations' can only be used in TypeScript.",
"start": 10,
"length": 1,
"category": "error",
"code": 8006
}
]`);

View File

@ -0,0 +1,15 @@
/// <reference path="fourslash.ts" />
// @allowNonTsExtensions: true
// @Filename: a.tsjs
//// module M { }
verify.getSemanticDiagnostics(`[
{
"message": "'module declarations' can only be used in TypeScript.",
"start": 7,
"length": 1,
"category": "error",
"code": 8007
}
]`);

View File

@ -0,0 +1,15 @@
/// <reference path="fourslash.ts" />
// @allowNonTsExtensions: true
// @Filename: a.tsjs
//// type a = b;
verify.getSemanticDiagnostics(`[
{
"message": "'type aliases' can only be used in TypeScript.",
"start": 0,
"length": 11,
"category": "error",
"code": 8008
}
]`);

View File

@ -0,0 +1,15 @@
/// <reference path="fourslash.ts" />
// @allowNonTsExtensions: true
// @Filename: a.tsjs
//// public function F() { }
verify.getSemanticDiagnostics(`[
{
"message": "'public' can only be used in TypeScript.",
"start": 0,
"length": 6,
"category": "error",
"code": 8009
}
]`);