blob: c6c787518a02340e73f2050fc0a8286ca9a3b6af [file] [log] [blame]
saambarati1@gmail.coma0376682015-02-10 07:40:53 +00001load("./driver/driver.js");
2
3function testForIn(x) {
saambarati1@gmail.com784581f2015-02-10 19:01:41 +00004 for (var arg1 in x)
5 x;
6
saambarati1@gmail.coma0376682015-02-10 07:40:53 +00007 for (arg2 in x)
8 x;
9
saambarati1@gmail.com784581f2015-02-10 19:01:41 +000010 for ({x: arg3} in x)
11 x;
12
13 for (var {x: arg4} in x)
saambarati1@gmail.coma0376682015-02-10 07:40:53 +000014 x;
15}
16
17function testForOf(x) {
saambarati1@gmail.com784581f2015-02-10 19:01:41 +000018 for (var arg1 of x)
19 x;
20
saambarati1@gmail.coma0376682015-02-10 07:40:53 +000021 for (arg2 of x)
22 x;
23
24 for ({x: arg3} of x)
25 x;
saambarati1@gmail.com784581f2015-02-10 19:01:41 +000026 for (var {x: arg4} of x)
27 x;
saambarati1@gmail.coma0376682015-02-10 07:40:53 +000028}
29
30testForIn([1])
saambarati1@gmail.com784581f2015-02-10 19:01:41 +000031var types = findTypeForExpression(testForIn, "arg1");
32assert(types.instructionTypeSet.primitiveTypeNames.indexOf(T.String) !== -1, "Primitive type names should contain 'String'");
33types = findTypeForExpression(testForIn, "arg2");
saambarati1@gmail.coma0376682015-02-10 07:40:53 +000034assert(types.instructionTypeSet.primitiveTypeNames.indexOf(T.String) !== -1, "Primitive type names should contain 'String'");
35types = findTypeForExpression(testForIn, "arg3");
36assert(types.instructionTypeSet.primitiveTypeNames.indexOf(T.Undefined) !== -1, "Primitive type names should contain 'Undefined'");
saambarati1@gmail.com784581f2015-02-10 19:01:41 +000037types = findTypeForExpression(testForIn, "arg4");
38assert(types.instructionTypeSet.primitiveTypeNames.indexOf(T.Undefined) !== -1, "Primitive type names should contain 'Undefined'");
saambarati1@gmail.coma0376682015-02-10 07:40:53 +000039
40testForOf([1])
saambarati1@gmail.com784581f2015-02-10 19:01:41 +000041types = findTypeForExpression(testForOf, "arg1");
42assert(types.instructionTypeSet.primitiveTypeNames.indexOf(T.Integer) !== -1, "Primitive type names should contain 'Integer'");
saambarati1@gmail.coma0376682015-02-10 07:40:53 +000043types = findTypeForExpression(testForOf, "arg2");
44assert(types.instructionTypeSet.primitiveTypeNames.indexOf(T.Integer) !== -1, "Primitive type names should contain 'Integer'");
45types = findTypeForExpression(testForOf, "arg3");
46assert(types.instructionTypeSet.primitiveTypeNames.indexOf(T.Undefined) !== -1, "Primitive type names should contain 'Undefined'");
saambarati1@gmail.com784581f2015-02-10 19:01:41 +000047types = findTypeForExpression(testForOf, "arg4");
48assert(types.instructionTypeSet.primitiveTypeNames.indexOf(T.Undefined) !== -1, "Primitive type names should contain 'Undefined'");
saambarati1@gmail.coma0376682015-02-10 07:40:53 +000049testForOf([{x:29}])
saambarati1@gmail.com784581f2015-02-10 19:01:41 +000050types = findTypeForExpression(testForOf, "arg1");
saambarati1@gmail.coma0376682015-02-10 07:40:53 +000051assert(types.instructionTypeSet.structures[0].fields.indexOf("x") !== -1, "variable 'arg1' should have field 'x'");
saambarati1@gmail.com784581f2015-02-10 19:01:41 +000052types = findTypeForExpression(testForOf, "arg2");
53assert(types.instructionTypeSet.structures[0].fields.indexOf("x") !== -1, "variable 'arg2' should have field 'x'");
saambarati1@gmail.coma0376682015-02-10 07:40:53 +000054types = findTypeForExpression(testForOf, "arg3");
55assert(types.instructionTypeSet.primitiveTypeNames.indexOf(T.Integer) !== -1, "Primitive type names should contain 'Integer'");
saambarati1@gmail.com784581f2015-02-10 19:01:41 +000056types = findTypeForExpression(testForOf, "arg4");
57assert(types.instructionTypeSet.primitiveTypeNames.indexOf(T.Integer) !== -1, "Primitive type names should contain 'Integer'");