From e71cfdf8be282b6fab60bce9963a4af47da9cb93 Mon Sep 17 00:00:00 2001 From: Vivien Voros Date: Mon, 25 Aug 2025 10:08:16 +0200 Subject: [PATCH] Increasing coverage of diagnostic errors - 6 Add tests to cover diagnostic errors. Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICUKOH Related Internal Issue: #26188 Change-Id: I1b7bbf19472ceaf99904747e5525077c499c0ea5 Signed-off-by: Vivien Voros --- .../test/ast/parser/ts/deleting_local_var.ts | 19 +++++++++++++++++++ .../ts/regex_class_range_out_of_order.ts | 18 ++++++++++++++++++ .../ast/parser/ts/regex_invalid_assertion.ts | 18 ++++++++++++++++++ .../test/ast/parser/ts/regex_invalid_char.ts | 18 ++++++++++++++++++ .../ts/regex_invalid_closing_parenthesis.ts | 18 ++++++++++++++++++ .../ts/regex_invalid_non_capturing_group.ts | 18 ++++++++++++++++++ .../ast/parser/ts/regex_quantifier_ranege.ts | 18 ++++++++++++++++++ .../ts/unterminated_multi_line_comment.ts | 18 ++++++++++++++++++ 8 files changed, 145 insertions(+) create mode 100644 ets2panda/test/ast/parser/ts/deleting_local_var.ts create mode 100644 ets2panda/test/ast/parser/ts/regex_class_range_out_of_order.ts create mode 100644 ets2panda/test/ast/parser/ts/regex_invalid_assertion.ts create mode 100644 ets2panda/test/ast/parser/ts/regex_invalid_char.ts create mode 100644 ets2panda/test/ast/parser/ts/regex_invalid_closing_parenthesis.ts create mode 100644 ets2panda/test/ast/parser/ts/regex_invalid_non_capturing_group.ts create mode 100644 ets2panda/test/ast/parser/ts/regex_quantifier_ranege.ts create mode 100644 ets2panda/test/ast/parser/ts/unterminated_multi_line_comment.ts diff --git a/ets2panda/test/ast/parser/ts/deleting_local_var.ts b/ets2panda/test/ast/parser/ts/deleting_local_var.ts new file mode 100644 index 0000000000..b132d6f719 --- /dev/null +++ b/ets2panda/test/ast/parser/ts/deleting_local_var.ts @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +let x = 42; +delete x; + +/* @@? 17:9 Error SyntaxError: Deleting local variable in strict mode. */ diff --git a/ets2panda/test/ast/parser/ts/regex_class_range_out_of_order.ts b/ets2panda/test/ast/parser/ts/regex_class_range_out_of_order.ts new file mode 100644 index 0000000000..66ced1f7e3 --- /dev/null +++ b/ets2panda/test/ast/parser/ts/regex_class_range_out_of_order.ts @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +const regex = /[z-a]/ + +/* @@? 16:16 Error SyntaxError: Class range out of order. */ diff --git a/ets2panda/test/ast/parser/ts/regex_invalid_assertion.ts b/ets2panda/test/ast/parser/ts/regex_invalid_assertion.ts new file mode 100644 index 0000000000..5ecc52e41b --- /dev/null +++ b/ets2panda/test/ast/parser/ts/regex_invalid_assertion.ts @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +const regex = /(?!/ + +/* @@? 16:16 Error SyntaxError: Invalid assertion. */ diff --git a/ets2panda/test/ast/parser/ts/regex_invalid_char.ts b/ets2panda/test/ast/parser/ts/regex_invalid_char.ts new file mode 100644 index 0000000000..67a3d115be --- /dev/null +++ b/ets2panda/test/ast/parser/ts/regex_invalid_char.ts @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +const regex = /?abc/; + +/* @@? 16:16 Error SyntaxError: Invalid character. */ diff --git a/ets2panda/test/ast/parser/ts/regex_invalid_closing_parenthesis.ts b/ets2panda/test/ast/parser/ts/regex_invalid_closing_parenthesis.ts new file mode 100644 index 0000000000..41a168aef7 --- /dev/null +++ b/ets2panda/test/ast/parser/ts/regex_invalid_closing_parenthesis.ts @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +const regex = /abc)/; + +/* @@? 16:16 Error SyntaxError: Invalid closing parenthesis. */ diff --git a/ets2panda/test/ast/parser/ts/regex_invalid_non_capturing_group.ts b/ets2panda/test/ast/parser/ts/regex_invalid_non_capturing_group.ts new file mode 100644 index 0000000000..ee8fbc1596 --- /dev/null +++ b/ets2panda/test/ast/parser/ts/regex_invalid_non_capturing_group.ts @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +const regex = /(?:abc/; + +/* @@? 16:16 Error SyntaxError: Invalid non-capturing group. */ diff --git a/ets2panda/test/ast/parser/ts/regex_quantifier_ranege.ts b/ets2panda/test/ast/parser/ts/regex_quantifier_ranege.ts new file mode 100644 index 0000000000..905c66a3e7 --- /dev/null +++ b/ets2panda/test/ast/parser/ts/regex_quantifier_ranege.ts @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +const regex = /a{3,2}/; + +/* @@? 16:16 Error SyntaxError: Quantifier range out of order. */ diff --git a/ets2panda/test/ast/parser/ts/unterminated_multi_line_comment.ts b/ets2panda/test/ast/parser/ts/unterminated_multi_line_comment.ts new file mode 100644 index 0000000000..d56d6fd4f9 --- /dev/null +++ b/ets2panda/test/ast/parser/ts/unterminated_multi_line_comment.ts @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* @@? 1:1 Error SyntaxError: Unterminated multi-line comment. */ + +/* -- Gitee