• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 #include <gtest/gtest.h>
16 #include <cstdint>
17 #include <string>
18 #include <utility>
19 #include <vector>
20 #include "assembly-program.h"
21 #include "test/unit/annotations/annotations_emit_test.h"
22 
23 namespace ark::es2panda::compiler::test {
24 
25 class AnnotationsforFunctionalObjects : public AnnotationEmitTest {
26 public:
27     AnnotationsforFunctionalObjects() = default;
28 
29     ~AnnotationsforFunctionalObjects() override = default;
30 
RunAnnotationEmitTest(const std::string_view text)31     void RunAnnotationEmitTest(const std::string_view text)
32     {
33         auto program = GetCurrentProgram(text);
34         ASSERT_NE(program, nullptr);
35 
36         CheckAnnotations(program.get());
37         CheckClassAnnotations(program.get());
38     }
39 
CheckAnnotations(pandasm::Program * program)40     void CheckAnnotations(pandasm::Program *program)
41     {
42         const std::string annoName = "std.annotations.InterfaceObjectLiteral";
43         AnnotationEmitTest::CheckAnnoDecl(program, annoName, {});
44     }
45 
CheckClassAnnotations(pandasm::Program * program)46     void CheckClassAnnotations(pandasm::Program *program)
47     {
48         const std::string recordName = "Iface$ObjectLiteral";
49         const AnnotationMap expectedClassAnnotations = {
50             {"std.annotations.InterfaceObjectLiteral", {}},
51         };
52         AnnotationEmitTest::CheckRecordAnnotations(program, recordName, expectedClassAnnotations);
53     }
54 
55 private:
56     NO_COPY_SEMANTIC(AnnotationsforFunctionalObjects);
57     NO_MOVE_SEMANTIC(AnnotationsforFunctionalObjects);
58 };
59 
60 // #22952
TEST_F(AnnotationsforFunctionalObjects,annotations_for_functional_objects)61 TEST_F(AnnotationsforFunctionalObjects, annotations_for_functional_objects)
62 {
63     std::string_view text = R"(
64     interface Iface { a: number }
65 
66     function bar() {
67         let tif: Iface = { a: 42 }
68     })";
69 
70     RunAnnotationEmitTest(text);
71 }
72 
73 }  // namespace ark::es2panda::compiler::test
74