Replace runTestCase with assert helpers [test/language/directive-prologue]

This commit is contained in:
André Bargull 2015-08-13 17:35:04 +02:00
parent 789224fbaa
commit 8447a55e49
47 changed files with 117 additions and 297 deletions

View File

@ -7,12 +7,12 @@ description: >
Strict Mode - Use Strict Directive Prologue is 'use strict';
which contains two space between 'use' and 'strict'
flags: [noStrict]
includes: [runTestCase.js]
---*/
function testcase() {
"use strict";
var public = 1;
return public === 1;
assert.sameValue(public, 1);
}
runTestCase(testcase);
testcase();

View File

@ -7,12 +7,12 @@ description: >
Strict Mode - Use Strict Directive Prologue is ''USE STRICT';' in
which all characters are uppercase
flags: [noStrict]
includes: [runTestCase.js]
---*/
function testcase() {
"USE STRICT";
var public = 1;
return public === 1;
assert.sameValue(public, 1);
}
runTestCase(testcase);
testcase();

View File

@ -7,17 +7,16 @@ description: >
Strict Mode - Eval code is strict code with a Use Strict Directive
at the beginning of the block
flags: [noStrict]
includes: [runTestCase.js]
---*/
function testcase() {
var err = null;
try {
eval("'use strict'; var public = 1; var anotherVariableNotReserveWord = 2;");
return false;
} catch (e) {
return e instanceof SyntaxError && typeof public === "undefined" &&
typeof anotherVariableNotReserveWord === "undefined";
err = e;
}
}
runTestCase(testcase);
assert(err instanceof SyntaxError, 'err instanceof SyntaxError');
assert.sameValue(typeof public, "undefined", 'typeof public');
assert.sameValue(typeof anotherVariableNotReserveWord, "undefined", 'typeof anotherVariableNotReserveWord');

View File

@ -7,11 +7,9 @@ description: >
Strict Mode - Eval code is strict eval code with a Use Strict
Directive in the middle of the block
flags: [noStrict]
includes: [runTestCase.js]
---*/
function testcase() {
eval("var public = 1; 'use strict'; var anotherVariableNotReserveWord = 2;");
return public === 1 && anotherVariableNotReserveWord === 2;
}
runTestCase(testcase);
assert.sameValue(public, 1, 'public');
assert.sameValue(anotherVariableNotReserveWord, 2, 'anotherVariableNotReserveWord');

View File

@ -7,11 +7,9 @@ description: >
Strict Mode - Eval code is strict eval code with a Use Strict
Directive at the end of the block
flags: [noStrict]
includes: [runTestCase.js]
---*/
function testcase() {
eval("var public = 1; var anotherVariableNotReserveWord = 2; 'use strict';");
return public === 1 && anotherVariableNotReserveWord === 2;
}
runTestCase(testcase);
assert.sameValue(public, 1, 'public');
assert.sameValue(anotherVariableNotReserveWord, 2, 'anotherVariableNotReserveWord');

View File

@ -7,16 +7,10 @@ description: >
Strict Mode - The call to eval function is contained in a Strict
Mode block
flags: [noStrict]
includes: [runTestCase.js]
---*/
function testcase() {
assert.throws(SyntaxError, function() {
'use strict';
try {
eval("var public = 1;");
return false;
} catch (e) {
return true;
}
}
runTestCase(testcase);
});

View File

@ -8,20 +8,16 @@ description: >
is strict function code if FunctionDeclaration is contained in use
strict
flags: [noStrict]
includes: [runTestCase.js]
---*/
function testcase() {
"use strict";
function fun() {
try {
eval("var public = 1;");
return false;
} catch (e) {
return e instanceof SyntaxError;
}
eval("var public = 1;");
}
return fun();
assert.throws(SyntaxError, function() {
fun();
});
}
runTestCase(testcase);
testcase();

View File

@ -8,18 +8,13 @@ description: >
is strict function code if FunctionExpression is contained in use
strict
flags: [noStrict]
includes: [runTestCase.js]
---*/
function testcase() {
"use strict";
return function () {
try {
assert.throws(SyntaxError, function() {
eval("var public = 1;");
return false;
} catch (e) {
return e instanceof SyntaxError;
}
} ();
});
}
runTestCase(testcase);
testcase();

