Refactor increment/decrement tests for parsers (#1786)

The tests for the parsing of postfix increment, postfix decrement,
prefix increment, and prefix decrement were expressed using `eval`.
This made the tests more complex than necessary and also prevented the
tests from providing value to ECMAScript parsers.

Remove the use of `eval` and instead express the expectations with
literal source text.
This commit is contained in:
jugglinmike 2018-09-24 12:29:30 -04:00 committed by Leo Balter
parent b37ba62af6
commit 42ed4291f5
27 changed files with 306 additions and 300 deletions

View File

@ -1,12 +0,0 @@
// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
info: Line Terminator between LeftHandSideExpression and "--" is not allowed
es5id: 11.3.2_A1.1_T1
description: Checking Line Feed
---*/
assert.throws(SyntaxError, function() {
eval("var x = 1; x\u000A--");
});

View File

@ -1,12 +0,0 @@
// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
info: Line Terminator between LeftHandSideExpression and "--" is not allowed
es5id: 11.3.2_A1.1_T3
description: Checking Page separator
---*/
assert.throws(SyntaxError, function() {
eval("var x = 1; x\u2028--");
});

View File

@ -1,38 +0,0 @@
// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
info: White Space between LeftHandSideExpression and "--" are allowed
es5id: 11.3.2_A1.2_T1
description: Checking by using eval
---*/
//CHECK#1
if (eval("var x = 0; x\u0009--; x") !== -1) {
$ERROR('#1: var x = 0; x\\u0009--; x === -1. Actual: ' + (x));
}
//CHECK#2
if (eval("var x = 0; x\u000B--; x") !== -1) {
$ERROR('#2: var x = 0; x\\u000B--; x === -1. Actual: ' + (x));
}
//CHECK#3
if (eval("var x = 0; x\u000C--; x") !== -1) {
$ERROR('#3: var x = 0; x\\u000C--; x === -1. Actual: ' + (x));
}
//CHECK#4
if (eval("var x = 0; x\u0020--; x") !== -1) {
$ERROR('#4: var x = 0; x\\u0020--; x === -1. Actual: ' + (x));
}
//CHECK#5
if (eval("var x = 0; x\u00A0--; x") !== -1) {
$ERROR('#5: var x = 0; x\\u00A0--; x === -1. Actual: ' + (x));
}
//CHECK#6
if (eval("var x = 0; x\u0009\u000B\u000C\u0020\u00A0--; x") !== -1) {
$ERROR('#6: var x = 0; x\\u0009\\u000B\\u000C\\u0020\\u00A0--; x === -1. Actual: ' + (x));
}

View File

@ -3,17 +3,16 @@
/*---
es5id: 11.3.2-2-1-s
esid: sec-postfix-decrement-operator
description: >
Strict Mode - SyntaxError is thrown if the identifier 'arguments'
appear as a PostfixExpression(arguments--)
flags: [onlyStrict]
negative:
phase: parse
type: SyntaxError
---*/
function testcase() {
var blah = arguments;
assert.throws(SyntaxError, function() {
eval("arguments--;");
});
assert.sameValue(blah, arguments, 'blah');
}
testcase();
throw "Test262: This statement should not be evaluated.";
arguments--;

View File

@ -3,14 +3,16 @@
/*---
es5id: 11.3.2-2-2-s
esid: sec-postfix-decrement-operator
description: >
Strict Mode - SyntaxError is thrown if the identifier 'eval'
appear as a PostfixExpression(eval--)
flags: [onlyStrict]
negative:
phase: parse
type: SyntaxError
---*/
var blah = eval;
assert.throws(SyntaxError, function() {
eval("eval--;");
});
assert.sameValue(blah, eval, 'blah');
throw "Test262: This statement should not be evaluated.";
eval--;

View File

@ -4,9 +4,14 @@
/*---
info: Line Terminator between LeftHandSideExpression and "--" is not allowed
es5id: 11.3.2_A1.1_T2
esid: sec-postfix-decrement-operator
description: Checking Carriage Return
negative:
phase: parse
type: SyntaxError
---*/
assert.throws(SyntaxError, function() {
eval("var x = 1; x\u000D--");
});
throw "Test262: This statement should not be evaluated.";
x --;
// The preceding line contains an unprintable CARRIAGE RETURN character (U+000D)

View File

@ -0,0 +1,17 @@
// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
info: Line Terminator (LINE FEED) between LeftHandSideExpression and "--" is not allowed
es5id: 11.3.2_A1.1_T1
esid: sec-postfix-decrement-operator
description: Checking Line Feed
negative:
phase: parse
type: SyntaxError
---*/
throw "Test262: This statement should not be evaluated.";
x
--;

View File

@ -3,10 +3,15 @@
/*---
info: Line Terminator between LeftHandSideExpression and "--" is not allowed
es5id: 11.3.2_A1.1_T4
es5id: 11.3.2_A1.1_T3
esid: sec-postfix-decrement-operator
description: Checking Line separator
negative:
phase: parse
type: SyntaxError
---*/
assert.throws(SyntaxError, function() {
eval("var x = 1; x\u2029--");
});
throw "Test262: This statement should not be evaluated.";
x--;
// The preceding line contains an unprintable LINE SEPARATOR character (U+2028)

View File

@ -0,0 +1,18 @@
// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
info: Line Terminator between LeftHandSideExpression and "--" is not allowed
es5id: 11.3.2_A1.1_T4
esid: sec-postfix-decrement-operator
description: Checking Paragraph separator
negative:
phase: parse
type: SyntaxError
---*/
throw "Test262: This statement should not be evaluated.";
x--;
// The preceding line contains an unprintable PARAGRAPH SEPARATOR character
// (U+2029)

View File

@ -0,0 +1,28 @@
// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: White Space between LeftHandSideExpression and "--" are allowed
es5id: 11.3.2_A1.2_T1
esid: sec-postfix-decrement-operator
---*/
var x = 0;
assert.sameValue(x --, 0, 'U+0009 (expression)');
assert.sameValue(x, -1, 'U+0009 (side effect)');
assert.sameValue(x --, -1, 'U+000B (expression)');
assert.sameValue(x, -2, 'U+000B (side effect)');
assert.sameValue(x --, -2, 'U+000C (expression)');
assert.sameValue(x, -3, 'U+000C (side effect)');
assert.sameValue(x --, -3, 'U+0020 (expression)');
assert.sameValue(x, -4, 'U+0020 (side effect)');
assert.sameValue(x --, -4, 'U+00A0 (expression)');
assert.sameValue(x, -5, 'U+00A0 (side effect)');
assert.sameValue(x  --, -5, 'U+0009U+000BU+000CU+0020U+00A0 (expression)');
assert.sameValue(x, -6, 'U+0009U+000BU+000CU+0020U+00A0 (side effect)');

View File

@ -1,12 +0,0 @@
// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
info: Line Terminator between LeftHandSideExpression and "++" is not allowed
es5id: 11.3.1_A1.1_T3
description: Checking Line Seprator
---*/
assert.throws(SyntaxError, function() {
eval("var x = 1; x\u2028++");
});

View File

@ -1,38 +0,0 @@
// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
info: White Space between LeftHandSideExpression and "++" are allowed
es5id: 11.3.1_A1.2_T1
description: Checking by using eval
---*/
//CHECK#1
if (eval("var x = 0; x\u0009++; x") !== 1) {
$ERROR('#1: var x = 0; x\\u0009++; x === 1. Actual: ' + (x));
}
//CHECK#2
if (eval("var x = 0; x\u000B++; x") !== 1) {
$ERROR('#2: var x = 0; x\\u000B++; x === 1. Actual: ' + (x));
}
//CHECK#3
if (eval("var x = 0; x\u000C++; x") !== 1) {
$ERROR('#3: var x = 0; x\\u000C++; x === 1. Actual: ' + (x));
}
//CHECK#4
if (eval("var x = 0; x\u0020++; x") !== 1) {
$ERROR('#4: var x = 0; x\\u0020++; x === 1. Actual: ' + (x));
}
//CHECK#5
if (eval("var x = 0; x\u00A0++; x") !== 1) {
$ERROR('#5: var x = 0; x\\u00A0++; x === 1. Actual: ' + (x));
}
//CHECK#6
if (eval("var x = 0; x\u0009\u000B\u000C\u0020\u00A0++; x") !== 1) {
$ERROR('#6: var x = 0; x\\u0009\\u000B\\u000C\\u0020\\u00A0++; x === 1. Actual: ' + (x));
}

View File

@ -3,17 +3,16 @@
/*---
es5id: 11.3.1-2-1-s
esid: postfix-increment-operator
description: >
Strict Mode - SyntaxError is thrown if the identifier 'arguments'
appear as a PostfixExpression(arguments++)
flags: [onlyStrict]
negative:
phase: parse
type: SyntaxError
---*/
function testcase() {
var blah = arguments;
assert.throws(SyntaxError, function() {
eval("arguments++;");
});
assert.sameValue(blah, arguments, 'blah');
}
testcase();
throw "Test262: This statement should not be evaluated.";
arguments++;

View File

@ -3,14 +3,16 @@
/*---
es5id: 11.3.1-2-2-s
esid: postfix-increment-operator
description: >
Strict Mode - SyntaxError is thrown if the identifier 'eval'
appear as a PostfixExpression(eval++)
flags: [onlyStrict]
negative:
phase: parse
type: SyntaxError
---*/
var blah = eval;
assert.throws(SyntaxError, function() {
eval("eval++;");
});
assert.sameValue(blah, eval, 'blah');
throw "Test262: This statement should not be evaluated.";
eval++;

View File

@ -4,9 +4,14 @@
/*---
info: Line Terminator between LeftHandSideExpression and "++" is not allowed
es5id: 11.3.1_A1.1_T2
esid: postfix-increment-operator
description: Carriage Return
negative:
phase: parse
type: SyntaxError
---*/
assert.throws(SyntaxError, function() {
eval("var x = 1; x\u000D++");
});
throw "Test262: This statement should not be evaluated.";
x ++;
// The preceding line contains an unprintable CARRIAGE RETURN character (U+000D)

View File

@ -4,9 +4,14 @@
/*---
info: Line Terminator between LeftHandSideExpression and "++" is not allowed
es5id: 11.3.1_A1.1_T1
esid: postfix-increment-operator
description: Checking Line Feed
negative:
phase: parse
type: SyntaxError
---*/
assert.throws(SyntaxError, function() {
eval("var x = 1; x\u000A++");
});
throw "Test262: This statement should not be evaluated.";
x
++;

View File

@ -0,0 +1,17 @@
// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
info: Line Terminator between LeftHandSideExpression and "++" is not allowed
es5id: 11.3.1_A1.1_T3
esid: postfix-increment-operator
description: Checking Line Separator
negative:
phase: parse
type: SyntaxError
---*/
throw "Test262: This statement should not be evaluated.";
x++;
// The preceding line contains an unprintable LINE SEPARATOR character (U+2028)

View File

@ -4,9 +4,15 @@
/*---
info: Line Terminator between LeftHandSideExpression and "++" is not allowed
es5id: 11.3.1_A1.1_T4
esid: postfix-increment-operator
description: Checking Paragraph separator
negative:
phase: parse
type: SyntaxError
---*/
assert.throws(SyntaxError, function() {
eval("var x = 1; x\u2029++");
});
throw "Test262: This statement should not be evaluated.";
x++;
// The preceding line contains an unprintable PARAGRAPH SEPARATOR character
// (U+2029)

View File

@ -0,0 +1,28 @@
// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: White Space between LeftHandSideExpression and "++" are allowed
es5id: 11.3.1_A1.2_T1
esid: postfix-increment-operator
---*/
var x = 0;
assert.sameValue(x ++, 0, 'U+0009 (expression)');
assert.sameValue(x, 1, 'U+0009 (side effect)');
assert.sameValue(x ++, 1, 'U+000B (expression)');
assert.sameValue(x, 2, 'U+000B (side effect)');
assert.sameValue(x ++, 2, 'U+000C (expression)');
assert.sameValue(x, 3, 'U+000C (side effect)');
assert.sameValue(x ++, 3, 'U+0020 (expression)');
assert.sameValue(x, 4, 'U+0020 (side effect)');
assert.sameValue(x ++, 4, 'U+00A0 (expression)');
assert.sameValue(x, 5, 'U+00A0 (side effect)');
assert.sameValue(x  ++, 5, 'U+0009U+000BU+000CU+0020U+00A0 (expression)');
assert.sameValue(x, 6, 'U+0009U+000BU+000CU+0020U+00A0 (side effect)');

View File

@ -1,60 +0,0 @@
// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
info: |
White Space and Line Terminator between "--" and UnaryExpression are
allowed
es5id: 11.4.5_A1
description: Checking by using eval
---*/
//CHECK#1
if (eval("var x = 1; --\u0009x") !== 0) {
$ERROR('#1: var x = 1; --\\u0009x; x === 0. Actual: ' + (x));
}
//CHECK#2
if (eval("var x = 1; --\u000Bx") !== 0) {
$ERROR('#2: var x = 1; --\\u000Bx; x === 0. Actual: ' + (x));
}
//CHECK#3
if (eval("var x = 1; --\u000Cx") !== 0) {
$ERROR('#3: var x = 1; --\\u000Cx; x === 0. Actual: ' + (x));
}
//CHECK#4
if (eval("var x = 1; --\u0020x") !== 0) {
$ERROR('#4: var x = 1; --\\u0020x; x === 0. Actual: ' + (x));
}
//CHECK#5
if (eval("var x = 1; --\u00A0x") !== 0) {
$ERROR('#5: var x = 1; --\\u00A0x; x === 0. Actual: ' + (x));
}
//CHECK#6
if (eval("var x = 1; --\u000Ax") !== 0) {
$ERROR('#6: var x = 1; --\\u000Ax; x === 0. Actual: ' + (x));
}
//CHECK#7
if (eval("var x = 1; --\u000Dx") !== 0) {
$ERROR('#7: var x = 1; --\\u000Dx; x === 0. Actual: ' + (x));
}
//CHECK#8
if (eval("var x = 1; --\u2028x") !== 0) {
$ERROR('#8: var x = 1; --\\u2028x; x === 0. Actual: ' + (x));
}
//CHECK#9
if (eval("var x = 1; --\u2029x") !== 0) {
$ERROR('#9: var x = 1; --\\u2029x; x === 0. Actual: ' + (x));
}
//CHECK#10
if (eval("var x = 1; --\u0009\u000B\u000C\u0020\u00A0\u000A\u000D\u2028\u2029x") !== 0) {
$ERROR('#10: var x = 1; --\\u0009\\u000B\\u000C\\u0020\\u00A0\\u000A\\u000D\\u2028\\u2029x; x === 0. Actual: ' + (x));
}

View File

@ -3,15 +3,14 @@
/*---
es5id: 11.4.5-2-2-s
esid: sec-prefix-decrement-operator
description: Strict Mode - SyntaxError is thrown for --arguments
flags: [onlyStrict]
negative:
phase: parse
type: SyntaxError
---*/
function testcase() {
var blah = arguments;
assert.throws(SyntaxError, function() {
eval("--arguments;");
});
assert.sameValue(blah, arguments, 'blah');
}
testcase();
throw "Test262: This statement should not be evaluated.";
--arguments;

View File

@ -3,12 +3,14 @@
/*---
es5id: 11.4.5-2-1-s
esid: sec-prefix-decrement-operator
description: Strict Mode - SyntaxError is thrown for --eval
flags: [onlyStrict]
negative:
phase: parse
type: SyntaxError
---*/
var blah = eval;
assert.throws(SyntaxError, function() {
eval("--eval;");
});
assert.sameValue(blah, eval, 'blah');
throw "Test262: This statement should not be evaluated.";
--eval;

View File

@ -0,0 +1,50 @@
// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: |
White Space and Line Terminator between "--" and UnaryExpression are
allowed
es5id: 11.4.5_A1
esid: sec-prefix-decrement-operator
---*/
var x = 0;
assert.sameValue(-- x, -1, 'U+0009 (expression)');
assert.sameValue(x, -1, 'U+0009 (side effect)');
assert.sameValue(-- x, -2, 'U+000B (expression)');
assert.sameValue(x, -2, 'U+000B (side effect)');
assert.sameValue(-- x, -3, 'U+000C (expression)');
assert.sameValue(x, -3, 'U+000C (side effect)');
assert.sameValue(-- x, -4, 'U+0020 (expression)');
assert.sameValue(x, -4, 'U+0020 (side effect)');
assert.sameValue(-- x, -5, 'U+00A0 (expression)');
assert.sameValue(x, -5, 'U+00A0 (side effect)');
assert.sameValue(--
x, -6, 'U+000A (expression)');
assert.sameValue(x, -6, 'U+000A (side effect)');
assert.sameValue(-- x, -7, 'U+000D (expression)');
assert.sameValue(x, -7, 'U+000D (side effect)');
assert.sameValue(--x, -8, 'U+2028 (expression)');
assert.sameValue(x, -8, 'U+2028 (side effect)');
assert.sameValue(--x, -9, 'U+2029 (expression)');
assert.sameValue(x, -9, 'U+2029 (side effect)');
assert.sameValue(
--  
x,
-10,
'U+0009U+000BU+000CU+0020U+00A0U+000AU+000DU+2028U+2029 (expression)'
);
assert.sameValue(
x, -10, 'U+0009U+000BU+000CU+0020U+00A0U+000AU+000DU+2028U+2029 (side effect)'
);

View File

@ -1,60 +0,0 @@
// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
info: |
White Space and Line Terminator between "++" and UnaryExpression are
allowed
es5id: 11.4.4_A1
description: Checking by using eval
---*/
//CHECK#1
if (eval("var x = 0; ++\u0009x") !== 1) {
$ERROR('#1: var x = 0; ++\\u0009x; x === 1. Actual: ' + (x));
}
//CHECK#2
if (eval("var x = 0; ++\u000Bx") !== 1) {
$ERROR('#2: var x = 0; ++\\u000Bx; x === 1. Actual: ' + (x));
}
//CHECK#3
if (eval("var x = 0; ++\u000Cx") !== 1) {
$ERROR('#3: var x = 0; ++\\u000Cx; x === 1. Actual: ' + (x));
}
//CHECK#4
if (eval("var x = 0; ++\u0020x") !== 1) {
$ERROR('#4: var x = 0; ++\\u0020x; x === 1. Actual: ' + (x));
}
//CHECK#5
if (eval("var x = 0; ++\u00A0x") !== 1) {
$ERROR('#5: var x = 0; ++\\u00A0x; x === 1. Actual: ' + (x));
}
//CHECK#6
if (eval("var x = 0; ++\u000Ax") !== 1) {
$ERROR('#6: var x = 0; ++\\u000Ax; x === 1. Actual: ' + (x));
}
//CHECK#7
if (eval("var x = 0; ++\u000Dx") !== 1) {
$ERROR('#7: var x = 0; ++\\u000Dx; x === 1. Actual: ' + (x));
}
//CHECK#8
if (eval("var x = 0; ++\u2028x") !== 1) {
$ERROR('#8: var x = 0; ++\\u2028x; x === 1. Actual: ' + (x));
}
//CHECK#9
if (eval("var x = 0; ++\u2029x") !== 1) {
$ERROR('#9: var x = 0; ++\\u2029x; x === 1. Actual: ' + (x));
}
//CHECK#10
if (eval("var x = 0; ++\u0009\u000B\u000C\u0020\u00A0\u000A\u000D\u2028\u2029x") !== 1) {
$ERROR('#10: var x = 0; ++\\u0009\\u000B\\u000C\\u0020\\u00A0\\u000A\\u000D\\u2028\\u2029x; x === 1. Actual: ' + (x));
}

View File

@ -3,15 +3,14 @@
/*---
es5id: 11.4.4-2-2-s
esid: sec-prefix-increment-operator
description: Strict Mode - SyntaxError is thrown for ++arguments
flags: [onlyStrict]
negative:
phase: parse
type: SyntaxError
---*/
function testcase() {
var blah = arguments;
assert.throws(SyntaxError, function() {
eval("++arguments;");
});
assert.sameValue(blah, arguments, 'blah');
}
testcase();
throw "Test262: This statement should not be evaluated.";
++arguments;

View File

@ -3,12 +3,14 @@
/*---
es5id: 11.4.4-2-1-s
esid: sec-prefix-increment-operator
description: Strict Mode - SyntaxError is thrown for ++eval
flags: [onlyStrict]
negative:
phase: parse
type: SyntaxError
---*/
var blah = eval;
assert.throws(SyntaxError, function() {
eval("++eval;");
});
assert.sameValue(blah, eval, 'blah');
throw "Test262: This statement should not be evaluated.";
++eval;

View File

@ -0,0 +1,50 @@
// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: |
White Space and Line Terminator between "++" and UnaryExpression are
allowed
es5id: 11.4.4_A1
esid: sec-prefix-increment-operator
---*/
var x = 0;
assert.sameValue(++ x, 1, 'U+0009 (expression)');
assert.sameValue(x, 1, 'U+0009 (side effect)');
assert.sameValue(++ x, 2, 'U+000B (expression)');
assert.sameValue(x, 2, 'U+000B (side effect)');
assert.sameValue(++ x, 3, 'U+000C (expression)');
assert.sameValue(x, 3, 'U+000C (side effect)');
assert.sameValue(++ x, 4, 'U+0020 (expression)');
assert.sameValue(x, 4, 'U+0020 (side effect)');
assert.sameValue(++ x, 5, 'U+00A0 (expression)');
assert.sameValue(x, 5, 'U+00A0 (side effect)');
assert.sameValue(++
x, 6, 'U+000A (expression)');
assert.sameValue(x, 6, 'U+000A (side effect)');
assert.sameValue(++ x, 7, 'U+000D (expression)');
assert.sameValue(x, 7, 'U+000D (side effect)');
assert.sameValue(++x, 8, 'U+2028 (expression)');
assert.sameValue(x, 8, 'U+2028 (side effect)');
assert.sameValue(++x, 9, 'U+2029 (expression)');
assert.sameValue(x, 9, 'U+2029 (side effect)');
assert.sameValue(
++  
x,
10,
'U+0009U+000BU+000CU+0020U+00A0U+000AU+000DU+2028U+2029 (expression)'
);
assert.sameValue(
x, 10, 'U+0009U+000BU+000CU+0020U+00A0U+000AU+000DU+2028U+2029 (side effect)'
);