Replace runTestCase with assert helpers [test/language/expressions]

This commit is contained in:
André Bargull 2015-08-13 17:34:17 +02:00
parent ee8a222125
commit 73d5292b77
41 changed files with 177 additions and 270 deletions

View File

@ -8,24 +8,17 @@ description: >
simple assignment creates property on the global object if
LeftHandSide is an unresolvable reference
flags: [noStrict]
includes:
- runTestCase.js
- fnGlobalObject.js
includes: [fnGlobalObject.js]
---*/
function testcase() {
function foo() {
__ES3_1_test_suite_test_11_13_1_unique_id_3__ = 42;
}
foo();
var desc = Object.getOwnPropertyDescriptor(fnGlobalObject(), '__ES3_1_test_suite_test_11_13_1_unique_id_3__');
if (desc.value === 42 &&
desc.writable === true &&
desc.enumerable === true &&
desc.configurable === true) {
delete __ES3_1_test_suite_test_11_13_1_unique_id_3__;
return true;
}
}
runTestCase(testcase);
assert.sameValue(desc.value, 42, 'desc.value');
assert.sameValue(desc.writable, true, 'desc.writable');
assert.sameValue(desc.enumerable, true, 'desc.enumerable');
assert.sameValue(desc.configurable, true, 'desc.configurable');

View File

@ -6,20 +6,10 @@ es5id: 11.13.1-4-27-s
description: >
simple assignment throws TypeError if LeftHandSide is a readonly
property in strict mode (Global.undefined)
includes:
- runTestCase.js
- fnGlobalObject.js
flags: [onlyStrict]
includes: [fnGlobalObject.js]
---*/
function testcase() {
'use strict';
try {
assert.throws(TypeError, function() {
fnGlobalObject().undefined = 42;
return false;
}
catch (e) {
return (e instanceof TypeError);
}
}
runTestCase(testcase);
});

View File

@ -8,16 +8,17 @@ description: >
appears as the LeftHandSideExpression of simple assignment(=)
under strict mode
flags: [onlyStrict]
includes: [runTestCase.js]
---*/
function testcase() {
var err = null;
var blah = eval;
try {
eval("var eval = 20;");
return false;
} catch (e) {
return e instanceof SyntaxError && blah === eval;
err = e;
}
assert(err instanceof SyntaxError, 'err instanceof SyntaxError');
assert.sameValue(blah, eval, 'blah');
}
runTestCase(testcase);
testcase();

View File

@ -8,16 +8,17 @@ description: >
appears as the LeftHandSideExpression of simple assignment(=)
under strict mode
flags: [onlyStrict]
includes: [runTestCase.js]
---*/
function testcase() {
var err = null;
var blah = arguments;
try {
eval("var arguments = 20;");
return false;
} catch (e) {
return e instanceof SyntaxError && blah === arguments;
err = e;
}
assert(err instanceof SyntaxError, 'err instanceof SyntaxError');
assert.sameValue(blah, arguments, 'blah');
}
runTestCase(testcase);
testcase();

View File

@ -8,16 +8,17 @@ description: >
appears as the LeftHandSideExpression (PrimaryExpression) of
simple assignment(=) under strict mode
flags: [onlyStrict]
includes: [runTestCase.js]
---*/
function testcase() {
var err = null;
var blah = arguments;
try {
eval("(arguments) = 20;");
return false;
} catch (e) {
return e instanceof SyntaxError && blah === arguments;
err = e;
}
assert(err instanceof SyntaxError, 'err instanceof SyntaxError');
assert.sameValue(blah, arguments, 'blah');
}
runTestCase(testcase);
testcase();

View File

