remove regenerator tests and git submodule regenerator
This commit is contained in:
@@ -1,7 +0,0 @@
|
||||
Copyright (c) 2014, Facebook, Inc.
|
||||
All rights reserved.
|
||||
|
||||
This source code is licensed under the BSD-style license found in the
|
||||
https://raw.github.com/facebook/regenerator/master/LICENSE file. An
|
||||
additional grant of patent rights can be found in the PATENTS file in
|
||||
the same directory.
|
||||
@@ -1,24 +0,0 @@
|
||||
function *gen() {
|
||||
var a$0 = 0, a$1 = 1;
|
||||
|
||||
let a = 3;
|
||||
|
||||
{
|
||||
let a = 1;
|
||||
yield a + a$0;
|
||||
}
|
||||
|
||||
{
|
||||
let a = 2;
|
||||
yield a - 1 + a$1;
|
||||
}
|
||||
|
||||
yield a;
|
||||
}
|
||||
|
||||
var g = gen();
|
||||
|
||||
assert.deepEqual(g.next(), { value: 1, done: false });
|
||||
assert.deepEqual(g.next(), { value: 2, done: false });
|
||||
assert.deepEqual(g.next(), { value: 3, done: false });
|
||||
assert.deepEqual(g.next(), { value: void 0, done: true });
|
||||
@@ -1,22 +0,0 @@
|
||||
function *gen() {
|
||||
let arr = [];
|
||||
|
||||
for (let x = 0; x < 3; x++) {
|
||||
let y = x;
|
||||
arr.push(function() { return y; });
|
||||
}
|
||||
|
||||
{
|
||||
let x;
|
||||
while( x = arr.pop() ) {
|
||||
yield x;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var g = gen();
|
||||
|
||||
assert.equal(g.next().value(), 2);
|
||||
assert.equal(g.next().value(), 1);
|
||||
assert.equal(g.next().value(), 0);
|
||||
assert.deepEqual(g.next(), { value: void 0, done: true });
|
||||
@@ -1,15 +0,0 @@
|
||||
function *gen() {
|
||||
try {
|
||||
genHelpers.raise("e1");
|
||||
} catch (e) {
|
||||
yield e;
|
||||
try {
|
||||
genHelpers.raise("e2");
|
||||
} catch (e) {
|
||||
yield e;
|
||||
}
|
||||
yield e;
|
||||
}
|
||||
}
|
||||
|
||||
genHelpers.check(gen(), ["e1", "e2", "e1"]);
|
||||
@@ -1,22 +0,0 @@
|
||||
function *gen(x) {
|
||||
var y = x + 1;
|
||||
try {
|
||||
throw x + 2;
|
||||
} catch (x) {
|
||||
yield x;
|
||||
x += 1;
|
||||
yield x;
|
||||
}
|
||||
yield x;
|
||||
try {
|
||||
throw x + 3;
|
||||
} catch (y) {
|
||||
yield y;
|
||||
y *= 2;
|
||||
yield y;
|
||||
}
|
||||
yield y;
|
||||
}
|
||||
|
||||
genHelpers.check(gen(1), [3, 4, 1, 4, 8, 2]);
|
||||
genHelpers.check(gen(2), [4, 5, 2, 5, 10, 3]);
|
||||
@@ -1,32 +0,0 @@
|
||||
function *gen(x) {
|
||||
try {
|
||||
throw x;
|
||||
} catch (x) {
|
||||
yield x;
|
||||
|
||||
yield (function(x) {
|
||||
return x += 1;
|
||||
}(x + 1));
|
||||
|
||||
yield (function() {
|
||||
var x = arguments[0];
|
||||
return x * 2;
|
||||
}(x + 2));
|
||||
|
||||
yield (function() {
|
||||
function notCalled(x) {
|
||||
throw x;
|
||||
}
|
||||
|
||||
x >>= 1;
|
||||
return x;
|
||||
}());
|
||||
|
||||
yield x -= 1;
|
||||
}
|
||||
|
||||
yield x;
|
||||
}
|
||||
|
||||
genHelpers.check(gen(10), [10, 12, 24, 5, 4, 10]);
|
||||
genHelpers.check(gen(11), [11, 13, 26, 5, 4, 11]);
|
||||
@@ -1,42 +0,0 @@
|
||||
function *gen(n) {
|
||||
var count = 0;
|
||||
|
||||
yield n;
|
||||
|
||||
while (n !== 1) {
|
||||
count += 1;
|
||||
|
||||
if (n % 2) {
|
||||
yield n = n * 3 + 1;
|
||||
} else {
|
||||
yield n >>= 1;
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
function collatz(n) {
|
||||
var result = [n];
|
||||
|
||||
while (n !== 1) {
|
||||
if (n % 2) {
|
||||
n *= 3;
|
||||
n += 1;
|
||||
} else {
|
||||
n >>= 1;
|
||||
}
|
||||
|
||||
result.push(n);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
var seven = collatz(7);
|
||||
var fiftyTwo = seven.slice(seven.indexOf(52));
|
||||
var eightyTwo = collatz(82);
|
||||
|
||||
genHelpers.check(gen(7), seven, 16);
|
||||
genHelpers.check(gen(52), fiftyTwo, 11);
|
||||
genHelpers.check(gen(82), eightyTwo, 110);
|
||||
@@ -1,11 +0,0 @@
|
||||
function *gen() {
|
||||
return "ALL DONE";
|
||||
}
|
||||
|
||||
var g = gen();
|
||||
|
||||
assert.deepEqual(g.next(), {
|
||||
value: "ALL DONE", done: true
|
||||
});
|
||||
|
||||
genHelpers.assertAlreadyFinished(g);
|
||||
@@ -1,27 +0,0 @@
|
||||
var error = new Error("thrown");
|
||||
|
||||
function *outer(n) {
|
||||
try {
|
||||
yield 0;
|
||||
yield* inner(n);
|
||||
yield 1;
|
||||
} catch (err) {
|
||||
yield err.message;
|
||||
}
|
||||
yield 4;
|
||||
}
|
||||
|
||||
function *inner(n) {
|
||||
while (n --> 0) {
|
||||
try {
|
||||
if (n === 3) {
|
||||
genHelpers.raise(error);
|
||||
}
|
||||
} finally {
|
||||
yield n;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
genHelpers.check(outer(3), [0, 2, 1, 0, 1, 4]);
|
||||
genHelpers.check(outer(5), [0, 4, 3, "thrown", 4]);
|
||||
@@ -1,10 +0,0 @@
|
||||
function *gen(condition) {
|
||||
if (condition) {
|
||||
yield 0;
|
||||
yield* gen(false);
|
||||
yield 1;
|
||||
}
|
||||
}
|
||||
|
||||
genHelpers.check(gen(true), [0, 1]);
|
||||
genHelpers.check(gen(false), []);
|
||||
@@ -1,12 +0,0 @@
|
||||
function *gen(condition) {
|
||||
yield 0;
|
||||
if (condition) {
|
||||
yield 1;
|
||||
yield* gen(false);
|
||||
yield 2;
|
||||
}
|
||||
yield 3;
|
||||
}
|
||||
|
||||
genHelpers.check(gen(true), [0, 1, 0, 3, 2, 3]);
|
||||
genHelpers.check(gen(false), [0, 3]);
|
||||
@@ -1,37 +0,0 @@
|
||||
var count = 0;
|
||||
|
||||
function *gen() {
|
||||
yield* inner();
|
||||
try {
|
||||
yield* inner();
|
||||
} catch (err) {
|
||||
// pass
|
||||
}
|
||||
return yield* inner();
|
||||
}
|
||||
|
||||
function *inner() {
|
||||
return yield count++;
|
||||
}
|
||||
|
||||
var g = gen();
|
||||
|
||||
assert.deepEqual(g.next(), {
|
||||
value: 0,
|
||||
done: false
|
||||
});
|
||||
|
||||
assert.deepEqual(g.next(), {
|
||||
value: 1,
|
||||
done: false
|
||||
});
|
||||
|
||||
assert.deepEqual(g.throw(new Error("lol")), {
|
||||
value: 2,
|
||||
done: false,
|
||||
});
|
||||
|
||||
assert.deepEqual(g.next("sent"), {
|
||||
value: "sent",
|
||||
done: true
|
||||
});
|
||||
@@ -1,15 +0,0 @@
|
||||
function *outer(n) {
|
||||
yield* inner(n << 1);
|
||||
yield "zxcv";
|
||||
}
|
||||
|
||||
function *inner(n) {
|
||||
return yield yield yield n;
|
||||
}
|
||||
|
||||
var g = outer(3);
|
||||
assert.deepEqual(g.next(), { value: 6, done: false });
|
||||
assert.deepEqual(g.next(1), { value: 1, done: false });
|
||||
assert.deepEqual(g.next(2), { value: 2, done: false });
|
||||
assert.deepEqual(g.next(4), { value: "zxcv", done: false });
|
||||
assert.deepEqual(g.next(5), { value: void 0, done: true });
|
||||
@@ -1,18 +0,0 @@
|
||||
function *outer(n) {
|
||||
yield n;
|
||||
yield* middle(n - 1, inner(n + 10));
|
||||
yield n + 1;
|
||||
}
|
||||
|
||||
function *middle(n, plusTen) {
|
||||
yield n;
|
||||
yield* inner(n - 1);
|
||||
yield n + 1;
|
||||
yield* plusTen;
|
||||
}
|
||||
|
||||
function *inner(n) {
|
||||
yield n;
|
||||
}
|
||||
|
||||
genHelpers.check(outer(5), [5, 4, 3, 5, 15, 6]);
|
||||
@@ -1,11 +0,0 @@
|
||||
function *gen() {
|
||||
yield 0;
|
||||
yield* [
|
||||
yield "one",
|
||||
yield "two",
|
||||
yield "three"
|
||||
];
|
||||
yield 5;
|
||||
}
|
||||
|
||||
genHelpers.check(gen(), [0, "one", "two", "three", 2, 3, 4, 5]);
|
||||
@@ -1,20 +0,0 @@
|
||||
function *gen(x, fname) {
|
||||
try {
|
||||
return fns[fname](x);
|
||||
} catch (thrown) {
|
||||
yield thrown;
|
||||
}
|
||||
}
|
||||
|
||||
var fns = {
|
||||
f: function(x) {
|
||||
throw x;
|
||||
},
|
||||
|
||||
g: function(x) {
|
||||
return x;
|
||||
}
|
||||
};
|
||||
|
||||
genHelpers.check(gen("asdf", "f"), ["asdf"]);
|
||||
genHelpers.check(gen("asdf", "g"), [], "asdf");
|
||||
@@ -1,16 +0,0 @@
|
||||
function *gen(x) {
|
||||
while (x) {
|
||||
// empty while loop
|
||||
}
|
||||
|
||||
do {
|
||||
// empty do-while loop
|
||||
} while (x);
|
||||
|
||||
return gen.toString();
|
||||
}
|
||||
|
||||
var info = gen(false).next();
|
||||
assert.strictEqual(info.done, true);
|
||||
assert.ok(/do \{/.test(info.value));
|
||||
assert.ok(/while \(/.test(info.value));
|
||||
@@ -1,19 +0,0 @@
|
||||
function *gen(obj) {
|
||||
var count = 0;
|
||||
for (var key in (yield "why not", obj)) {
|
||||
if (obj.hasOwnProperty(key)) {
|
||||
if (key === "skip") {
|
||||
break;
|
||||
}
|
||||
count += 1;
|
||||
yield [key, obj[key]];
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
genHelpers.check(
|
||||
gen({ a: 1, b: 2, skip: 3, c: 4 }),
|
||||
["why not", ["a", 1], ["b", 2]],
|
||||
2
|
||||
);
|
||||
@@ -1,13 +0,0 @@
|
||||
function *gen() {
|
||||
var count = 0;
|
||||
var obj = {foo: 1, bar: 2};
|
||||
for (var key in obj) {
|
||||
assert(obj.hasOwnProperty(key), key + " must be own property");
|
||||
yield [key, obj[key]];
|
||||
delete obj.bar;
|
||||
count += 1;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
genHelpers.check(gen(), [["foo", 1]], 1);
|
||||
@@ -1,26 +0,0 @@
|
||||
function a(sent) {
|
||||
assert.strictEqual(sent, 1);
|
||||
a.called = true;
|
||||
}
|
||||
|
||||
function b(sent) {
|
||||
assert.strictEqual(sent, 2);
|
||||
b.called = true;
|
||||
return { callee: b };
|
||||
}
|
||||
|
||||
function *gen() {
|
||||
assert.ok(!a.called);
|
||||
assert.ok(!b.called);
|
||||
for (var key in a(yield 0), b(yield 1)) {
|
||||
assert.ok(a.called);
|
||||
assert.ok(b.called);
|
||||
assert.strictEqual(yield key, 3);
|
||||
}
|
||||
|
||||
for (var key in a(1), { foo: "foo", bar: "bar" }) {
|
||||
yield key;
|
||||
}
|
||||
}
|
||||
|
||||
genHelpers.check(gen(), [0, 1, "callee", "foo", "bar"]);
|
||||
@@ -1,12 +0,0 @@
|
||||
function *gen() {
|
||||
var count = 0;
|
||||
var obj = {foo: 1, bar: 2};
|
||||
for (var key in obj) {
|
||||
assert(obj.hasOwnProperty(key), key + " must be own property");
|
||||
yield [key, obj[key]];
|
||||
count += 1;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
genHelpers.check(gen(), [["foo", 1], ["bar", 2]], 2);
|
||||
@@ -1,16 +0,0 @@
|
||||
function *gen() {
|
||||
var count = 0;
|
||||
function Foo() {
|
||||
this.baz = 1
|
||||
}
|
||||
Foo.prototype.bar = 2;
|
||||
|
||||
var foo = new Foo();
|
||||
for (var key in foo) {
|
||||
yield [key, foo[key]];
|
||||
count += 1;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
genHelpers.check(gen(), [["baz", 1], ["bar", 2]], 2);
|
||||
@@ -1,7 +0,0 @@
|
||||
// https://github.com/facebook/regenerator/issues/103
|
||||
function *range() {
|
||||
for (var i = 0; false; ) {
|
||||
}
|
||||
}
|
||||
|
||||
genHelpers.check(range(), []);
|
||||
@@ -1,5 +0,0 @@
|
||||
var sum = 0;
|
||||
for (var x of [1, 2].concat(3)) {
|
||||
sum += x;
|
||||
}
|
||||
assert.strictEqual(sum, 6);
|
||||
@@ -1,10 +0,0 @@
|
||||
function *range(n) {
|
||||
for (var i = 0; i < n; ++i) {
|
||||
yield i;
|
||||
}
|
||||
}
|
||||
|
||||
var value, values = [];
|
||||
for (value of range(3))
|
||||
values.push(value);
|
||||
assert.deepEqual(values, [0, 1, 2]);
|
||||
@@ -1,45 +0,0 @@
|
||||
function *yieldPermutations(list) {
|
||||
if (list.length < 2) {
|
||||
yield list;
|
||||
return 1;
|
||||
}
|
||||
|
||||
var count = 0;
|
||||
var first = list.slice(0, 1);
|
||||
var genRest = yieldPermutations(list.slice(1));
|
||||
|
||||
for (var perm of genRest) {
|
||||
for (var i = 0; i < list.length; ++i) {
|
||||
var prefix = perm.slice(0, i);
|
||||
var suffix = perm.slice(i);
|
||||
yield prefix.concat(first, suffix);
|
||||
}
|
||||
|
||||
count += i;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
var count = 0;
|
||||
for (var perm of yieldPermutations([])) {
|
||||
assert.deepEqual(perm, []);
|
||||
++count;
|
||||
}
|
||||
assert.strictEqual(count, 1);
|
||||
|
||||
genHelpers.check(yieldPermutations([1]), [[1]], 1);
|
||||
|
||||
genHelpers.check(yieldPermutations([2, 1]), [
|
||||
[2, 1],
|
||||
[1, 2]
|
||||
], 2);
|
||||
|
||||
genHelpers.check(yieldPermutations([1,3,2]), [
|
||||
[1, 3, 2],
|
||||
[3, 1, 2],
|
||||
[3, 2, 1],
|
||||
[1, 2, 3],
|
||||
[2, 1, 3],
|
||||
[2, 3, 1]
|
||||
], 6);
|
||||
@@ -1,24 +0,0 @@
|
||||
function *gen(n) {
|
||||
yield increment(n);
|
||||
|
||||
function increment(x) {
|
||||
return x + 1;
|
||||
}
|
||||
|
||||
if (n % 2) {
|
||||
yield halve(decrement(n));
|
||||
|
||||
function halve(x) {
|
||||
return x >> 1;
|
||||
}
|
||||
|
||||
function decrement(x) {
|
||||
return x - 1;
|
||||
}
|
||||
}
|
||||
|
||||
yield increment(increment(n));
|
||||
}
|
||||
|
||||
genHelpers.check(gen(3), [4, 1, 5]);
|
||||
genHelpers.check(gen(4), [5, 6]);
|
||||
@@ -1,15 +0,0 @@
|
||||
function *outer(n) {
|
||||
yield 0;
|
||||
assert.ok(regeneratorRuntime.isGeneratorFunction(inner));
|
||||
return yield* inner(n);
|
||||
|
||||
// Note that this function declaration comes after everything else
|
||||
// in the outer function, but needs to be fully available above.
|
||||
function *inner(n) {
|
||||
yield n - 1;
|
||||
yield n;
|
||||
return yield n + 1;
|
||||
}
|
||||
}
|
||||
|
||||
genHelpers.check(outer(2), [0, 1, 2, 3], 4);
|
||||
@@ -1,6 +0,0 @@
|
||||
genHelpers.check(function *(x, y) {
|
||||
yield x;
|
||||
yield y;
|
||||
yield x + y;
|
||||
return x * y;
|
||||
}(3, 7), [3, 7, 10], 21);
|
||||
@@ -1,60 +0,0 @@
|
||||
|
||||
var GeneratorFunctionPrototype = f.__proto__;
|
||||
var GeneratorFunction = GeneratorFunctionPrototype.constructor;
|
||||
|
||||
assert.strictEqual(GeneratorFunction.name, 'GeneratorFunction');
|
||||
assert.strictEqual(GeneratorFunction.prototype,
|
||||
GeneratorFunctionPrototype);
|
||||
assert.strictEqual(GeneratorFunctionPrototype.prototype.constructor,
|
||||
GeneratorFunctionPrototype);
|
||||
assert.strictEqual(GeneratorFunctionPrototype.prototype,
|
||||
f.prototype.__proto__);
|
||||
assert.strictEqual(GeneratorFunctionPrototype.__proto__,
|
||||
Function.prototype);
|
||||
assert.strictEqual(GeneratorFunctionPrototype.name,
|
||||
"GeneratorFunctionPrototype");
|
||||
|
||||
assert.strictEqual(typeof f2, "function");
|
||||
assert.strictEqual(f2.constructor, GeneratorFunction);
|
||||
assert.ok(f2 instanceof GeneratorFunction);
|
||||
assert.strictEqual(f2.name, "f2");
|
||||
|
||||
var g = f();
|
||||
assert.ok(g instanceof f);
|
||||
assert.strictEqual(g.__proto__, f.prototype);
|
||||
|
||||
assert.deepEqual([], Object.getOwnPropertyNames(f.prototype));
|
||||
// assert.deepEqual([], Object.getOwnPropertyNames(g));
|
||||
|
||||
f.prototype.x = 42;
|
||||
|
||||
var g2 = f();
|
||||
assert.strictEqual(g2.x, 42);
|
||||
|
||||
var g3 = new f();
|
||||
assert.strictEqual(g3.x, 42);
|
||||
|
||||
function* f2() {
|
||||
yield 1;
|
||||
}
|
||||
|
||||
assert.strictEqual(f.__proto__, f2.__proto__);
|
||||
assert.strictEqual(f.hasOwnProperty('constructor'), false);
|
||||
assert.strictEqual(f.__proto__.constructor.name, 'GeneratorFunction');
|
||||
|
||||
// Intentionally at the end to test hoisting.
|
||||
function* f() {
|
||||
yield this;
|
||||
}
|
||||
|
||||
function* f() {
|
||||
yield 1;
|
||||
}
|
||||
|
||||
var f2 = f;
|
||||
f = 42;
|
||||
var g = f2();
|
||||
|
||||
assert.deepEqual(g.next(), { value: 1, done: false });
|
||||
assert.deepEqual(g.next(), { value: void 0, done: true });
|
||||
assert.ok(g instanceof f2);
|
||||
@@ -1,18 +0,0 @@
|
||||
function *gen(x) {
|
||||
try {
|
||||
(yield x).next(x);
|
||||
} catch (err) {
|
||||
yield err;
|
||||
}
|
||||
return x + 1;
|
||||
}
|
||||
|
||||
var g = gen(3);
|
||||
assert.deepEqual(g.next(), { value: 3, done: false });
|
||||
var complaint = g.next(g); // Sending the generator to itself.
|
||||
assert.ok(complaint.value instanceof Error);
|
||||
assert.strictEqual(
|
||||
complaint.value.message,
|
||||
"Generator is already running"
|
||||
);
|
||||
assert.deepEqual(g.next(), { value: 4, done: true });
|
||||
@@ -1,22 +0,0 @@
|
||||
var executedFinally = false;
|
||||
|
||||
function *gen() {
|
||||
try {
|
||||
yield 0;
|
||||
} catch (err) {
|
||||
assert.ok(false, "should not have executed the catch handler");
|
||||
} finally {
|
||||
executedFinally = true;
|
||||
}
|
||||
}
|
||||
|
||||
var g = gen();
|
||||
assert.deepEqual(g.next(), { value: 0, done: false });
|
||||
|
||||
assert.deepEqual(g.return("argument"), {
|
||||
value: "argument",
|
||||
done: true
|
||||
});
|
||||
|
||||
assert.strictEqual(executedFinally, true);
|
||||
genHelpers.assertAlreadyFinished(g);
|
||||
@@ -1,12 +0,0 @@
|
||||
function *gen() {
|
||||
yield 0;
|
||||
}
|
||||
|
||||
var g = gen();
|
||||
|
||||
assert.deepEqual(g.return("argument"), {
|
||||
value: "argument",
|
||||
done: true
|
||||
});
|
||||
|
||||
genHelpers.assertAlreadyFinished(g);
|
||||
@@ -1,16 +0,0 @@
|
||||
function *gen(x) {
|
||||
yield 2;
|
||||
throw 1;
|
||||
}
|
||||
|
||||
var u = gen();
|
||||
|
||||
u.next();
|
||||
|
||||
try {
|
||||
u.throw(2);
|
||||
} catch (err) {
|
||||
assert.strictEqual(err, 2);
|
||||
}
|
||||
|
||||
genHelpers.assertAlreadyFinished(u);
|
||||
@@ -1,16 +0,0 @@
|
||||
var began = false;
|
||||
|
||||
function *gen() {
|
||||
began = true;
|
||||
yield 1;
|
||||
}
|
||||
|
||||
var g = gen();
|
||||
var exception = new Error("unhandled exception");
|
||||
try {
|
||||
g.throw(exception);
|
||||
assert.ok(false, "should have thrown an exception");
|
||||
} catch (err) {
|
||||
assert.strictEqual(err, exception);
|
||||
assert.strictEqual(began, false);
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
function *outer() {
|
||||
try {
|
||||
yield* inner();
|
||||
} catch (err) {
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
function *inner() {
|
||||
try {
|
||||
yield void 0;
|
||||
} catch (e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var g = outer();
|
||||
g.next();
|
||||
assert.equal(g.throw(new Error('foo')).value, 1);
|
||||
@@ -1,16 +0,0 @@
|
||||
function *outer() {
|
||||
try {
|
||||
yield* inner();
|
||||
} catch (err) {
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
function *inner() {
|
||||
yield void 0;
|
||||
}
|
||||
|
||||
var g = outer();
|
||||
g.next();
|
||||
assert.equal(g.throw(new Error('foo')).value, -1);
|
||||
@@ -1,14 +0,0 @@
|
||||
function *gen() {
|
||||
yield 1;
|
||||
}
|
||||
|
||||
var g = gen();
|
||||
assert.deepEqual(g.next(), { value: 1, done: false });
|
||||
|
||||
var exception = new Error("unhandled exception");
|
||||
try {
|
||||
g.throw(exception);
|
||||
assert.ok(false, "should have thrown an exception");
|
||||
} catch (err) {
|
||||
assert.strictEqual(err, exception);
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
function *gen(start, step) {
|
||||
step = step || 1;
|
||||
while (true) {
|
||||
yield start;
|
||||
start += step;
|
||||
}
|
||||
}
|
||||
|
||||
function *limit(g, stop) {
|
||||
while (true) {
|
||||
var info = g.next();
|
||||
if (info.done) {
|
||||
return;
|
||||
} else if (info.value < stop) {
|
||||
yield info.value;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// should generate a lot of plausible values
|
||||
var g = gen(10, 2);
|
||||
|
||||
assert.deepEqual(g.next(), { value: 10, done: false });
|
||||
assert.deepEqual(g.next(), { value: 12, done: false });
|
||||
assert.deepEqual(g.next(), { value: 14, done: false });
|
||||
assert.deepEqual(g.next(), { value: 16, done: false });
|
||||
|
||||
var sum = 10 + 12 + 14 + 16;
|
||||
|
||||
for (var n = 0; n < 1000; ++n) {
|
||||
var info = g.next();
|
||||
sum += info.value;
|
||||
assert.strictEqual(info.done, false);
|
||||
}
|
||||
|
||||
assert.strictEqual(sum, 1017052);
|
||||
|
||||
// should allow limiting
|
||||
genHelpers.check(limit(gen(10, 3), 20), [10, 13, 16, 19]);
|
||||
@@ -1,19 +0,0 @@
|
||||
// Do the assertions up here to make sure the generator function is
|
||||
// marked at the beginning of the block the function is declared in.
|
||||
assert.strictEqual(
|
||||
regeneratorRuntime.isGeneratorFunction(genFun),
|
||||
true
|
||||
);
|
||||
|
||||
assert.strictEqual(
|
||||
regeneratorRuntime.isGeneratorFunction(normalFun),
|
||||
false
|
||||
);
|
||||
|
||||
function normalFun() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
function *genFun() {
|
||||
yield 0;
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
assert.strictEqual(
|
||||
regeneratorRuntime.isGeneratorFunction(function *genFun() {
|
||||
yield 0;
|
||||
}),
|
||||
true
|
||||
);
|
||||
|
||||
assert.strictEqual(
|
||||
regeneratorRuntime.isGeneratorFunction(function normalFun() {
|
||||
return 0;
|
||||
}),
|
||||
false
|
||||
);
|
||||
@@ -1,82 +0,0 @@
|
||||
|
||||
var e1 = "first";
|
||||
var e2 = "second";
|
||||
var e3 = "third";
|
||||
var e4 = "fourth";
|
||||
|
||||
function *gen(n, which) {
|
||||
try {
|
||||
yield 0;
|
||||
genHelpers.raise(e1);
|
||||
|
||||
} finally {
|
||||
yield 1;
|
||||
|
||||
loop:
|
||||
for (var i = 0; i < n; ++i) {
|
||||
yield i;
|
||||
|
||||
try {
|
||||
genHelpers.raise(e2);
|
||||
} finally {
|
||||
yield 2;
|
||||
|
||||
try {
|
||||
genHelpers.raise(e3);
|
||||
} finally {
|
||||
yield 3;
|
||||
|
||||
try {
|
||||
genHelpers.raise(e4);
|
||||
} finally {
|
||||
yield 4;
|
||||
|
||||
if (which === "break") {
|
||||
yield "breaking";
|
||||
break loop;
|
||||
}
|
||||
|
||||
if (which === "continue") {
|
||||
yield "continuing";
|
||||
continue loop;
|
||||
}
|
||||
|
||||
yield 5;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
yield 6;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
genHelpers.check(gen(1, "break"), [
|
||||
0, 1, 0, 2, 3, 4, "breaking", 6
|
||||
]);
|
||||
assert.ok(false, "should have thrown an exception");
|
||||
} catch (err) {
|
||||
assert.strictEqual(err, e1);
|
||||
}
|
||||
|
||||
try {
|
||||
genHelpers.check(gen(3, "continue"), [
|
||||
0, 1, 0, 2, 3, 4, "continuing",
|
||||
1, 2, 3, 4, "continuing",
|
||||
2, 2, 3, 4, "continuing",
|
||||
6 // Loop finished naturally.
|
||||
]);
|
||||
assert.ok(false, "should have thrown an exception");
|
||||
} catch (err) {
|
||||
assert.strictEqual(err, e1);
|
||||
}
|
||||
|
||||
try {
|
||||
genHelpers.check(gen(3, "neither"), [
|
||||
0, 1, 0, 2, 3, 4, 5
|
||||
]);
|
||||
assert.ok(false, "should have thrown an exception");
|
||||
} catch (err) {
|
||||
assert.strictEqual(err, e4);
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
function *usingThrow() {
|
||||
try {
|
||||
try {
|
||||
try {
|
||||
throw "thrown";
|
||||
} finally {
|
||||
yield 1;
|
||||
}
|
||||
} catch (thrown) {
|
||||
yield thrown;
|
||||
} finally {
|
||||
yield 2;
|
||||
}
|
||||
} finally {
|
||||
yield 3;
|
||||
}
|
||||
}
|
||||
|
||||
function *usingRaise() {
|
||||
try {
|
||||
try {
|
||||
try {
|
||||
genHelpers.raise("thrown");
|
||||
} finally {
|
||||
yield 1;
|
||||
}
|
||||
} catch (thrown) {
|
||||
yield thrown;
|
||||
} finally {
|
||||
yield 2;
|
||||
}
|
||||
} finally {
|
||||
yield 3;
|
||||
}
|
||||
}
|
||||
|
||||
// should statically execute in order
|
||||
genHelpers.check(usingThrow(), [1, "thrown", 2, 3]);
|
||||
|
||||
// should dynamically execute in order
|
||||
genHelpers.check(usingRaise(), [1, "thrown", 2, 3]);
|
||||
@@ -1,18 +0,0 @@
|
||||
function *gen() {
|
||||
try {
|
||||
nonExistent;
|
||||
} catch (e) {
|
||||
yield function* () {
|
||||
yield e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var genFun2 = gen().next().value;
|
||||
assert.ok(regeneratorRuntime.isGeneratorFunction(genFun2));
|
||||
var gen2 = genFun2();
|
||||
var res = gen2.next();
|
||||
assert.ok(res.value instanceof ReferenceError);
|
||||
// Note that we don't do strict equality over the message because it varies
|
||||
// across browsers (if we ever want to run tests in browsers).
|
||||
assert.ok(res.value.message.match(/nonExistent/));
|
||||
@@ -1,22 +0,0 @@
|
||||
function A(first, second) {
|
||||
this.first = first;
|
||||
this.second = second;
|
||||
}
|
||||
|
||||
function *gen() {
|
||||
return yield new (yield 0)(yield 1, yield 2);
|
||||
}
|
||||
|
||||
var g = gen();
|
||||
|
||||
assert.deepEqual(g.next(), { value: 0, done: false });
|
||||
assert.deepEqual(g.next(A), { value: 1, done: false });
|
||||
assert.deepEqual(g.next("asdf"), { value: 2, done: false });
|
||||
|
||||
var info = g.next("zxcv");
|
||||
assert.strictEqual(info.done, false);
|
||||
assert.ok(info.value instanceof A);
|
||||
assert.strictEqual(info.value.first, "asdf");
|
||||
assert.strictEqual(info.value.second, "zxcv");
|
||||
|
||||
assert.deepEqual(g.next("qwer"), { value: "qwer", done: true });
|
||||
@@ -1,40 +0,0 @@
|
||||
function *range(n) {
|
||||
for (var i = 0; i < n; ++i) {
|
||||
yield i;
|
||||
}
|
||||
}
|
||||
|
||||
function *chain(a, b) {
|
||||
yield* a;
|
||||
yield* b;
|
||||
}
|
||||
|
||||
genHelpers.check(chain(range(3), range(5)), [0, 1, 2, 0, 1, 2, 3, 4]);
|
||||
|
||||
function *y3(x) {
|
||||
return yield yield yield x;
|
||||
}
|
||||
|
||||
function *y5(x) {
|
||||
return yield yield yield yield yield x;
|
||||
}
|
||||
|
||||
genHelpers.check(
|
||||
chain(y3("foo"), y5("bar")),
|
||||
["foo", 1, 2, "bar", 4, 5, 6, 7]
|
||||
);
|
||||
|
||||
var g3 = y3("three");
|
||||
assert.deepEqual(g3.next(), {
|
||||
value: "three",
|
||||
done: false
|
||||
});
|
||||
|
||||
var g5 = y5("five");
|
||||
assert.deepEqual(g5.next(), {
|
||||
value: "five",
|
||||
done: false
|
||||
});
|
||||
|
||||
var undef; // A little easier to read than void 0.
|
||||
genHelpers.check(chain(g3, g5), [undef, 1, undef, 3, 4, 5]);
|
||||
@@ -1,29 +0,0 @@
|
||||
function *inner() {
|
||||
return [yield 1, yield 2];
|
||||
}
|
||||
|
||||
function *outer(delegate) {
|
||||
return yield* delegate;
|
||||
}
|
||||
|
||||
var n = inner();
|
||||
|
||||
assert.deepEqual(n.next(), {
|
||||
value: 1,
|
||||
done: false
|
||||
});
|
||||
|
||||
var g = outer(n);
|
||||
|
||||
// I would really like to be able to pass 3 to g.next here, but V8
|
||||
// ignores values sent to newborn generators, and SpiderMonkey throws
|
||||
// a TypeError.
|
||||
assert.deepEqual(g.next(), {
|
||||
value: 2,
|
||||
done: false
|
||||
});
|
||||
|
||||
assert.deepEqual(g.next(4), {
|
||||
value: [void 0, 4],
|
||||
done: true
|
||||
});
|
||||
@@ -1,58 +0,0 @@
|
||||
var markers = [];
|
||||
|
||||
function *inner() {
|
||||
markers.push(0);
|
||||
var sent1 = yield 1;
|
||||
markers.push(2);
|
||||
var sent2 = yield 2;
|
||||
markers.push(3);
|
||||
return [sent1, sent2];
|
||||
}
|
||||
|
||||
function wrapper(delegate) {
|
||||
var gen = (function*() {
|
||||
// This yield is the "initial yield" whose argument we ignore.
|
||||
var sent = yield "ignored", info;
|
||||
|
||||
markers.push(1);
|
||||
|
||||
while (!(info = delegate.next(sent)).done) {
|
||||
sent = yield info.value;
|
||||
}
|
||||
|
||||
markers.push(4);
|
||||
|
||||
return info.value;
|
||||
})();
|
||||
|
||||
// Ensure that gen is not newborn and that the next invocation of
|
||||
// gen.next(value) can send value to the initial yield expression.
|
||||
gen.next();
|
||||
|
||||
return gen;
|
||||
}
|
||||
|
||||
var n = inner();
|
||||
|
||||
assert.deepEqual(n.next(), {
|
||||
value: 1,
|
||||
done: false
|
||||
});
|
||||
|
||||
var g = wrapper(n);
|
||||
|
||||
// Unlike in the previous spec, it's fine to pass 3 to g.next here,
|
||||
// because g is not newborn, because g.next was already called once
|
||||
// before g was returned from the wrapper function.
|
||||
assert.deepEqual(g.next(3), {
|
||||
value: 2,
|
||||
done: false
|
||||
});
|
||||
|
||||
assert.deepEqual(g.next(4), {
|
||||
value: [3, 4],
|
||||
done: true
|
||||
});
|
||||
|
||||
// Ensure we encountered the marker points in the expected order.
|
||||
assert.deepEqual(markers, [0, 1, 2, 3, 4]);
|
||||
@@ -1,9 +0,0 @@
|
||||
function *gen(a, b) {
|
||||
yield {
|
||||
a: a - (yield a),
|
||||
b: yield b
|
||||
};
|
||||
}
|
||||
|
||||
genHelpers.check(gen(1, 2), [1, 2, { a: 0, b: 2 }]);
|
||||
genHelpers.check(gen(4, 2), [4, 2, { a: 3, b: 2 }]);
|
||||
@@ -1,17 +0,0 @@
|
||||
function *gen(fn) {
|
||||
return {
|
||||
a: yield "a",
|
||||
b: yield "b",
|
||||
c: fn(yield "c", yield "d"),
|
||||
d: [yield "e", yield "f"]
|
||||
};
|
||||
}
|
||||
|
||||
genHelpers.check(gen(function sum(x, y) {
|
||||
return x + y;
|
||||
}), ["a", "b", "c", "d", "e", "f"], {
|
||||
a: 1,
|
||||
b: 2,
|
||||
c: 3 + 4,
|
||||
d: [5, 6]
|
||||
});
|
||||
@@ -1,9 +0,0 @@
|
||||
function *range(n) {
|
||||
for (var i = 0; i < n; ++i) {
|
||||
yield i;
|
||||
}
|
||||
}
|
||||
|
||||
genHelpers.check(range(0), []);
|
||||
|
||||
genHelpers.check(range(5), [0, 1, 2, 3, 4]);
|
||||
@@ -1,5 +0,0 @@
|
||||
function *gen() { return (yield 0) + (yield 0); }
|
||||
var itr = gen();
|
||||
itr.next();
|
||||
itr.next(1);
|
||||
assert.equal(itr.next(2).value, 3);
|
||||
@@ -1,6 +0,0 @@
|
||||
function *gen(x) {
|
||||
yield x;
|
||||
}
|
||||
|
||||
genHelpers.check(gen("oyez"), ["oyez"]);
|
||||
genHelpers.check(gen("foo", "bar"), ["foo"]);
|
||||
@@ -1,11 +0,0 @@
|
||||
function *gen(a) {
|
||||
switch (yield a) {
|
||||
case (yield "x") - a:
|
||||
return "first case";
|
||||
case (yield "y") - a:
|
||||
return "second case";
|
||||
}
|
||||
}
|
||||
|
||||
genHelpers.check(gen(1), [1, "x"], "first case");
|
||||
genHelpers.check(gen(2), [2, "x", "y"], "second case");
|
||||
@@ -1,7 +0,0 @@
|
||||
function *gen(obj) {
|
||||
yield obj.arguments;
|
||||
obj.arguments = "oyez";
|
||||
yield obj;
|
||||
}
|
||||
|
||||
genHelpers.check(gen({ arguments: 42 }), [42, { arguments: "oyez" }]);
|
||||
@@ -1,12 +0,0 @@
|
||||
function *sum() {
|
||||
var result = 0;
|
||||
|
||||
for (var i = 0; i < arguments.length; ++i) {
|
||||
yield result += arguments[i];
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
genHelpers.check(sum(1, 2, 3), [1, 3, 6], 6);
|
||||
genHelpers.check(sum(9, -5, 3, 0, 2), [9, 4, 7, 7, 9], 9);
|
||||
@@ -1,13 +0,0 @@
|
||||
function *gen(x) {
|
||||
throw 1;
|
||||
}
|
||||
|
||||
var u = gen();
|
||||
|
||||
try {
|
||||
u.next();
|
||||
} catch (err) {
|
||||
assert.strictEqual(err, 1);
|
||||
}
|
||||
|
||||
genHelpers.assertAlreadyFinished(u);
|
||||
@@ -1,42 +0,0 @@
|
||||
|
||||
function *usingThrow() {
|
||||
yield 0;
|
||||
try {
|
||||
try {
|
||||
yield 1;
|
||||
throw 2;
|
||||
yield 3;
|
||||
} catch (x) {
|
||||
throw yield x;
|
||||
} finally {
|
||||
yield 5;
|
||||
}
|
||||
} catch (thrown) {
|
||||
yield thrown;
|
||||
}
|
||||
yield 6;
|
||||
}
|
||||
|
||||
function *usingRaise() {
|
||||
yield 0;
|
||||
try {
|
||||
try {
|
||||
yield 1;
|
||||
genHelpers.raise(2);
|
||||
yield 3;
|
||||
} catch (x) {
|
||||
throw yield x;
|
||||
} finally {
|
||||
yield 5;
|
||||
}
|
||||
} catch (thrown) {
|
||||
yield thrown;
|
||||
}
|
||||
yield 6;
|
||||
}
|
||||
|
||||
// should statically catch and then finalize
|
||||
genHelpers.check(usingThrow(), [0, 1, 2, 5, 3, 6]);
|
||||
|
||||
// should dynamically catch and then finalize
|
||||
genHelpers.check(usingRaise(), [0, 1, 2, 5, 3, 6]);
|
||||
@@ -1,33 +0,0 @@
|
||||
function *usingThrow(x) {
|
||||
yield 0;
|
||||
try {
|
||||
yield 1;
|
||||
if (x % 2 === 0)
|
||||
throw 2;
|
||||
yield x;
|
||||
} catch (x) {
|
||||
yield x;
|
||||
}
|
||||
yield 3;
|
||||
}
|
||||
|
||||
function *usingRaise(x) {
|
||||
yield 0;
|
||||
try {
|
||||
yield 1;
|
||||
if (x % 2 === 0)
|
||||
genHelpers.raise(2);
|
||||
yield x;
|
||||
} catch (x) {
|
||||
yield x;
|
||||
}
|
||||
yield 3;
|
||||
}
|
||||
|
||||
// should catch static exceptions properly
|
||||
genHelpers.check(usingThrow(4), [0, 1, 2, 3]);
|
||||
genHelpers.check(usingThrow(5), [0, 1, 5, 3]);
|
||||
|
||||
// should catch dynamic exceptions properly
|
||||
genHelpers.check(usingRaise(4), [0, 1, 2, 3]);
|
||||
genHelpers.check(usingRaise(5), [0, 1, 5, 3]);
|
||||
@@ -1,114 +0,0 @@
|
||||
function *usingThrow(condition) {
|
||||
yield 0;
|
||||
try {
|
||||
yield 1;
|
||||
throw 2;
|
||||
yield 3;
|
||||
} finally {
|
||||
if (condition) {
|
||||
yield 4;
|
||||
return 5;
|
||||
}
|
||||
yield 6;
|
||||
return 7;
|
||||
}
|
||||
}
|
||||
|
||||
function *usingRaise(condition) {
|
||||
yield 0;
|
||||
try {
|
||||
yield 1;
|
||||
genHelpers.raise(2);
|
||||
yield 3;
|
||||
} finally {
|
||||
if (condition) {
|
||||
yield 4;
|
||||
return 5;
|
||||
}
|
||||
yield 6;
|
||||
return 7;
|
||||
}
|
||||
}
|
||||
|
||||
// should execute finally blocks statically
|
||||
genHelpers.check(usingThrow(true), [0, 1, 4], 5);
|
||||
genHelpers.check(usingThrow(false), [0, 1, 6], 7);
|
||||
|
||||
// should execute finally blocks dynamically
|
||||
genHelpers.check(usingRaise(true), [0, 1, 4], 5);
|
||||
genHelpers.check(usingRaise(false), [0, 1, 6], 7);
|
||||
|
||||
// should execute finally blocks before throwing
|
||||
var uncaughtError = new Error("uncaught");
|
||||
|
||||
function *uncaught(condition) {
|
||||
try {
|
||||
yield 0;
|
||||
if (condition) {
|
||||
yield 1;
|
||||
genHelpers.raise(uncaughtError);
|
||||
}
|
||||
yield 2;
|
||||
} finally {
|
||||
yield 3;
|
||||
}
|
||||
yield 4;
|
||||
}
|
||||
|
||||
genHelpers.check(uncaught(false), [0, 2, 3, 4]);
|
||||
|
||||
var u = uncaught(true);
|
||||
|
||||
assert.deepEqual(u.next(), { value: 0, done: false });
|
||||
assert.deepEqual(u.next(), { value: 1, done: false });
|
||||
assert.deepEqual(u.next(), { value: 3, done: false });
|
||||
|
||||
try {
|
||||
u.next();
|
||||
assert.ok(false, "should have thrown an exception");
|
||||
} catch (err) {
|
||||
assert.strictEqual(err, uncaughtError);
|
||||
}
|
||||
|
||||
// should throw correct error when finally contains catch
|
||||
var right = new Error("right");
|
||||
var wrong = new Error("wrong");
|
||||
|
||||
function *gen() {
|
||||
try {
|
||||
yield 0;
|
||||
genHelpers.raise(right);
|
||||
} finally {
|
||||
yield 1;
|
||||
try {
|
||||
genHelpers.raise(wrong);
|
||||
} catch (err) {
|
||||
assert.strictEqual(err, wrong);
|
||||
yield 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var g = gen();
|
||||
|
||||
assert.deepEqual(g.next(), {
|
||||
value: 0,
|
||||
done: false
|
||||
});
|
||||
|
||||
assert.deepEqual(g.next(), {
|
||||
value: 1,
|
||||
done: false
|
||||
});
|
||||
|
||||
assert.deepEqual(g.next(), {
|
||||
value: 2,
|
||||
done: false
|
||||
});
|
||||
|
||||
try {
|
||||
g.next();
|
||||
assert.ok(false, "should have thrown an exception");
|
||||
} catch (err) {
|
||||
assert.strictEqual(err, right);
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
function getThis() {
|
||||
return this;
|
||||
}
|
||||
|
||||
// This is almost certainly the global object, but there's a chance it
|
||||
// might be null or undefined (in strict mode).
|
||||
var unqualifiedThis = getThis();
|
||||
|
||||
function *invoke() {
|
||||
// It seems like a bug in the ES6 spec that we have to yield an
|
||||
// argument instead of just calling (yield)().
|
||||
return (yield "dummy")();
|
||||
}
|
||||
|
||||
var g = invoke();
|
||||
var info = g.next();
|
||||
|
||||
assert.deepEqual(info, { value: "dummy", done: false });
|
||||
|
||||
info = g.next(getThis);
|
||||
|
||||
// Avoid using assert.strictEqual when the arguments might equal the
|
||||
// global object, since JSON.stringify chokes on circular structures.
|
||||
assert.ok(info.value === unqualifiedThis);
|
||||
|
||||
assert.strictEqual(info.done, true);
|
||||
@@ -1,6 +0,0 @@
|
||||
function *gen(n) {
|
||||
return yield yield yield yield n;
|
||||
}
|
||||
|
||||
genHelpers.check(gen(5), [5, 1, 2, 3], 4);
|
||||
genHelpers.check(gen("asdf"), ["asdf", 1, 2, 3], 4);
|
||||
@@ -1,22 +0,0 @@
|
||||
function pumpNumber(gen) {
|
||||
var n = 0;
|
||||
|
||||
while (true) {
|
||||
var res = n > 0 ? gen.next(n) : gen.next();
|
||||
n = res.value;
|
||||
if (res.done) {
|
||||
return n;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function* foo() {
|
||||
return (yield* bar()) + (yield* bar());
|
||||
}
|
||||
|
||||
function* bar() {
|
||||
return (yield 2) + (yield 3);
|
||||
}
|
||||
|
||||
assert.strictEqual(pumpNumber(bar()), 5);
|
||||
assert.strictEqual(pumpNumber(foo()), 10);
|
||||
@@ -1,11 +0,0 @@
|
||||
function* foo() {
|
||||
yield 0;
|
||||
return yield* bar();
|
||||
}
|
||||
|
||||
function* bar() {
|
||||
yield 1;
|
||||
return 2;
|
||||
}
|
||||
|
||||
genHelpers.check(foo(), [0, 1], 2);
|
||||
@@ -1,7 +0,0 @@
|
||||
Copyright (c) 2014, Facebook, Inc.
|
||||
All rights reserved.
|
||||
|
||||
This source code is licensed under the BSD-style license found in the
|
||||
https://raw.github.com/facebook/regenerator/master/LICENSE file. An
|
||||
additional grant of patent rights can be found in the PATENTS file in
|
||||
the same directory.
|
||||
@@ -1,26 +0,0 @@
|
||||
async function outer(value) {
|
||||
var resolved = false;
|
||||
var p1 = new Promise(function(resolve) {
|
||||
setTimeout(function() {
|
||||
resolve(value + 1);
|
||||
resolved = true;
|
||||
}, 0);
|
||||
});
|
||||
|
||||
assert.strictEqual(resolved, false);
|
||||
|
||||
var v2 = await p1.then(function(value) {
|
||||
return value + 1;
|
||||
});
|
||||
|
||||
assert.strictEqual(resolved, true);
|
||||
|
||||
var v1 = await p1;
|
||||
|
||||
return [v1, v2];
|
||||
}
|
||||
|
||||
outer(1).then(function(pair) {
|
||||
assert.deepEqual(pair, [2, 3]);
|
||||
done();
|
||||
}).catch(done);
|
||||
@@ -1,40 +0,0 @@
|
||||
var markers = [];
|
||||
|
||||
async function innerMost(marker) {
|
||||
markers.push(marker);
|
||||
return await marker;
|
||||
}
|
||||
|
||||
async function inner(marker) {
|
||||
markers.push(marker);
|
||||
|
||||
assert.strictEqual(
|
||||
await innerMost(marker + 1),
|
||||
marker + 1
|
||||
);
|
||||
|
||||
markers.push(marker + 2);
|
||||
|
||||
assert.strictEqual(
|
||||
await innerMost(marker + 3),
|
||||
marker + 3
|
||||
);
|
||||
|
||||
markers.push(marker + 4);
|
||||
}
|
||||
|
||||
async function outer() {
|
||||
markers.push(0);
|
||||
await inner(1);
|
||||
markers.push(6);
|
||||
await inner(7);
|
||||
markers.push(12);
|
||||
}
|
||||
|
||||
outer().then(function() {
|
||||
var expected = [];
|
||||
for (var i = 0; i <= 12; ++i)
|
||||
expected.push(i);
|
||||
assert.deepEqual(markers, expected);
|
||||
done();
|
||||
}).catch(done);
|
||||
@@ -1,15 +0,0 @@
|
||||
var called = false;
|
||||
|
||||
async function noAwait(value) {
|
||||
called = true;
|
||||
return value;
|
||||
}
|
||||
|
||||
var promise = noAwait("asdf");
|
||||
assert.strictEqual(called, true);
|
||||
|
||||
promise.then(function(value) {
|
||||
assert.strictEqual(called, true);
|
||||
assert.strictEqual(value, "asdf");
|
||||
done();
|
||||
}).catch(done);
|
||||
@@ -1,19 +0,0 @@
|
||||
var flag1 = false;
|
||||
var flag2 = false;
|
||||
|
||||
async function oneAwait(value) {
|
||||
flag1 = true;
|
||||
var result = await value;
|
||||
flag2 = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
var promise = oneAwait("asdf");
|
||||
assert.strictEqual(flag1, true);
|
||||
assert.strictEqual(flag2, false);
|
||||
|
||||
promise.then(function(value) {
|
||||
assert.strictEqual(flag2, true);
|
||||
assert.strictEqual(value, "asdf");
|
||||
done();
|
||||
}).catch(done);
|
||||
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"asyncExec": true,
|
||||
"experimental": true
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
var error = new Error("rejected");
|
||||
|
||||
async function e(arg) {
|
||||
if (arg) {
|
||||
throw arg;
|
||||
}
|
||||
return "did not throw";
|
||||
}
|
||||
|
||||
async function f(arg) {
|
||||
return await e(arg);
|
||||
}
|
||||
|
||||
async function g(arg) {
|
||||
return await f(arg);
|
||||
}
|
||||
|
||||
async function h(arg) {
|
||||
return await Promise.all([
|
||||
g(arg),
|
||||
Promise.resolve("dummy")
|
||||
]);
|
||||
}
|
||||
|
||||
Promise.all([
|
||||
h(error).then(function() {
|
||||
done(new Error("should not have resolved"));
|
||||
}, function(e) {
|
||||
assert.strictEqual(e, error);
|
||||
return "ok1";
|
||||
}),
|
||||
h(null).then(function(result) {
|
||||
assert.deepEqual(result, [
|
||||
"did not throw",
|
||||
"dummy"
|
||||
]);
|
||||
return "ok2";
|
||||
})
|
||||
]).then(function(results) {
|
||||
assert.deepEqual(results, ["ok1", "ok2"]);
|
||||
done();
|
||||
}).catch(done);
|
||||
@@ -1,21 +0,0 @@
|
||||
var error = new Error("rejected");
|
||||
|
||||
async function f(arg) {
|
||||
try {
|
||||
return await arg;
|
||||
} catch (e) {
|
||||
assert.strictEqual(e, error);
|
||||
return "did throw";
|
||||
}
|
||||
}
|
||||
|
||||
Promise.all([
|
||||
f(Promise.reject(error)),
|
||||
f(Promise.resolve("did not throw"))
|
||||
]).then(function(results) {
|
||||
assert.deepEqual(results, [
|
||||
"did throw",
|
||||
"did not throw"
|
||||
]);
|
||||
done();
|
||||
}).catch(done);
|
||||
21
test/regenerator.js
Normal file
21
test/regenerator.js
Normal file
@@ -0,0 +1,21 @@
|
||||
require("../register")({
|
||||
blacklist: ["useStrict"],
|
||||
experimental: true
|
||||
});
|
||||
|
||||
var transform = require("../lib/6to5/transformation/transform");
|
||||
var fs = require("fs");
|
||||
var _ = require("lodash");
|
||||
|
||||
var regeneratorLoc = __dirname + "/../vendor/regenerator";
|
||||
|
||||
if (!fs.existsSync(regeneratorLoc)) {
|
||||
console.error("No vendor/regenerator - run `git submodule update --init && cd vendor/regenerator && npm install`");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
_.each(["tests", "async"], function (filename) {
|
||||
var loc = regeneratorLoc + "/test/" + filename + ".es6.js";
|
||||
var code = fs.readFileSync(loc, "utf8");
|
||||
require(loc);
|
||||
});
|
||||
Reference in New Issue
Block a user