From aa4c533d2827435325e1a5f127a0682f75fe4ea6 Mon Sep 17 00:00:00 2001 From: Mike Pennisi Date: Sun, 31 Mar 2019 21:08:35 -0400 Subject: [PATCH] Refactor misc. statement tests for parsers The tests for the parsing of various statement 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. Rename the files to make each test's purpose more clear. --- test/language/statements/block/12.1-1.js | 8 ++- test/language/statements/block/12.1-2.js | 8 ++- test/language/statements/block/12.1-3.js | 8 ++- test/language/statements/block/12.1-4.js | 8 ++- test/language/statements/block/12.1-5.js | 8 ++- test/language/statements/block/12.1-6.js | 8 ++- test/language/statements/block/12.1-7.js | 8 ++- test/language/statements/break/S12.8_A2.js | 66 ------------------- .../statements/break/line-terminators.js | 45 +++++++++++++ test/language/statements/continue/S12.7_A2.js | 66 ------------------- .../statements/continue/line-terminators.js | 44 +++++++++++++ test/language/statements/return/S12.9_A2.js | 57 ---------------- .../statements/return/line-terminators.js | 36 ++++++++++ 13 files changed, 160 insertions(+), 210 deletions(-) delete mode 100644 test/language/statements/break/S12.8_A2.js create mode 100644 test/language/statements/break/line-terminators.js delete mode 100644 test/language/statements/continue/S12.7_A2.js create mode 100644 test/language/statements/continue/line-terminators.js delete mode 100644 test/language/statements/return/S12.9_A2.js create mode 100644 test/language/statements/return/line-terminators.js diff --git a/test/language/statements/block/12.1-1.js b/test/language/statements/block/12.1-1.js index 0f1ddd0237..d5f0106ca7 100644 --- a/test/language/statements/block/12.1-1.js +++ b/test/language/statements/block/12.1-1.js @@ -4,9 +4,11 @@ /*--- es5id: 12.1-1 description: "12.1 - block '{ StatementListopt };' is not allowed: try-catch" +negative: + phase: parse + type: SyntaxError ---*/ +$DONOTEVALUATE(); -assert.throws(SyntaxError, function() { - eval("try{};catch(){}"); -}); +try{};catch(){} diff --git a/test/language/statements/block/12.1-2.js b/test/language/statements/block/12.1-2.js index b0b41000c4..da123633b6 100644 --- a/test/language/statements/block/12.1-2.js +++ b/test/language/statements/block/12.1-2.js @@ -6,9 +6,11 @@ es5id: 12.1-2 description: > 12.1 - block '{ StatementListopt };' is not allowed: try-catch-finally +negative: + phase: parse + type: SyntaxError ---*/ +$DONOTEVALUATE(); -assert.throws(SyntaxError, function() { - eval("try{};catch{};finally{}"); -}); +try{};catch{};finally{} diff --git a/test/language/statements/block/12.1-3.js b/test/language/statements/block/12.1-3.js index a7fb97e72e..64e836759c 100644 --- a/test/language/statements/block/12.1-3.js +++ b/test/language/statements/block/12.1-3.js @@ -4,9 +4,11 @@ /*--- es5id: 12.1-3 description: "12.1 - block '{ StatementListopt };' is not allowed: try-finally" +negative: + phase: parse + type: SyntaxError ---*/ +$DONOTEVALUATE(); -assert.throws(SyntaxError, function() { - eval("try{};finally{}"); -}); +try{};finally{} diff --git a/test/language/statements/block/12.1-4.js b/test/language/statements/block/12.1-4.js index bf130e4594..eb7edd744f 100644 --- a/test/language/statements/block/12.1-4.js +++ b/test/language/statements/block/12.1-4.js @@ -4,9 +4,11 @@ /*--- es5id: 12.1-4 description: "12.1 - block '{ StatementListopt };' is not allowed: if-else" +negative: + phase: parse + type: SyntaxError ---*/ +$DONOTEVALUATE(); -assert.throws(SyntaxError, function() { - eval("if{};else{}"); -}); +if{};else{} diff --git a/test/language/statements/block/12.1-5.js b/test/language/statements/block/12.1-5.js index 2ac6f46085..4dd7ff5ac1 100644 --- a/test/language/statements/block/12.1-5.js +++ b/test/language/statements/block/12.1-5.js @@ -4,9 +4,11 @@ /*--- es5id: 12.1-5 description: "12.1 - block '{ StatementListopt };' is not allowed: if-else-if" +negative: + phase: parse + type: SyntaxError ---*/ +$DONOTEVALUATE(); -assert.throws(SyntaxError, function() { - eval("if{};else if{}"); -}); +if{};else if{} diff --git a/test/language/statements/block/12.1-6.js b/test/language/statements/block/12.1-6.js index deeffa1710..ef60e90e8f 100644 --- a/test/language/statements/block/12.1-6.js +++ b/test/language/statements/block/12.1-6.js @@ -6,9 +6,11 @@ es5id: 12.1-6 description: > 12.1 - block '{ StatementListopt };' is not allowed: if-else-if-else +negative: + phase: parse + type: SyntaxError ---*/ +$DONOTEVALUATE(); -assert.throws(SyntaxError, function() { - eval("if{};else if{};else{}"); -}); +if{};else if{};else{} diff --git a/test/language/statements/block/12.1-7.js b/test/language/statements/block/12.1-7.js index ee5c6acdfc..345cfd89b2 100644 --- a/test/language/statements/block/12.1-7.js +++ b/test/language/statements/block/12.1-7.js @@ -4,9 +4,11 @@ /*--- es5id: 12.1-7 description: "12.1 - block '{ StatementListopt };' is not allowed: do-while" +negative: + phase: parse + type: SyntaxError ---*/ +$DONOTEVALUATE(); -assert.throws(SyntaxError, function() { - eval("do{};while()"); -}); +do{};while() diff --git a/test/language/statements/break/S12.8_A2.js b/test/language/statements/break/S12.8_A2.js deleted file mode 100644 index 0d1bc5ef3b..0000000000 --- a/test/language/statements/break/S12.8_A2.js +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright 2009 the Sputnik authors. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -info: | - Since LineTerminator between "break" and Identifier is not allowed, - "break" is evaluated without label -es5id: 12.8_A2 -description: > - Checking by using eval, inserting LineTerminator between break and - Identifier ----*/ - -var result; - -////////////////////////////////////////////////////////////////////////////// -//CHECK#1 -try{ - eval("FOR1 : for(var i=1;i<2;i++){ LABEL1 : do {var x =1;break\u000AFOR1;var y=2;} while(0);} result = i;"); - if (result!==2) { - $ERROR('#1: Since LineTerminator(U-000A) between break and Identifier not allowed break evaluates without label'); - } -} catch(e){ - $ERROR('#1.1: eval("FOR1 : for(var i=1;i<2;i++){ LABEL1 : do {var x =1;break\\u000AFOR1;var y=2;} while(0);}") does not lead to throwing exception'); -} -// -////////////////////////////////////////////////////////////////////////////// - -////////////////////////////////////////////////////////////////////////////// -//CHECK#2 -try{ - eval("FOR2 : for(var i=1;i<2;i++){ LABEL2 : do {var x =1;break\u000DFOR2;var y=2;} while(0);} result = i;"); - if (result!==2) { - $ERROR('#2: Since LineTerminator(U-000D) between break and Identifier not allowed break evaluates without label'); - } -} catch(e){ - $ERROR('#2.1: eval("FOR2 : for(var i=1;i<2;i++){ LABEL2 : do {var x =1;break\\u000DFOR2;var y=2;} while(0);}") does not lead to throwing exception'); -} -// -////////////////////////////////////////////////////////////////////////////// - -////////////////////////////////////////////////////////////////////////////// -//CHECK#3 -try{ - eval("FOR3 : for(var i=1;i<2;i++){ LABEL3 : do {var x =1;break\u2028FOR3;var y=2;} while(0);} result = i;"); - if (result!==2) { - $ERROR('#3: Since LineTerminator(U-2028) between break and Identifier not allowed break evaluates without label'); - } -} catch(e){ - $ERROR('#3.1: eval("FOR3 : for(var i=1;i<2;i++){ LABEL3 : do {var x =1;break\\u2028FOR3;var y=2;} while(0);}") does not lead to throwing exception'); -} -// -////////////////////////////////////////////////////////////////////////////// - -////////////////////////////////////////////////////////////////////////////// -//CHECK#4 -try{ - eval("FOR4 : for(var i=1;i<2;i++){ LABEL4 : do {var x =1;break\u2029FOR4;var y=2;} while(0);} result = i;"); - if (result!==2) { - $ERROR('#4: Since LineTerminator(U-2029) between break and Identifier not allowed break evaluates without label'); - } -} catch(e){ - $ERROR('#4.1: eval("FOR4 : for(var i=1;i<2;i++){ LABEL4 : do {var x =1;break\\u2029FOR4;var y=2;} while(0);}") does not lead to throwing exception'); -} -// -////////////////////////////////////////////////////////////////////////////// diff --git a/test/language/statements/break/line-terminators.js b/test/language/statements/break/line-terminators.js new file mode 100644 index 0000000000..5b534778c5 --- /dev/null +++ b/test/language/statements/break/line-terminators.js @@ -0,0 +1,45 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + Since LineTerminator between "break" and Identifier is not allowed, + "break" is evaluated without label +es5id: 12.8_A2 +description: > + Checking by using eval, inserting LineTerminator between break and + Identifier +---*/ + +FOR1 : for(var i=1;i<2;i++){ + LABEL1 : do { + break +FOR1; + } while(0); +} + +assert.sameValue(i, 2, '#1: Since LineTerminator(U-000A) between break and Identifier not allowed break evaluates without label'); + +FOR2 : for(var i=1;i<2;i++){ + LABEL2 : do { + break FOR2; + } while(0); +} + +assert.sameValue(i, 2, '#2: Since LineTerminator(U-000D) between break and Identifier not allowed break evaluates without label'); + +FOR3 : for(var i=1;i<2;i++){ + LABEL3 : do { + break
FOR3; + } while(0); +} + +assert.sameValue(i, 2, '#3: Since LineTerminator(U-2028) between break and Identifier not allowed break evaluates without label'); + +FOR4 : for(var i=1;i<2;i++){ + LABEL4 : do { + break
FOR4; + } while(0); +} + +assert.sameValue(i, 2, '#4: Since LineTerminator(U-2029) between break and Identifier not allowed break evaluates without label'); diff --git a/test/language/statements/continue/S12.7_A2.js b/test/language/statements/continue/S12.7_A2.js deleted file mode 100644 index 7cefe290ab..0000000000 --- a/test/language/statements/continue/S12.7_A2.js +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright 2009 the Sputnik authors. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -info: | - Since LineTerminator between "continue" and Identifier is not allowed, - "continue" is evaluated without label -es5id: 12.7_A2 -description: > - Checking by using eval, inserting LineTerminator between continue - and Identifier ----*/ - -var result; - -////////////////////////////////////////////////////////////////////////////// -//CHECK#1 -try{ - eval("FOR1 : for(var i=1;i<2;i++){FOR1NESTED : for(var j=1;j<2;j++) { continue\u000AFOR1; } while(0);} result = j;"); - if (result!==2) { - $ERROR('#1: Since LineTerminator(U-000A) between continue and Identifier not allowed continue evaluates without label'); - } -} catch(e){ - $ERROR('#1.1: eval("FOR1 : for(var i=1;i<2;i++){FOR1NESTED : for(var j=1;j<2;j++) { continue\\u000AFOR1; } while(0);}") does not lead to throwing exception'); -} -// -////////////////////////////////////////////////////////////////////////////// - -////////////////////////////////////////////////////////////////////////////// -//CHECK#2 -try{ - eval("FOR2 : for(var i=1;i<2;i++){FOR2NESTED : for(var j=1;j<2;j++) { continue\u000DFOR2; } while(0);} result = j;"); - if (result!==2) { - $ERROR('#2: Since LineTerminator(U-000D) between continue and Identifier not allowed continue evaluates without label'); - } -} catch(e){ - $ERROR('#2.1: eval("FOR2 : for(var i=1;i<2;i++){FOR2NESTED : for(var j=1;j<2;j++) { continue\\u000DFOR2; } while(0);}") does not lead to throwing exception'); -} -// -////////////////////////////////////////////////////////////////////////////// - -////////////////////////////////////////////////////////////////////////////// -//CHECK#3 -try{ - eval("FOR3 : for(var i=1;i<2;i++){FOR3NESTED : for(var j=1;j<2;j++) { continue\u2028FOR3; } while(0);} result = j;"); - if (result!==2) { - $ERROR('#3: Since LineTerminator(U-2028) between continue and Identifier not allowed continue evaluates without label'); - } -} catch(e){ - $ERROR('#3.1: eval("FOR3 : for(var i=1;i<2;i++){FOR3NESTED : for(var j=1;j<2;j++) { continue\\u2028FOR3; } while(0);}") does not lead to throwing exception'); -} -// -////////////////////////////////////////////////////////////////////////////// - -////////////////////////////////////////////////////////////////////////////// -//CHECK#4 -try{ - eval("FOR4 : for(var i=1;i<2;i++){FOR4NESTED : for(var j=1;j<2;j++) { continue\u2029FOR4; } while(0);} result = j;"); - if (result!==2) { - $ERROR('#4: Since LineTerminator(U-2029) between continue and Identifier not allowed continue evaluates without label'); - } -} catch(e){ - $ERROR('#4.1: eval("FOR4 : for(var i=1;i<2;i++){FOR4NESTED : for(var j=1;j<2;j++) { continue\\u2029FOR4; } while(0);}"); does not lead to throwing exception'); -} -// -////////////////////////////////////////////////////////////////////////////// diff --git a/test/language/statements/continue/line-terminators.js b/test/language/statements/continue/line-terminators.js new file mode 100644 index 0000000000..f3fb86f6fd --- /dev/null +++ b/test/language/statements/continue/line-terminators.js @@ -0,0 +1,44 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + Since LineTerminator between "continue" and Identifier is not allowed, + "continue" is evaluated without label +es5id: 12.7_A2 +description: > + Checking by using eval, inserting LineTerminator between continue + and Identifier +---*/ + +FOR1 : for(var i=1;i<2;i++){ + FOR1NESTED : for(var j=1;j<2;j++) { + continue +FOR1; + } while(0); +} + +assert.sameValue(j, 2, '#1: Since LineTerminator(U-000A) between continue and Identifier not allowed continue evaluates without label'); + +FOR2 : for(var i=1;i<2;i++){ + FOR2NESTED : for(var j=1;j<2;j++) { + continue FOR2; + } while(0); +} + +assert.sameValue(j, 2, '#2: Since LineTerminator(U-000D) between continue and Identifier not allowed continue evaluates without label'); + +FOR3 : for(var i=1;i<2;i++){ + FOR3NESTED : for(var j=1;j<2;j++) { + continue
FOR3; + } while(0); +} +assert.sameValue(j, 2, '#3: Since LineTerminator(U-2028) between continue and Identifier not allowed continue evaluates without label'); + +FOR4 : for(var i=1;i<2;i++){ + FOR4NESTED : for(var j=1;j<2;j++) { + continue
FOR4; + } while(0); +} + +assert.sameValue(j, 2, '#4: Since LineTerminator(U-2029) between continue and Identifier not allowed continue evaluates without label'); diff --git a/test/language/statements/return/S12.9_A2.js b/test/language/statements/return/S12.9_A2.js deleted file mode 100644 index 64b73fd6dc..0000000000 --- a/test/language/statements/return/S12.9_A2.js +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright 2009 the Sputnik authors. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -info: | - LineTerminator between return and Identifier_opt yields return without - Identifier_opt -es5id: 12.9_A2 -description: > - Checking by using eval, inserting LineTerminator between return - and Variable ----*/ - -//CHECK#1 -try{ - if (eval("(function(){var x = 1;return\u000Ax;var y=2;})()") !== undefined) { - $ERROR("#1: LineTerminator(U-000A) between return and Identifier_opt yields return without Identifier_opt"); - } -} catch(e){ - $ERROR('#1: eval("(function(){var x = 1;return\\u000Ax;var y=2;})()") does not lead to throwing exception'); -} - - - - -//CHECK#2 -try{ - if (eval("(function(){var x = 1;return\u000Dx;var y=2;})()") !== undefined) { - $ERROR("#1: LineTerminator(U-000D) between return and Identifier_opt yields return without Identifier_opt"); - } -} catch(e){ - $ERROR('#2: eval("(function(){var x = 1;return\\u000Dx;var y=2;})()") does not lead to throwing exception'); -} - - - - -//CHECK#3 -try{ - if (eval("(function(){var x = 1;return\u2028x;var y=2;})()") !== undefined) { - $ERROR("#1: LineTerminator(U-2028) between return and Identifier_opt yields return without Identifier_opt"); - } -} catch(e){ - $ERROR('#3: eval("(function(){var x = 1;return\\u2028x;var y=2;})()") does not lead to throwing exception'); -} - - - - -//CHECK#4 -try{ - if (eval("(function(){var x =1;return\u2029x;var y=2;})()") !== undefined) { - $ERROR("#1: LineTerminator(U-2029) between return and Identifier_opt yields return without Identifier_opt"); - } -} catch(e){ - $ERROR('#4: eval("(function(){var x =1;return\\u2029x;var y=2;})()") does not lead to throwing exception'); -} diff --git a/test/language/statements/return/line-terminators.js b/test/language/statements/return/line-terminators.js new file mode 100644 index 0000000000..640f859397 --- /dev/null +++ b/test/language/statements/return/line-terminators.js @@ -0,0 +1,36 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + LineTerminator between return and Identifier_opt yields return without + Identifier_opt +es5id: 12.9_A2 +description: Inserting LineTerminator between return and Variable +---*/ + +assert.sameValue( + function(){ return +1; }(), + undefined, + "#1: LineTerminator(U-000A) between return and Identifier_opt yields return without Identifier_opt" +); + +assert.sameValue( + function(){ return 1; }(), + undefined, + "#1: LineTerminator(U-000D) between return and Identifier_opt yields return without Identifier_opt" +); + + +assert.sameValue( + function(){ return
1; }(), + undefined, + "#1: LineTerminator(U-2028) between return and Identifier_opt yields return without Identifier_opt" +); + +assert.sameValue( + function(){ return
1; }(), + undefined, + "#1: LineTerminator(U-2029) between return and Identifier_opt yields return without Identifier_opt" +);