Skip to content

Commit

Permalink
Add tests for yield expressions.
Browse files Browse the repository at this point in the history
  • Loading branch information
CyrusNajmabadi committed Nov 12, 2014
1 parent 99981aa commit fad7978
Show file tree
Hide file tree
Showing 44 changed files with 5,485 additions and 422 deletions.
46 changes: 34 additions & 12 deletions tests/Fidelity/incremental/IncrementalParserTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,12 @@ module TypeScript {
//}

public static testStrictMode1() {
// In non-strict mode 'yield' means nothing and can be reused. In strict mode though
// we'll have to reparse the nodes (and generate an error for 'static();'
// In non-strict mode 'package' means nothing and can be reused. In strict mode though
// we'll have to reparse the nodes (and generate an error for 'package();'
//
// Note: in this test we don't actually add 'use strict'. This is so we can compare
// reuse with/without a strict mode change.
var source = "foo1();\r\nfoo1();\r\nfoo1();\r\yield();";
var source = "foo1();\r\nfoo1();\r\nfoo1();\r\package();";

var oldText = SimpleText.fromString(source);
var newTextAndChange = withInsert(oldText, 0, "'strict';\r\n");
Expand All @@ -247,9 +247,9 @@ module TypeScript {
}

public static testStrictMode2() {
// In non-strict mode 'yield' means nothing and can be reused. In strict mode though
// we'll have to reparse the nodes (and generate an error for 'yield();'
var source = "foo1();\r\nfoo1();\r\nfoo1();\r\yield();";
// In non-strict mode 'package' means nothing and can be reused. In strict mode though
// we'll have to reparse the nodes (and generate an error for 'package();'
var source = "foo1();\r\nfoo1();\r\nfoo1();\r\package();";

var oldText = SimpleText.fromString(source);
var newTextAndChange = withInsert(oldText, 0, "'use strict';\r\n");
Expand All @@ -259,12 +259,12 @@ module TypeScript {
}

public static testStrictMode3() {
// In non-strict mode 'yield' means nothing and can be reused. In strict mode though
// we'll have to reparse the nodes (and generate an error for 'static();'
// In non-strict mode 'package' means nothing and can be reused. In strict mode though
// we'll have to reparse the nodes (and generate an error for 'package();'
//
// Note: in this test we don't actually remove 'use strict'. This is so we can compare
// reuse with/without a strict mode change.
var source = "'strict';\r\nfoo1();\r\nfoo1();\r\nfoo1();\r\nyield();";
var source = "'strict';\r\nfoo1();\r\nfoo1();\r\nfoo1();\r\npackage();";

var index = source.indexOf('f');

Expand All @@ -275,9 +275,9 @@ module TypeScript {
}

public static testStrictMode4() {
// In non-strict mode 'yield' means nothing and can be reused. In strict mode though
// we'll have to reparse the nodes (and generate an error for 'static();'
var source = "'use strict';\r\nfoo1();\r\nfoo1();\r\nfoo1();\r\nyield();";
// In non-strict mode 'package' means nothing and can be reused. In strict mode though
// we'll have to reparse the nodes (and generate an error for 'package();'
var source = "'use strict';\r\nfoo1();\r\nfoo1();\r\nfoo1();\r\npackage();";

var index = source.indexOf('f');

Expand Down Expand Up @@ -543,6 +543,28 @@ module TypeScript {
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, -1);
}

public static testYield1() {
// We're changing from a non-generator to a genarator. We can't reuse statement nodes.
var source = "function foo() {\r\nyield(foo1);\r\n}";

var oldText = SimpleText.fromString(source);
var index = source.indexOf("foo");
var newTextAndChange = withInsert(oldText, index, "*");

compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, -1);
}

public static testYield2() {
// We're changing from a generator to a non-genarator. We can't reuse statement nodes.
var source = "function *foo() {\r\nyield(foo1);\r\n}";

var oldText = SimpleText.fromString(source);
var index = source.indexOf("*");
var newTextAndChange = withDelete(oldText, index, "*".length);

compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, -1);
}

public static textComplexEdits1() {
var source =
"if (typeParameterSymbol.isResolved() || typeParameterSymbol.isResolving()) {\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,20 +225,19 @@
]
},
"value": {
"kind": "TemplateAccessExpression",
"kind": "YieldExpression",
"start": 117,
"end": 137,
"width": 20,
"expression": {
"kind": "IdentifierName",
"yieldKeyword": {
"kind": "YieldKeyword",
"fullStart": 116,
"start": 117,
"fullWidth": 6,
"width": 5,
"text": "yield",
"value": "yield",
"valueText": "yield",
"isKeywordConvertedToIdentifier": true,
"hasLeadingTrivia": true,
"leadingTrivia": [
{
Expand All @@ -249,7 +248,7 @@
}
]
},
"templateExpression": {
"expression": {
"kind": "TemplateExpression",
"start": 123,
"end": 137,
Expand Down
Loading

0 comments on commit fad7978

Please sign in to comment.