Bug 1184922 - Part 3: Add a test for array destructuring with complicated default values. r=shu

This commit is contained in:
Tooru Fujisawa 2016-09-27 13:57:00 +09:00
Родитель 7c897db9d3
Коммит e0b580ab4b
6 изменённых файлов: 317 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,10 @@
var BUGNUMBER = 1184922;
var summary = "Array destructuring with various default values in various context - call/new expression";
print(BUGNUMBER + ": " + summary);
testDestructuringArrayDefault("func()");
testDestructuringArrayDefault("new func()");
if (typeof reportCompare === "function")
reportCompare(true, true);

Просмотреть файл

@ -0,0 +1,72 @@
var BUGNUMBER = 1184922;
var summary = "Array destructuring with various default values in various context - class expression and super/new.target";
print(BUGNUMBER + ": " + summary);
testDestructuringArrayDefault(`class E {
constructor() {}
method() {}
get v() {}
set v(_) {}
static method() {}
static get v() {}
static set v(_) {}
}`);
testDestructuringArrayDefault(`class E extends C {
constructor() {}
method() {}
get v() {}
set v(_) {}
static method() {}
static get v() {}
static set v(_) {}
}`);
var opt = {
no_plain: true,
no_func: true,
no_func_arg: true,
no_gen: true,
no_gen_arg: true,
no_ctor: true,
no_method: true,
no_pre_super: true,
no_comp: true,
no_derived_ctor: false,
};
testDestructuringArrayDefault("super()", opt);
opt = {
no_plain: true,
no_func: true,
no_func_arg: true,
no_gen: true,
no_gen_arg: true,
no_ctor: true,
no_comp: true,
no_derived_ctor: false,
no_method: false,
no_pre_super: false,
};
testDestructuringArrayDefault("super.foo()", opt);
opt = {
no_plain: true,
no_func: false,
no_func_arg: false,
no_gen: false,
no_gen_arg: false,
no_ctor: false,
no_derived_ctor: false,
no_method: false,
no_pre_super: false,
no_comp: false,
};
testDestructuringArrayDefault("new.target", opt);
if (typeof reportCompare === "function")
reportCompare(true, true);

Просмотреть файл

@ -0,0 +1,11 @@
var BUGNUMBER = 1184922;
var summary = "Array destructuring with various default values in various context - function expression";
print(BUGNUMBER + ": " + summary);
testDestructuringArrayDefault("function f() {}");
testDestructuringArrayDefault("function* g() {}");
testDestructuringArrayDefault("() => {}");
if (typeof reportCompare === "function")
reportCompare(true, true);

Просмотреть файл

@ -0,0 +1,16 @@
var BUGNUMBER = 1184922;
var summary = "Array destructuring with various default values in various context - simple literal";
print(BUGNUMBER + ": " + summary);
testDestructuringArrayDefault("'foo'");
testDestructuringArrayDefault("`foo`");
testDestructuringArrayDefault("func`foo`");
testDestructuringArrayDefault("/foo/");
testDestructuringArrayDefault("{}");
testDestructuringArrayDefault("[]");
if (typeof reportCompare === "function")
reportCompare(true, true);

Просмотреть файл

@ -0,0 +1,22 @@
var BUGNUMBER = 1184922;
var summary = "Array destructuring with various default values in various context - yield expression";
print(BUGNUMBER + ": " + summary);
var opt = {
no_plain: true,
no_func: true,
no_func_arg: true,
no_gen_arg: true,
no_ctor: true,
no_derived_ctor: true,
no_method: true,
no_pre_super: true,
no_comp: true,
no_gen: false,
};
testDestructuringArrayDefault("yield 1", opt);
if (typeof reportCompare === "function")
reportCompare(true, true);

Просмотреть файл

@ -0,0 +1,186 @@
(function(global) {
function func() {
}
class C {
foo() {
}
static foo() {
}
}
function test_one(pattern, val, opt) {
var stmts = [];
var i = 0;
var c;
stmts.push(`var ${pattern} = ${val};`);
if (!opt.no_comp) {
stmts.push(`[for (x of [1]) ${pattern} = ${val}];`);
stmts.push(`[...(for (x of [1]) ${pattern} = ${val})];`);
}
for (var stmt of stmts) {
if (!opt.no_plain) {
eval(`
${stmt}
`);
}
if (!opt.no_func) {
eval(`
function f${i}() {
${stmt}
}
f${i}();
`);
i++;
eval(`
var f${i} = function foo() {
${stmt}
};
f${i}();
`);
i++;
eval(`
var f${i} = () => {
${stmt}
};
f${i}();
`);
i++;
}
if (!opt.no_gen) {
eval(`
function* g${i}() {
${stmt}
}
[...g${i}()];
`);
i++;
eval(`
var g${i} = function* foo() {
${stmt}
};
[...g${i}()];
`);
i++;
}
if (!opt.no_ctor) {
eval(`
class D${i} {
constructor() {
${stmt}
}
}
new D${i}();
`);
i++;
}
if (!opt.no_derived_ctor) {
if (opt.no_pre_super) {
eval(`
class D${i} extends C {
constructor() {
${stmt}
try { super(); } catch (e) {}
}
}
new D${i}();
`);
i++;
} else {
eval(`
class D${i} extends C {
constructor() {
super();
${stmt}
}
}
new D${i}();
`);
i++;
}
}
if (!opt.no_method) {
eval(`
class D${i} extends C {
method() {
${stmt}
}
static staticMethod() {
${stmt}
}
}
new D${i}().method();
D${i}.staticMethod();
`);
i++;
}
}
if (!opt.no_func_arg) {
eval(`
function f${i}(${pattern}) {}
f${i}(${val});
`);
i++;
eval(`
var f${i} = function foo(${pattern}) {};
f${i}(${val});
`);
i++;
eval(`
var f${i} = (${pattern}) => {};
f${i}(${val});
`);
i++;
}
if (!opt.no_gen_arg) {
eval(`
function* g${i}(${pattern}) {}
[...g${i}(${val})];
`);
i++;
eval(`
var g${i} = function* foo(${pattern}) {};
[...g${i}(${val})];
`);
i++;
}
}
function test(expr, opt={}) {
var pattern = `[a=${expr}, ...c]`;
test_one(pattern, "[]", opt);
test_one(pattern, "[1]", opt);
pattern = `[,a=${expr}]`;
test_one(pattern, "[]", opt);
test_one(pattern, "[1]", opt);
test_one(pattern, "[1, 2]", opt);
pattern = `[{x: [a=${expr}]}]`;
test_one(pattern, "[{x: [1]}]", opt);
pattern = `[x=[a=${expr}]=[]]`;
test_one(pattern, "[]", opt);
test_one(pattern, "[1]", opt);
pattern = `[x=[a=${expr}]=[1]]`;
test_one(pattern, "[]", opt);
test_one(pattern, "[1]", opt);
}
global.testDestructuringArrayDefault = test;
})(this);