idlize
246 строк · 6.3 Кб
1/*
2* Copyright (c) 2022-2023 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
16import { qox, til, zex as wax, accessId, juv, Zan, ryq, bae } from "./module.test"
17import { exported } from "./exports.test"
18import defexport from "./default-export.test"
19import { E } from "./export-as.test"
20import { __id, Context } from "./context.test"
21import { log, getLogFiltered, resetLog, cleanDumpDirectory, checkDump } from "./util.test"
22import { assert } from "chai"
23
24const someId = "xxx"
25
26suite("Function and callsite transformations", () => {
27cleanDumpDirectory()
28
29test("Can find the declaration through named import", () => {
30resetLog()
31
32/** @memo:entry */
33function start(__memo_context: Context, __memo_id: any) {
34wax(() => {
35log("wax lambda")
36})
37}
38start(new Context(), someId)
39
40assert.equal(
41getLogFiltered(),
42`I'm zex
43wax lambda
44`
45)
46})
47test("A user argument is passed correctly", () => {
48resetLog()
49
50/** @memo:entry */
51function start(__memo_context: Context, __memo_id: any) {
52til("apple", () => {
53log("til lambda")
54})
55}
56start(new Context(), someId)
57
58assert.equal(
59getLogFiltered(),
60`I'm til, I have an apple
61til lambda
62`
63)
64})
65
66test("Access to __id() intrinsic works", () => {
67resetLog()
68
69/** @memo:entry */
70function start(__memo_context: Context, __memo_id: any) {
71accessId("orange", () => {
72log("accessId lambda, I have an id on the call site: " + __id())
73})
74}
75start(new Context(), someId)
76
77assert.equal(
78getLogFiltered(),
79`I'm accessId, I have an orange
80accessId lambda, I have an id on the call site: xxx5___key_id_DIRNAME/basic.test.ts7___key_id_DIRNAME/module.test.ts
81`
82)
83})
84
85test("Events absence is allowed", () => {
86resetLog()
87
88/** @memo:entry */
89function start(__memo_context: Context, __memo_id: any) {
90qox("apple", () => {
91log("qox lambda")
92})
93}
94start(new Context(), someId)
95
96assert.equal(
97getLogFiltered(),
98`I'm qox, I have an apple
99qox lambda
100`
101)
102})
103
104test("Compute transformation on a global", () => {
105resetLog()
106
107/** @memo:entry */
108function start(__memo_context: Context, __memo_id: any) {
109juv("plum", () => {
110log("juv lambda")
111})
112}
113start(new Context(), someId)
114
115assert.equal(
116getLogFiltered(),
117`I'm juv, I have a plum
118`
119)
120})
121
122test("Member call site compute transformation", () => {
123resetLog()
124
125/** @memo:entry */
126function start(__memo_context: Context, __memo_id: any) {
127const zan = new Zan()
128zan.rek("avocado")
129}
130start(new Context(), someId)
131
132assert.equal(
133getLogFiltered(),
134`I'm rek the member. I have an avocado
135`
136)
137})
138
139test("Member call site component transformation", () => {
140resetLog()
141
142/** @memo:entry */
143function start(__memo_context: Context, __memo_id: any) {
144const zan = new Zan()
145zan.cep("onion", () => {
146log("cep lambda")
147})
148}
149start(new Context(), someId)
150
151assert.equal(
152getLogFiltered(),
153`I'm cep the member. I have an onion, false
154cep lambda
155`
156)
157})
158
159test("UI arrows work when passed as UI parameters", () => {
160resetLog()
161
162/** @memo:entry */
163function start(__memo_context: Context, __memo_id: any) {
164ryq("jumps", "thoughtfully")
165}
166start(new Context(), someId)
167
168assert.equal(
169getLogFiltered(),
170`funny ui cow thoughtfully jumps
171happy non-ui goat thoughtfully jumps
172`
173)
174})
175
176test("UI function expressions work when passed as UI parameters", () => {
177resetLog()
178
179/** @memo:entry */
180function start(__memo_context: Context, __memo_id: any) {
181bae("dances", "brainlessly")
182}
183start(new Context(), someId)
184
185assert.equal(
186getLogFiltered(),
187`funny ui pig brainlessly dances
188happy non-ui horse brainlessly dances
189`
190)
191})
192
193test("The real declaration is discoverable through explicit export", () => {
194resetLog()
195let x: number = 0
196/** @memo:entry */
197function start(__memo_context: Context, __memo_id: any) {
198x = exported(17)
199}
200start(new Context(), someId)
201assert.equal(x, 18)
202})
203
204test("The real declaration is discoverable through export as", () => {
205resetLog()
206let x: number = 0
207/** @memo:entry */
208function start(__memo_context: Context, __memo_id: any) {
209x = E(17)
210}
211start(new Context(), someId)
212assert.equal(x, 18)
213
214})
215
216test("Default export can be found", () => {
217resetLog()
218let x: number = 0
219/** @memo:entry */
220function start(__memo_context: Context, __memo_id: any) {
221x = defexport()
222}
223start(new Context(), someId)
224assert.equal(x, 29)
225})
226
227for (let name of ["accessId", "cep", "juv", "qox", "rek", "til", "zex", "kla", "ryq", "bae"]) {
228checkDump(name, "module")
229}
230
231for (let name of ["exported"]) {
232checkDump(name, "exported")
233}
234
235for (let name of ["intrinsicFunctionUsingThis"]) {
236checkDump(name, "receiver")
237}
238
239for (let name of ["functionUsingThis"]) {
240checkDump(name, "receiver")
241}
242
243for (let name of ["entry1", "entry2", "entry3", "entry4"]) {
244checkDump(name, "property")
245}
246})
247