add traceur test suite

This commit is contained in:
Sebastian McKenzie
2015-01-04 19:40:09 +11:00
parent 18813f26bb
commit 6a35bdb42b
495 changed files with 9831 additions and 360 deletions

View File

@@ -0,0 +1,12 @@
// Options: --array-comprehension
// https://github.com/google/traceur-compiler/issues/1086
function f() {
var a = [for (x of [1]) arguments[0]];
var b = [for (x of [1]) arguments[0]];
assert.deepEqual(a, [arguments[0]]);
assert.deepEqual(a, [42]);
assert.deepEqual(a, b);
}
f(42);

View File

@@ -0,0 +1,11 @@
// Options: --array-comprehension --block-binding
// Block binding is needed to get the right scoping semantics inside the arrow
// function in the comprehension.
var res = [for (x of [0, 1]) for (y of [2, 3]) () => [x, y]];
assert.equal(4, res.length);
assertArrayEquals([0, 2], res[0]());
assertArrayEquals([0, 3], res[1]());
assertArrayEquals([1, 2], res[2]());
assertArrayEquals([1, 3], res[3]());

View File

@@ -0,0 +1,4 @@
// Options: --array-comprehension=false
// Error: :4:14: Unexpected token for
var array = [for (x of [0, 1, 2, 3, 4]) x];

View File

@@ -0,0 +1,5 @@
// Options: --array-comprehension --free-variable-checker
// Error: :5:1: notDefined is not defined
var array = [for (notDefined of [0]) notDefined];
notDefined;

View File

@@ -0,0 +1,32 @@
// Options: --array-comprehension
function* range() {
for (var i = 0; i < 5; i++) {
yield i;
}
}
var array = [for (x of [0, 1, 2, 3]) x];
assertArrayEquals([0, 1, 2, 3], array);
var array2 = [for (x of [0, 1, 2]) for (y of [0, 1, 2]) x + '' + y];
assertArrayEquals(['00', '01', '02', '10', '11', '12', '20', '21', '22'],
array2);
var array3 = [
for (x of [0, 1, 2, 3, 4])
for (y of range())
if (x === y)
x + '' + y];
assertArrayEquals(['00', '11', '22', '33', '44'], array3);
// Ensure this works as expression statement
[for (testVar of []) testVar];
var array4 = [
for (x of range())
if (x % 2 === 0)
for (y of range())
if (y % 2 === 1)
x + '' + y];
assertArrayEquals(['01', '03', '21', '23', '41', '43'], array4);

View File

@@ -0,0 +1,14 @@
// Options: --array-comprehension
// https://github.com/google/traceur-compiler/issues/1086
var object = {};
function f() {
var a = [for (x of [1]) this];
var b = [for (x of [1]) this];
assert.deepEqual(a, [this]);
assert.deepEqual(a, [object]);
assert.deepEqual(a, b);
}
f.call(object);