add traceur test suite
This commit is contained in:
12
test/fixtures/traceur/ArrayComprehension/ArgumentsInComprehension.js
vendored
Normal file
12
test/fixtures/traceur/ArrayComprehension/ArgumentsInComprehension.js
vendored
Normal 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);
|
||||
11
test/fixtures/traceur/ArrayComprehension/Closure.js
vendored
Normal file
11
test/fixtures/traceur/ArrayComprehension/Closure.js
vendored
Normal 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]());
|
||||
4
test/fixtures/traceur/ArrayComprehension/Error_Disabled.js
vendored
Normal file
4
test/fixtures/traceur/ArrayComprehension/Error_Disabled.js
vendored
Normal 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];
|
||||
5
test/fixtures/traceur/ArrayComprehension/Error_NotDefined.js
vendored
Normal file
5
test/fixtures/traceur/ArrayComprehension/Error_NotDefined.js
vendored
Normal 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;
|
||||
32
test/fixtures/traceur/ArrayComprehension/Simple.js
vendored
Normal file
32
test/fixtures/traceur/ArrayComprehension/Simple.js
vendored
Normal 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);
|
||||
14
test/fixtures/traceur/ArrayComprehension/ThisInComprehension.js
vendored
Normal file
14
test/fixtures/traceur/ArrayComprehension/ThisInComprehension.js
vendored
Normal 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);
|
||||
Reference in New Issue
Block a user