@ -6,15 +6,11 @@ es5id: 8.12.5-3-b_1
description: >
Changing the value of a data property should not affect it's
non-value property descriptor attributes.
includes: [runTestCase.js]
---*/
function testcase() {
var origReduce = Array.prototype.reduce;
var origDesc = Object.getOwnPropertyDescriptor(Array.prototype, "reduce");
var newDesc;
try {
Array.prototype.reduce = function () {;};
newDesc = Object.getOwnPropertyDescriptor(Array.prototype, "reduce");
var descArray = [origDesc, newDesc];
@ -22,19 +18,10 @@ function testcase() {
for (var j in descArray) { //Ensure no attributes are magically added to newDesc
for (var i in descArray[j]) {
if (i==="value") {
if (origDesc[i]===newDesc[i]) {
return false;
}
assert.notSameValue(origDesc[i], newDesc[i], 'origDesc[i]');
}
else if (origDesc[i]!==newDesc[i]) {
return false;
else {
assert.sameValue(origDesc[i], newDesc[i], 'origDesc[i]');
}
}
}
return true;
} finally {
Array.prototype.reduce = origReduce;
}
}
runTestCase(testcase);

View File

@ -6,19 +6,15 @@ es5id: 8.12.5-3-b_2
description: >
Changing the value of a data property should not affect it's
non-value property descriptor attributes.
includes: [runTestCase.js]
---*/
function testcase() {
var tempObj = {};
Object.defineProperty(tempObj, "reduce", { value:456, enumerable:false, writable:true});
var origReduce = tempObj.reduce;
var origDesc = Object.getOwnPropertyDescriptor(tempObj, "reduce");
var newDesc;
try {
tempObj.reduce = 123;
newDesc = Object.getOwnPropertyDescriptor(tempObj, "reduce");
var descArray = [origDesc, newDesc];
@ -26,19 +22,10 @@ function testcase() {
for (var j in descArray) {
for (var i in descArray[j]) {
if (i==="value") {
if (origDesc[i]===newDesc[i]) {
return false;
}
assert.notSameValue(origDesc[i], newDesc[i], 'origDesc[i]');
}
else if (origDesc[i]!==newDesc[i]) {
return false;
else {
assert.sameValue(origDesc[i], newDesc[i], 'origDesc[i]');
}
}
}
return true;
} finally {
tempObj.reduce = origReduce;
}
}
runTestCase(testcase);

View File

@ -6,34 +6,23 @@ es5id: 8.12.5-5-b_1
description: >
Changing the value of an accessor property should not affect it's
property descriptor attributes.
includes: [runTestCase.js]
---*/
function testcase() {
var tempObj = {};
Object.defineProperty(tempObj, "reduce", { get: function() {return 456;}, enumerable:false, set: function() {;}});
var origReduce = tempObj.reduce;
var origDesc = Object.getOwnPropertyDescriptor(tempObj, "reduce");
var newDesc;
try {
tempObj.reduce = 123;
newDesc = Object.getOwnPropertyDescriptor(tempObj, "reduce");
var descArray = [origDesc, newDesc];
for (var j in descArray) {
for (var i in descArray[j]) {
if (origDesc[i]!==newDesc[i]) {
return false;
}
assert.sameValue(origDesc[i], newDesc[i], 'origDesc[i]');
}
}
return tempObj.reduce===456;
} finally {
tempObj.reduce = origReduce;
}
}
runTestCase(testcase);
assert.sameValue(tempObj.reduce, 456, 'tempObj.reduce');

View File

@ -8,16 +8,17 @@ description: >
appear as the LeftHandSideExpression of a Compound Assignment
operator(*=)
flags: [onlyStrict]
includes: [runTestCase.js]
---*/
function testcase() {
var err = null;
var blah = arguments;
try {
eval("arguments *= 20;");
return false;
} catch (e) {
return e instanceof SyntaxError && blah === arguments;
err = e;
}
}
runTestCase(testcase);
assert(err instanceof SyntaxError, 'err instanceof SyntaxError');
assert.sameValue(blah, arguments, 'blah');
}
testcase();

View File

@ -8,16 +8,17 @@ description: >
appear as the LeftHandSideExpression of a Compound Assignment
operator(/=)
flags: [onlyStrict]
includes: [runTestCase.js]
---*/
function testcase() {
var err = null;
var blah = arguments;
try {
eval("arguments /= 20;");
return false;
} catch (e) {
return e instanceof SyntaxError && blah === arguments;
err = e;
}
}
runTestCase(testcase);
assert(err instanceof SyntaxError, 'err instanceof SyntaxError');
assert.sameValue(blah, arguments, 'blah');
}
testcase();

View File

@ -8,16 +8,17 @@ description: >
appear as the LeftHandSideExpression of a Compound Assignment
operator(%=)
flags: [onlyStrict]
includes: [runTestCase.js]
---*/
function testcase() {
var err = null;
var blah = arguments;
try {
eval("arguments %= 20;");
return false;
} catch (e) {
return e instanceof SyntaxError && blah === arguments;
err = e;
}
}
runTestCase(testcase);
assert(err instanceof SyntaxError, 'err instanceof SyntaxError');
assert.sameValue(blah, arguments, 'blah');
}
testcase();

View File

@ -8,16 +8,17 @@ description: >
appear as the LeftHandSideExpression of a Compound Assignment
operator(+=)
flags: [onlyStrict]
includes: [runTestCase.js]
---*/
function testcase() {
var err = null;
var blah = arguments;
try {
eval("arguments += 20;");
return false;
} catch (e) {
return e instanceof SyntaxError && blah === arguments;
err = e;
}
}
runTestCase(testcase);
assert(err instanceof SyntaxError, 'err instanceof SyntaxError');
assert.sameValue(blah, arguments, 'blah');
}
testcase();

