Skip to content

Commit

Permalink
Add runtime tests for for-of initializers that are not simple names
Browse files Browse the repository at this point in the history
Also enables typechecking in Es6ForOfConverterTest for some tests cases

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=202064469
  • Loading branch information
lauraharker authored and brad4d committed Jun 26, 2018
1 parent 7b0aa7f commit c19c762
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
6 changes: 0 additions & 6 deletions test/com/google/javascript/jscomp/Es6ForOfConverterTest.java
Expand Up @@ -194,9 +194,6 @@ public void testForOfOnNonIterable() {
}

public void testForOfWithQualifiedNameInitializer() {
// TODO(b/79532975): handle this case in the type checker and remove disableTypeCheck();
disableTypeCheck();
disableTypeInfoValidation();
test(
"var obj = {a: 0}; for (obj.a of [1,2,3]) { console.log(obj.a); }",
lines(
Expand All @@ -212,9 +209,6 @@ public void testForOfWithQualifiedNameInitializer() {
}

public void testForOfWithComplexInitializer() {
// TODO(b/79532975): handle this case in the type checker and remove disableTypeCheck();
disableTypeCheck();
disableTypeInfoValidation();
test(
"function f() { return {}; } for (f()['x' + 1] of [1,2,3]) {}",
lines(
Expand Down
21 changes: 21 additions & 0 deletions test/com/google/javascript/jscomp/runtime_tests/for_of_test.js
Expand Up @@ -106,3 +106,24 @@ function testForOfArrayNested() {
assertEquals(13, result[7]);
assertEquals(14, result[8]);
}

function testForOfWithGetPropInitializer() {
const /** {a: number} */ obj = {a: 3};
for (obj.a of [4]) {}
assertEquals(4, obj.a);
}

function testForOfWithGetElemInitializer() {
const /** !Object<number, number> */ obj = {};

const /** !Array<number> */ arr = [5, 6, 7];
const /** !Array<number> */ newArr = [];
var index = 0;
for (obj[index] of arr) {
newArr.push(obj[index]);
index++;
}

assertArrayEquals(arr, newArr);
assertObjectEquals({0: 5, 1: 6, 2: 7}, obj);
}

0 comments on commit c19c762

Please sign in to comment.