Skip to content

Commit

Permalink
chore: add class static block tests
Browse files Browse the repository at this point in the history
it was copied from test262
refs: tc39/test262@afe217b
  • Loading branch information
aladdin-add committed Sep 16, 2021
1 parent 54ed0c0 commit 496b091
Show file tree
Hide file tree
Showing 63 changed files with 624 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class C {
static {
(await => 0);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class C {
static {
((x = await) => 0);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class C {
static {
(class await {});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@


var await = 0;
var fromParam, fromBody;

class C {
static {
new (class {
constructor(x = fromParam = await) {
fromBody = await;
}
});
}
}

assert.sameValue(fromParam, 0, 'from parameter');
assert.sameValue(fromBody, 0, 'from body');
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@


class C {
static {
(function await(await) {});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@


var await = 0;
var fromParam, fromBody;

class C {
static {
(function (x = fromParam = await) {
fromBody = await;
})();
}
}

assert.sameValue(fromParam, 0, 'from parameter');
assert.sameValue(fromBody, 0, 'from body');
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@


class C {
static {
(function * await (await) {});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@


var await = 0;
var fromParam, fromBody;

class C {
static {
(function * (x = fromParam = await) {
fromBody = await;
})().next();
}
}

assert.sameValue(fromParam, 0, 'from parameter');
assert.sameValue(fromBody, 0, 'from body');
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@


class C {
static {
({ await: 0 });
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class C {
static {
({ await });
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@


class C {
static {
(() => ({ await }));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@


class C {
static {
({set accessor(await) {}});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@


class C {
static {
({*method(await) {}});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@


class C {
static {
({method(await) {}});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@


var await = 0;
var fromParam, fromBody;

class C {
static {
({
set accessor(x = fromParam = await) {
fromBody = await;
}
}).accessor = undefined;
}
}

assert.sameValue(fromParam, 0, 'from parameter');
assert.sameValue(fromBody, 0, 'from body');
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@


var await = 0;
var fromParam, fromBody;

class C {
static {
({
*method(x = fromParam = await) {
fromBody = await;
}
}).method().next();
}
}

assert.sameValue(fromParam, 0, 'from parameter');
assert.sameValue(fromBody, 0, 'from body');
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@


var await = 0;
var fromParam, fromBody;

class C {
static {
({
method(x = fromParam = await) {
fromBody = await;
}
}).method();
}
}

assert.sameValue(fromParam, 0, 'from parameter');
assert.sameValue(fromBody, 0, 'from body');
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class C {
static {
await;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
label: while(false) {
class C {
static {
break;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@


var thrown = new Test262Error();
var caught;
var sameBlock = false;
var subsequentField = false;
var subsequentBlock = false;

try {
class C {
static {
throw thrown;
sameBlock = true;
}
static x = subsequentField = true;
static {
subsequentBlock = true;
}
}
} catch (error) {
caught = error;
}

assert.sameValue(caught, thrown);
assert.sameValue(sameBlock, false, 'same block');
assert.sameValue(subsequentField, false, 'subsequent field');
assert.sameValue(subsequentBlock, false, 'subsequent block');
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@


var fn, fnParam;
var gen, genParam;
var asyncFn, asyncFnParam;

class C {
static {
(function({test262 = fnParam = arguments}) {
fn = arguments;
})('function');

(function * ({test262 = genParam = arguments}) {
gen = arguments;
})('generator function').next();

(async function ({test262 = asyncFnParam = arguments}) {
asyncFn = arguments;
})('async function');
}
}

assert(compareArray(['function'], fn), 'body');
assert(compareArray(['function'], fnParam), 'parameter');
assert(compareArray(['generator function'], gen), 'body');
assert(compareArray(['generator function'], genParam), 'parameter');
assert(compareArray(['async function'], asyncFn), 'body');
assert(compareArray(['async function'], asyncFnParam), 'parameter');
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@


var instance;
var method, methodParam;
var getter;
var setter, setterParam;
var genMethod, genMethodParam;
var asyncMethod, asyncMethodParam;

class C {
static {
instance = new class {
method({test262 = methodParam = arguments}) {
method = arguments;
}
get accessor() {
getter = arguments;
}
set accessor({test262 = setterParam = arguments}) {
setter = arguments;
}
*gen({test262 = genMethodParam = arguments}) {
genMethod = arguments;
}
async async({test262 = asyncMethodParam = arguments}) {
asyncMethod = arguments;
}
}();
}
}

instance.method('method');
instance.accessor;
instance.accessor = 'setter';
instance.gen('generator method').next();
instance.async('async method');

assert(compareArray(['method'], method), 'body');
assert(compareArray(['method'], methodParam), 'parameter');
assert(compareArray([], getter), 'body');
assert(compareArray(['setter'], setter), 'body');
assert(compareArray(['setter'], setterParam), 'parameter');
assert(compareArray(['generator method'], genMethod), 'body');
assert(compareArray(['generator method'], genMethodParam), 'parameter');
assert(compareArray(['async method'], asyncMethod), 'body');
assert(compareArray(['async method'], asyncMethodParam), 'parameter');
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class C {
static {
class await {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@


class C {
static {
(() => { class await {} });
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@


var value = null;

class C {
static {
value = new.target;
}
}

assert.sameValue(value, undefined);
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@


var value;

class C {
static {
value = this;
}
}

assert.sameValue(value, C);
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class C {
static {
(class { [argument\u0073]() {} });
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
async function f() {
class C {
static {
await 0;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class C {
static {
x: x: 0;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class C {
static {
let x;
let x;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class C {
static {
let x;
var x;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function f() {
class C {
static {
return;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class C {
static {
super();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class C {
static {
x: while (false) {
break y;
}
}
}
Loading

0 comments on commit 496b091

Please sign in to comment.