View File

@ -8,16 +8,17 @@ description: >
appear as the LeftHandSideExpression of a Compound Assignment
operator(-=)
flags: [onlyStrict]
includes: [runTestCase.js]
---*/
function testcase() {
var err = null;
var blah = arguments;
try {
eval("arguments -= 20;");
return false;
} catch (e) {
return e instanceof SyntaxError && blah === arguments;
err = e;
}
}
runTestCase(testcase);
assert(err instanceof SyntaxError, 'err instanceof SyntaxError');
assert.sameValue(blah, arguments, 'blah');
}
testcase();

View File

@ -8,16 +8,17 @@ description: >
appear as the LeftHandSideExpression of a Compound Assignment
operator(<<=)
flags: [onlyStrict]
includes: [runTestCase.js]
---*/
function testcase() {
var err = null;
var blah = arguments;
try {
eval("arguments <<= 20;");
return false;
} catch (e) {
return e instanceof SyntaxError && blah === arguments;
err = e;
}
}
runTestCase(testcase);
assert(err instanceof SyntaxError, 'err instanceof SyntaxError');
assert.sameValue(blah, arguments, 'blah');
}
testcase();

View File

@ -8,16 +8,17 @@ description: >
appear as the LeftHandSideExpression of a Compound Assignment
operator(>>=)
flags: [onlyStrict]
includes: [runTestCase.js]
---*/
function testcase() {
var err = null;
var blah = arguments;
try {
eval("arguments >>= 20;");
return false;
} catch (e) {
return e instanceof SyntaxError && blah === arguments;
err = e;
}
}
runTestCase(testcase);
assert(err instanceof SyntaxError, 'err instanceof SyntaxError');
assert.sameValue(blah, arguments, 'blah');
}
testcase();

View File

@ -8,16 +8,17 @@ description: >
appear as the LeftHandSideExpression of a Compound Assignment
operator(>>>=)
flags: [onlyStrict]
includes: [runTestCase.js]
---*/
function testcase() {
var err = null;
var blah = arguments;
try {
eval("arguments >>>= 20;");
return false;
} catch (e) {
return e instanceof SyntaxError && blah === arguments;
err = e;
}
}
runTestCase(testcase);
assert(err instanceof SyntaxError, 'err instanceof SyntaxError');
assert.sameValue(blah, arguments, 'blah');
}
testcase();

View File

@ -8,16 +8,17 @@ description: >
appear as the LeftHandSideExpression of a Compound Assignment
operator(&=)
flags: [onlyStrict]
includes: [runTestCase.js]
---*/
function testcase() {
var err = null;
var blah = arguments;
try {
eval("arguments &= 20;");
return false;
} catch (e) {
return e instanceof SyntaxError && blah === arguments;
err = e;
}
}
runTestCase(testcase);
assert(err instanceof SyntaxError, 'err instanceof SyntaxError');
assert.sameValue(blah, arguments, 'blah');
}
testcase();

