1// Copyright JS Foundation and other contributors, http://js.foundation 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15function test_parse_error (txt) { 16 try { 17 eval (txt) 18 assert (false) 19 } catch (e){ 20 assert (e instanceof SyntaxError) 21 } 22} 23 24var if1= 25"if (false)() print ('t')" + 26"else print ('f')" 27test_parse_error (if1) 28 29test_parse_error ("if (true)() { print ('t') }") 30test_parse_error ("if {} (true) print ('t')") 31test_parse_error ("if (true false) print ('t')") 32test_parse_error ("if (true && || false) print ('t')") 33test_parse_error ("if (&& true) print ('t')") 34test_parse_error ("if (true ||) print ('t')") 35test_parse_error ("if (true && {false || true}) print ('t')") 36 37var elseif1 = 38"if (false) print ('if statement') " + 39"elseif (false) print ('else if statement') " + 40"else print ('else statement') " 41test_parse_error (elseif1); 42 43var elseif2 = 44"if (false) print ('if statement') " + 45"elif (false) print ('else if statement') " + 46"else print ('else statement') " 47test_parse_error (elseif2) 48 49var elseif3 = 50"if (false) print ('if statement') " + 51"else (false) print ('else if statement') " + 52"else print ('else statement') " 53test_parse_error (elseif3) 54