View File

@ -8,12 +8,10 @@ description: >
PropertyAssignment is in Strict Mode if Accessor
PropertyAssignment is contained in use strict(getter)
flags: [noStrict]
includes: [runTestCase.js]
---*/
function testcase() {
assert.throws(SyntaxError, function() {
"use strict";
try {
var obj = {};
Object.defineProperty(obj, "accProperty", {
get: function () {
@ -23,9 +21,4 @@ function testcase() {
});
var temp = obj.accProperty === 11;
return false;
} catch (e) {
return e instanceof SyntaxError;
}
}
runTestCase(testcase);
});

View File

@ -8,14 +8,14 @@ description: >
PropertyAssignment is in Strict Mode if Accessor
PropertyAssignment is contained in use strict(setter)
flags: [noStrict]
includes: [runTestCase.js]
---*/
function testcase() {
var data = "data";
assert.throws(SyntaxError, function() {
"use strict";
try {
var obj = {};
var data = "data";
Object.defineProperty(obj, "accProperty", {
set: function (value) {
eval("var public = 1;");
@ -24,9 +24,6 @@ function testcase() {
});
obj.accProperty = "overrideData";
return false;
} catch (e) {
return e instanceof SyntaxError && data === "data";
}
}
runTestCase(testcase);
});
assert.sameValue(data, "data", 'data unchanged');

View File

@ -7,19 +7,14 @@ description: >
Strict Mode - Function code of a FunctionDeclaration contains Use
Strict Directive which appears at the start of the block
flags: [noStrict]
includes: [runTestCase.js]
---*/
function testcase() {
function fun() {
"use strict";
try {
eval("var public = 1;");
return false;
} catch (e) {
return e instanceof SyntaxError;
}
}
return fun();
}
runTestCase(testcase);
assert.throws(SyntaxError, function() {
fun();
});

View File

@ -7,17 +7,10 @@ description: >
Strict Mode - Use Strict Directive Prologue is ''use strict''
which lost the last character ';'
flags: [noStrict]
includes: [runTestCase.js]
---*/
function testcase() {
assert.throws(SyntaxError, function() {
"use strict"
try {
eval("var public = 1;");
return false;
} catch (e) {
return e instanceof SyntaxError;
}
}
runTestCase(testcase);
eval("var public = 1;");
});

View File

@ -7,15 +7,11 @@ description: >
Strict Mode - Function code of a FunctionDeclaration contains Use
Strict Directive which appears in the middle of the block
flags: [noStrict]
includes: [runTestCase.js]
---*/
function testcase() {
function fun() {
eval("var public = 1;");
"use strict";
return public === 1;
assert.sameValue(public, 1);
}
return fun();
}
runTestCase(testcase);
fun();

View File

@ -7,15 +7,10 @@ description: >
Strict Mode - Function code of a FunctionDeclaration contains Use
Strict Directive which appears at the end of the block
flags: [noStrict]
includes: [runTestCase.js]
---*/
function testcase() {
function fun() {
eval("var public = 1;");
return public === 1;
assert.sameValue(public, 1);
"use strict";
}
return fun();
}
runTestCase(testcase);
fun();

View File

@ -7,18 +7,10 @@ description: >
Strict Mode - Function code of a FunctionExpression contains Use
Strict Directive which appears at the start of the block
flags: [noStrict]
includes: [runTestCase.js]
---*/
function testcase() {
return function () {
assert.throws(SyntaxError, function () {
"use strict";
try {
eval("var public = 1;");
return false;
} catch (e) {
return e instanceof SyntaxError;
}
} ();
}
runTestCase(testcase);
});

View File

@ -7,14 +7,10 @@ description: >
Strict Mode - Function code of a FunctionExpression contains Use
Strict Directive which appears in the middle of the block
flags: [noStrict]
includes: [runTestCase.js]
---*/
function testcase() {
return function () {
(function () {
eval("var public = 1;");
return public === 1;
assert.sameValue(public, 1);
"use strict";
} ();
}
runTestCase(testcase);
}) ();

View File

@ -7,14 +7,11 @@ description: >
Strict Mode - Function code of a FunctionExpression contains Use
Strict Directive which appears at the end of the block
flags: [noStrict]
includes: [runTestCase.js]
---*/
function testcase() {
return function () {
(function () {
eval("var public = 1;");
"use strict";
return public === 1;
} ();
}
runTestCase(testcase);
assert.sameValue(public, 1);
}) ();

View File

@ -8,13 +8,12 @@ description: >
contains Use Strict Directive which appears at the start of the
block(setter)
flags: [noStrict]
includes: [runTestCase.js]
---*/
function testcase() {
try {
var data = "data";
assert.throws(SyntaxError, function() {
var obj = {};
var data = "data";
Object.defineProperty(obj, "accProperty", {
set: function (value) {
"use strict";
@ -24,10 +23,6 @@ function testcase() {
});
obj.accProperty = "overrideData";
});
return false;
} catch (e) {
return e instanceof SyntaxError && data === "data";
}
}
runTestCase(testcase);
assert.sameValue(data, "data", 'data unchanged');

View File

@ -8,10 +8,8 @@ description: >
contains Use Strict Directive which appears in the middle of the
block(getter)
flags: [noStrict]
includes: [runTestCase.js]
---*/
function testcase() {
var obj = {};
Object.defineProperty(obj, "accProperty", {
get: function () {
@ -20,6 +18,6 @@ function testcase() {
return 11;
}
});
return obj.accProperty === 11 && public === 1;
}
runTestCase(testcase);
assert.sameValue(obj.accProperty, 11, 'obj.accProperty');
assert.sameValue(public, 1, 'public');

View File

@ -8,10 +8,8 @@ description: >
contains Use Strict Directive which appears at the end of the
block(setter)
flags: [noStrict]
includes: [runTestCase.js]
---*/
function testcase() {
var obj = {};
var data;
@ -23,6 +21,5 @@ function testcase() {
}
});
obj.accProperty = "overrideData";
return data==="overrideData";
}
runTestCase(testcase);
assert.sameValue(data, "overrideData", 'data');

View File

@ -7,13 +7,11 @@ description: >
Strict Mode - The built-in Function constructor is contained in
use strict code
flags: [noStrict]
includes: [runTestCase.js]
---*/
function testcase() {
"use strict";
var funObj = new Function("a", "eval('public = 1;');");
funObj();
return true;
}
runTestCase(testcase);
testcase();

View File

@ -7,13 +7,12 @@ description: >
Strict Mode - Use Strict Directive Prologue is '' use strict';'
which the first character is space
flags: [noStrict]
includes: [runTestCase.js]
---*/
function testcase() {
" use strict";
var public = 1;
return public === 1;
assert.sameValue(public, 1);
}
runTestCase(testcase);
testcase();

View File

@ -8,12 +8,11 @@ description: >
contains Use Strict Directive which appears in the middle of the
block
flags: [noStrict]
includes: [runTestCase.js]
---*/
function testcase() {
var funObj = new Function("a", "eval('public = 1;'); 'use strict'; anotherVariable = 2;");
funObj();
return public === 1 && anotherVariable === 2;
}
runTestCase(testcase);
assert.sameValue(public, 1, 'public');
assert.sameValue(anotherVariable, 2, 'anotherVariable');

View File

@ -7,12 +7,11 @@ description: >
Strict Mode - Function code of built-in Function constructor
contains Use Strict Directive which appears at the end of the block
flags: [noStrict]
includes: [runTestCase.js]
---*/
function testcase() {
var funObj = new Function("a", "eval('public = 1;'); anotherVariable = 2; 'use strict';");
funObj();
return public === 1 && anotherVariable === 2;
}
runTestCase(testcase);
assert.sameValue(public, 1, 'public');
assert.sameValue(anotherVariable, 2, 'anotherVariable');

View File

@ -7,12 +7,12 @@ description: >
Strict Mode - Use Strict Directive Prologue is ''use strict ';'
which the last character is space
flags: [noStrict]
includes: [runTestCase.js]
---*/
function testcase() {
"use strict ";
var public = 1;
return public === 1;
assert.sameValue(public, 1);
}
runTestCase(testcase);
testcase();

View File

@ -7,17 +7,10 @@ description: >
Strict Mode - Use Strict Directive Prologue is ''use strict';'
which appears at the beginning of the block
flags: [noStrict]
includes: [runTestCase.js]
---*/
function testcase() {
assert.throws(SyntaxError, function() {
"use strict";
try {
eval("var public = 1;");
return false;
} catch (e) {
return e instanceof SyntaxError;
}
}
runTestCase(testcase);
eval("var public = 1;");
});

View File

@ -7,13 +7,14 @@ description: >
Strict Mode - Use Strict Directive Prologue is ''use strict';'
which appears in the middle of the block
flags: [noStrict]
includes: [runTestCase.js]
---*/
function testcase() {
var interface = 2;
"use strict";
var public = 1;
return public === 1 && interface === 2;
assert.sameValue(public, 1, 'public');
assert.sameValue(interface, 2, 'interface');
}
runTestCase(testcase);
testcase();

View File

@ -7,12 +7,11 @@ description: >
Strict Mode - Use Strict Directive Prologue is ''use strict';'
which appears at the end of the block
flags: [noStrict]
includes: [runTestCase.js]
---*/
function testcase() {
var public = 1;
return public === 1;
assert.sameValue(public, 1);
"use strict";
}
runTestCase(testcase);
testcase();

View File

@ -7,17 +7,11 @@ description: >
Strict Mode - Use Strict Directive Prologue is ''use strict';'
which appears twice in the directive prologue
flags: [noStrict]
includes: [runTestCase.js]
---*/
function testcase() {
assert.throws(SyntaxError, function() {
"use strict";
"use strict";
try {
eval("var public = 1;");
return false;
} catch (e) {
return e instanceof SyntaxError;
}
}
runTestCase(testcase);
});

View File

@ -7,12 +7,11 @@ description: >
Strict Mode - Use Strict Directive Prologue is ''Use strict';' in
which the first character is uppercase
flags: [noStrict]
includes: [runTestCase.js]
---*/
function testcase() {
"Use strict";
var public = 1;
return public === 1;
assert.sameValue(public, 1);
}
runTestCase(testcase);
testcase();

View File

@ -5,17 +5,12 @@
es5id: 14.1-1-s
description: "'use strict' directive - correct usage"
flags: [noStrict]
includes: [runTestCase.js]
---*/
function testcase() {
function foo()
{
'use strict';
return(this === undefined);
}
return foo.call(undefined);
}
runTestCase(testcase);
assert(foo.call(undefined));

View File

@ -5,11 +5,8 @@
es5id: 14.1-10-s
description: other directives - may follow 'use strict' directive
flags: [noStrict]
includes: [runTestCase.js]
---*/
function testcase() {
function foo()
{
"use strict";
@ -17,6 +14,4 @@ function testcase() {
return (this === undefined);
}
return foo.call(undefined);
}
runTestCase(testcase);
assert(foo.call(undefined));

View File

@ -5,11 +5,8 @@
es5id: 14.1-11-s
description: comments may preceed 'use strict' directive
flags: [noStrict]
includes: [runTestCase.js]
---*/
function testcase() {
function foo()
{
// comment
@ -19,6 +16,4 @@ function testcase() {
}
return foo.call(undefined);
}
runTestCase(testcase);
assert(foo.call(undefined));

View File

@ -5,11 +5,8 @@
es5id: 14.1-12-s
description: comments may follow 'use strict' directive
flags: [noStrict]
includes: [runTestCase.js]
---*/
function testcase() {
function foo()
{
"use strict"; /* comment */ // comment
@ -17,6 +14,4 @@ function testcase() {
return (this === undefined);
}
return foo.call(undefined);
}
runTestCase(testcase);
assert(foo.call(undefined));

View File

@ -5,17 +5,12 @@
es5id: 14.1-13-s
description: semicolon insertion works for'use strict' directive
flags: [noStrict]
includes: [runTestCase.js]
---*/
function testcase() {
function foo()
{
"use strict"
return (this === undefined);
}
return foo.call(undefined);
}
runTestCase(testcase);
assert(foo.call(undefined));

View File

@ -5,11 +5,8 @@
es5id: 14.1-14-s
description: semicolon insertion may come before 'use strict' directive
flags: [noStrict]
includes: [runTestCase.js]
---*/
function testcase() {
function foo()
{
"another directive"
@ -17,6 +14,4 @@ function testcase() {
return (this === undefined);
}
return foo.call(undefined);
}
runTestCase(testcase);
assert(foo.call(undefined));

View File

@ -5,11 +5,8 @@
es5id: 14.1-15-s
description: blank lines may come before 'use strict' directive
flags: [noStrict]
includes: [runTestCase.js]
---*/
function testcase() {
function foo()
{
@ -22,6 +19,4 @@ function testcase() {
return (this === undefined);
}
return foo.call(undefined);
}
runTestCase(testcase);
assert(foo.call(undefined));

View File

@ -7,17 +7,12 @@ description: >
'use strict' directive - not recognized if it follow an empty
statement
flags: [noStrict]
includes: [runTestCase.js]
---*/
function testcase() {
function foo()
{
; 'use strict';
return (this !== undefined);
}
return foo.call(undefined);
}
runTestCase(testcase);
assert(foo.call(undefined));

View File

@ -7,11 +7,8 @@ description: >
'use strict' directive - not recognized if it follow some other
statment empty statement
flags: [noStrict]
includes: [runTestCase.js]
---*/
function testcase() {
function foo()
{
var x;
@ -19,6 +16,4 @@ function testcase() {
return (this !== undefined);
}
return foo.call(undefined);
}
runTestCase(testcase);
assert(foo.call(undefined));

View File

@ -5,17 +5,12 @@
es5id: 14.1-2-s
description: "\"use strict\" directive - correct usage double quotes"
flags: [noStrict]
includes: [runTestCase.js]
---*/
function testcase() {
function foo()
{
"use strict";
return (this === undefined);
}
return foo.call(undefined);
}
runTestCase(testcase);
assert(foo.call(undefined));

View File

@ -7,17 +7,12 @@ description: >
'use strict' directive - not recognized if it contains extra
whitespace
flags: [noStrict]
includes: [runTestCase.js]
---*/
function testcase() {
function foo()
{
' use strict ';
return (this !== undefined);
}
return foo.call(undefined);
}
runTestCase(testcase);
assert(foo.call(undefined));

View File

@ -7,11 +7,8 @@ description: >
'use strict' directive - not recognized if contains Line
Continuation
flags: [noStrict]
includes: [runTestCase.js]
---*/
function testcase() {
function foo()
{
'use str\
@ -19,6 +16,4 @@ ict';
return (this !== undefined);
}
return foo.call(undefined);
}
runTestCase(testcase);
assert(foo.call(undefined));

View File

@ -7,17 +7,12 @@ description: >
'use strict' directive - not recognized if contains a
EscapeSequence
flags: [noStrict]
includes: [runTestCase.js]
---*/
function testcase() {
function foo()
{
'use\u0020strict';
return(this !== undefined);
}
return foo.call(undefined);
}
runTestCase(testcase);
assert(foo.call(undefined));

View File

@ -7,17 +7,12 @@ description: >
'use strict' directive - not recognized if contains a <TAB>
instead of a space
flags: [noStrict]
includes: [runTestCase.js]
---*/
function testcase() {
function foo()
{
'use strict';
return (this !== undefined);
}
return foo.call(undefined);
}
runTestCase(testcase);
assert(foo.call(undefined));

View File

@ -5,17 +5,12 @@
es5id: 14.1-7-s
description: "'use strict' directive - not recognized if upper case"
flags: [noStrict]
includes: [runTestCase.js]
---*/
function testcase() {
function foo()
{
'Use Strict';
return (this !== undefined);
}
return foo.call(undefined);
}
runTestCase(testcase);
assert(foo.call(undefined));

View File

@ -5,11 +5,8 @@
es5id: 14.1-8-s
description: "'use strict' directive - may follow other directives"
flags: [noStrict]
includes: [runTestCase.js]
---*/
function testcase() {
function foo()
{
"bogus directive";
@ -17,6 +14,4 @@ function testcase() {
return (this === undefined);
}
return foo.call(undefined);
}
runTestCase(testcase);
assert(foo.call(undefined));

View File

@ -5,11 +5,8 @@
es5id: 14.1-9-s
description: "'use strict' directive - may occur multiple times"
flags: [noStrict]
includes: [runTestCase.js]
---*/
function testcase() {
function foo()
{
'use strict';
@ -17,6 +14,4 @@ function testcase() {
return (this === undefined);
}
return foo.call(undefined);
}
runTestCase(testcase);
assert(foo.call(undefined));