View File

@ -8,16 +8,17 @@ description: >
appear as the LeftHandSideExpression of a Compound Assignment
operator(^=)
flags: [onlyStrict]
includes: [runTestCase.js]
---*/
function testcase() {
var err = null;
var blah = arguments;
try {
eval("arguments ^= 20;");
return false;
} catch (e) {
return e instanceof SyntaxError && blah === arguments;
err = e;
}
}
runTestCase(testcase);
assert(err instanceof SyntaxError, 'err instanceof SyntaxError');
assert.sameValue(blah, arguments, 'blah');
}
testcase();

View File

@ -8,16 +8,17 @@ description: >
appear as the LeftHandSideExpression of a Compound Assignment
operator(|=)
flags: [onlyStrict]
includes: [runTestCase.js]
---*/
function testcase() {
var err = null;
var blah = arguments;
try {
eval("arguments |= 20;");
return false;
} catch (e) {
return e instanceof SyntaxError && blah === arguments;
err = e;
}
}
runTestCase(testcase);
assert(err instanceof SyntaxError, 'err instanceof SyntaxError');
assert.sameValue(blah, arguments, 'blah');
}
testcase();

View File

@ -8,18 +8,14 @@ info: >
es5id: 11.4.1-0-1
description: delete operator as UnaryExpression
flags: [noStrict]
includes: [runTestCase.js]
---*/
function testcase() {
var x = 1;
var y = 2;
var z = 3;
if( (!delete x || delete y) &&
delete delete z)
{
return true;
}
assert((!delete x || delete y), '(!delete x || delete y)');
assert(delete delete z, 'delete delete z');
}
runTestCase(testcase);
testcase();

View File

@ -4,13 +4,8 @@
/*---
es5id: 11.4.1-2-1
description: delete operator returns true when deleting a non-reference (number)
includes: [runTestCase.js]
---*/
function testcase() {
var d = delete 42;
if (d === true) {
return true;
}
}
runTestCase(testcase);
assert.sameValue(d, true, 'd');

View File

@ -10,7 +10,6 @@ description: >
delete operator returns true on deleting arguments
propterties(arguments.callee)
flags: [noStrict]
includes: [runTestCase.js]
---*/
function testcase() {
@ -19,7 +18,8 @@ function testcase() {
return (delete arguments.callee);
}
var d = delete arguments.callee;
if(d === true && arguments.callee === undefined)
return true;
assert.sameValue(d, true, 'd');
assert.sameValue(arguments.callee, undefined, 'arguments.callee');
}
runTestCase(testcase);
testcase();

View File

