• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2024-2025 Huawei Device Co., Ltd.
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 "ast_verifier_test.h"
17 #include "checker/ETSchecker.h"
18 #include "ir/expressions/identifier.h"
19 #include "ir/astNode.h"
20 #include "parser/ETSparser.h"
21 
22 #include <gtest/gtest.h>
23 
24 using ark::es2panda::compiler::ast_verifier::EveryChildHasValidParent;
25 
26 namespace {
TEST_F(ASTVerifierTest,ReturnTypeInLambda)27 TEST_F(ASTVerifierTest, ReturnTypeInLambda)
28 {
29     char const *text = R"(
30         function main(): void {
31             let x: () => void = ()=> {}
32         }
33     )";
34 
35     CONTEXT(ES2PANDA_STATE_CHECKED, text)
36     {
37         EXPECT_TRUE(Verify<EveryChildHasValidParent>());
38     }
39 }
40 
TEST_F(ASTVerifierTest,TSThisType)41 TEST_F(ASTVerifierTest, TSThisType)
42 {
43     char const *text = R"(
44         class A {
45             foo(a?: Number): this { return this; }
46         }
47 
48         function main () {}
49     )";
50 
51     CONTEXT(ES2PANDA_STATE_CHECKED, text)
52     {
53         EXPECT_TRUE(Verify<EveryChildHasValidParent>());
54     }
55 }
56 
TEST_F(ASTVerifierTest,TupleFieldInInterface)57 TEST_F(ASTVerifierTest, TupleFieldInInterface)
58 {
59     char const *text = R"(
60         interface I {
61             field: [String, String]
62         }
63     )";
64 
65     CONTEXT(ES2PANDA_STATE_CHECKED, text)
66     {
67         EXPECT_TRUE(Verify<EveryChildHasValidParent>());
68     }
69 }
70 
71 }  // namespace
72