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 */ 15 16 #include "jerryscript.h" 17 #include "test-common.h" 18 19 static bool test_syntax_error(char * script_p)20test_syntax_error (char *script_p) /**< script */ 21 { 22 jerry_value_t parse_result = jerry_parse (NULL, 23 0, 24 (const jerry_char_t *) script_p, 25 strlen (script_p), 26 JERRY_PARSE_NO_OPTS); 27 28 bool result = false; 29 30 if (jerry_value_is_error (parse_result)) 31 { 32 result = true; 33 TEST_ASSERT (jerry_get_error_type (parse_result) == JERRY_ERROR_SYNTAX); 34 } 35 36 jerry_release_value (parse_result); 37 return result; 38 } /* test_syntax_error */ 39 40 int main(void)41main (void) 42 { 43 jerry_init (JERRY_INIT_EMPTY); 44 45 if (!test_syntax_error ("\\u{61}")) 46 { 47 TEST_ASSERT (!test_syntax_error ("\xF0\x90\xB2\x80: break \\u{10C80}")); 48 /* The \u surrogate pairs are ignored. The \u{hex} form must be used. */ 49 TEST_ASSERT (test_syntax_error ("\xF0\x90\xB2\x80: break \\ud803\\udc80")); 50 /* The utf8 code point and the cesu8 surrogate pair must match. */ 51 TEST_ASSERT (!test_syntax_error ("\xF0\x90\xB2\x80: break \xed\xa0\x83\xed\xb2\x80")); 52 53 TEST_ASSERT (!test_syntax_error ("$\xF0\x90\xB2\x80$: break $\\u{10C80}$")); 54 TEST_ASSERT (test_syntax_error ("$\xF0\x90\xB2\x80$: break $\\ud803\\udc80$")); 55 TEST_ASSERT (!test_syntax_error ("$\xF0\x90\xB2\x80$: break $\xed\xa0\x83\xed\xb2\x80$")); 56 } 57 58 jerry_cleanup (); 59 60 return 0; 61 } /* main */ 62