@ -8,7 +8,6 @@ info: >
es5id: 11.4.1-4.a-13
description: delete operator returns false when deleting Array object
flags: [noStrict]
includes: [runTestCase.js]
---*/
function testcase() {
@ -18,7 +17,7 @@ function testcase() {
var d = delete a
if(d === false && Array.isArray(a) === true)
return true;
assert.sameValue(d, false, 'd');
assert.sameValue(Array.isArray(a), true, 'Array.isArray(a)');
}
runTestCase(testcase);
testcase();

View File

@ -8,12 +8,10 @@ info: >
es5id: 11.4.1-4.a-16
description: delete operator returns false on deleting arguments object
flags: [noStrict]
includes: [runTestCase.js]
---*/
function testcase() {
if(delete arguments === false && arguments !== undefined)
return true;
assert.sameValue(delete arguments, false, 'delete arguments');
assert.notSameValue(arguments, undefined, 'arguments');
}
runTestCase(testcase);
testcase();

View File

@ -7,17 +7,12 @@ info: >
language provides no way to directly exercise [[Delete]], the tests are placed here.
es5id: 11.4.1-4.a-17
description: delete operator returns true on deleting a arguments element
includes: [runTestCase.js]
---*/
function testcase() {
function foo(a,b)
{
var d = delete arguments[0];
return (d === true && arguments[0] === undefined);
}
if(foo(1,2) === true)
return true;
}
runTestCase(testcase);
assert.sameValue(foo(1,2), true, 'foo(1,2)');

View File

@ -10,7 +10,6 @@ description: >
delete operator returns false when deleting the declaration of the environment object
inside 'with'
flags: [noStrict]
includes: [runTestCase.js]
---*/
function testcase() {
@ -21,9 +20,9 @@ function testcase() {
{
d = delete o;
}
if (d === false && typeof(o) === 'object' && o.x === 1) {
return true;
}
return false;
assert.sameValue(d, false, 'd');
assert.sameValue(typeof(o), 'object', 'typeof(o)');
assert.sameValue(o.x, 1, 'o.x');
}
runTestCase(testcase);
testcase();

View File

@ -8,15 +8,13 @@ info: >
es5id: 11.4.1-4.a-7
description: delete operator inside 'eval'
flags: [noStrict]
includes: [runTestCase.js]
---*/
function testcase() {
var x = 1;
var d = eval("delete x");
if (d === false && x === 1) {
return true;
}
return false;
assert.sameValue(d, false, 'd');
assert.sameValue(x, 1, 'x');
}
runTestCase(testcase);
testcase();

View File

@ -7,7 +7,6 @@ description: >
delete operator returns false when deleting a direct reference to
a var
flags: [noStrict]
includes: [runTestCase.js]
---*/
function testcase() {
@ -15,7 +14,8 @@ function testcase() {
// Now, deleting 'x' directly should fail;
var d = delete x;
if(d === false && x === 1)
return true;
assert.sameValue(d, false, 'd');
assert.sameValue(x, 1, 'x');
}
runTestCase(testcase);
testcase();

View File

@ -7,8 +7,6 @@ description: >
delete operator returns false when deleting a direct reference to
a function name
flags: [noStrict]
includes:
- runTestCase.js
---*/
function testcase() {
@ -16,7 +14,8 @@ function testcase() {
// Now, deleting 'foo' directly should fail;
var d = delete foo;
if(d === false && typeof foo === 'function')
return true;
assert.sameValue(d, false, 'd');
assert.sameValue(typeof foo, 'function', 'typeof foo');
}
runTestCase(testcase);
testcase();

View File

@ -7,20 +7,16 @@ info: >
probably be replaced by some more targeted tests. AllenWB
es5id: 11.1.5-0-1
description: Object literal - get set property
includes: [runTestCase.js]
---*/
function testcase() {
var s1 = "In getter";
var s2 = "In setter";
var s3 = "Modified by setter";
var o;
eval("o = {get foo(){ return s1;},set foo(arg){return s2 = s3}};");
if(o.foo !== s1)
return false;
assert.sameValue(o.foo, s1, 'o.foo');
o.foo=10;
if(s2 !== s3)
return false;
return true;
}
runTestCase(testcase);
assert.sameValue(s2, s3, 's2');

View File

@ -7,25 +7,21 @@ info: >
probably be replaced by some more targeted tests. AllenWB
es5id: 11.1.5-0-2
description: Object literal - multiple get set properties
includes: [runTestCase.js]
---*/
function testcase() {
var s1 = "First getter";
var s2 = "First setter";
var s3 = "Second getter";
var o;
eval("o = {get foo(){ return s1;},set foo(arg){return s2 = s3}, get bar(){ return s3}, set bar(arg){ s3 = arg;}};");
if(o.foo !== s1)
return false;
assert.sameValue(o.foo, s1, 'o.foo');
o.foo = 10;
if(s2 !== s3)
return false;
if(o.bar !== s3)
return false;
assert.sameValue(s2, s3, 's2');
assert.sameValue(o.bar, s3, 'o.bar');
o.bar = "Second setter";
if(o.bar !== "Second setter")
return false;
return true;
}
runTestCase(testcase);
assert.sameValue(o.bar, "Second setter", 'o.bar');

View File

@ -7,16 +7,13 @@ description: >
Strict Mode - SyntaxError is thrown if the identifier 'arguments'
appear as a PostfixExpression(arguments--)
flags: [onlyStrict]
includes: [runTestCase.js]
---*/
function testcase() {
var blah = arguments;
try {
assert.throws(SyntaxError, function() {
eval("arguments--;");
return false;
} catch (e) {
return e instanceof SyntaxError && blah === arguments;
}
});
assert.sameValue(blah, arguments, 'blah');
}
runTestCase(testcase);
testcase();

View File

@ -6,12 +6,11 @@ es5id: 11.3.2-2-3-s
description: >
SyntaxError is not thrown if the identifier 'arguments[...]' appears as a
PostfixExpression(arguments--)
includes: [runTestCase.js]
---*/
function testcase() {
arguments[1] = 7;
arguments[1]--;
return arguments[1]===6;
assert.sameValue(arguments[1], 6, 'arguments[1]');
}
runTestCase(testcase);
testcase();

View File

@ -7,16 +7,13 @@ description: >
Strict Mode - SyntaxError is thrown if the identifier 'arguments'
appear as a PostfixExpression(arguments++)
flags: [onlyStrict]
includes: [runTestCase.js]
---*/
function testcase() {
var blah = arguments;
try {
assert.throws(SyntaxError, function() {
eval("arguments++;");
return false;
} catch (e) {
return e instanceof SyntaxError && blah === arguments;
}
});
assert.sameValue(blah, arguments, 'blah');
}
runTestCase(testcase);
testcase();

View File

@ -7,12 +7,11 @@ description: >
Strict Mode - SyntaxError is not thrown if the identifier
'arguments[...]' appears as a PostfixExpression(arguments++)
flags: [onlyStrict]
includes: [runTestCase.js]
---*/
function testcase() {
arguments[1] = 7;
arguments[1]++;
return arguments[1]===8;
assert.sameValue(arguments[1], 8, 'arguments[1]');
}
runTestCase(testcase);
testcase();

View File

@ -5,16 +5,13 @@
es5id: 11.4.5-2-2-s
description: Strict Mode - SyntaxError is thrown for --arguments
flags: [onlyStrict]
includes: [runTestCase.js]
---*/
function testcase() {
var blah = arguments;
try {
assert.throws(SyntaxError, function() {
eval("--arguments;");
return false;
} catch (e) {
return e instanceof SyntaxError && blah === arguments;
}
});
assert.sameValue(blah, arguments, 'blah');
}
runTestCase(testcase);
testcase();

View File

@ -4,12 +4,11 @@
/*---
es5id: 11.4.5-2-3-s
description: SyntaxError is not thrown for --arguments[...]
includes: [runTestCase.js]
---*/
function testcase() {
arguments[1] = 7;
--arguments[1];
return arguments[1]===6;
assert.sameValue(arguments[1], 6, 'arguments[1]');
}
runTestCase(testcase);
testcase();

View File

@ -5,16 +5,13 @@
es5id: 11.4.4-2-2-s
description: Strict Mode - SyntaxError is thrown for ++arguments
flags: [onlyStrict]
includes: [runTestCase.js]
---*/
function testcase() {
var blah = arguments;
try {
assert.throws(SyntaxError, function() {
eval("++arguments;");
return false;
} catch (e) {
return e instanceof SyntaxError && blah === arguments;
}
});
assert.sameValue(blah, arguments, 'blah');
}
runTestCase(testcase);
testcase();

View File

@ -4,12 +4,11 @@
/*---
es5id: 11.4.4-2-3-s
description: SyntaxError is not thrown for ++arguments[...]
includes: [runTestCase.js]
---*/
function testcase() {
arguments[1] = 7;
++arguments[1];
return arguments[1]===8;
assert.sameValue(arguments[1], 8, 'arguments[1]');
}
runTestCase(testcase);
testcase();

View File

@ -4,10 +4,6 @@
/*---
es5id: 11.4.7-4-1
description: -"" should be zero
includes: [runTestCase.js]
---*/
function testcase() {
return -"" === 0;
}
runTestCase(testcase);
assert.sameValue(-"", -0, '-""');

View File

@ -4,10 +4,6 @@
/*---
es5id: 11.4.6-2-1
description: +"" should be zero
includes: [runTestCase.js]
---*/
function testcase() {
return +"" === 0;
}
runTestCase(testcase);
assert.sameValue(+"", 0, '+""');