idlize

Форк
0
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

16
import { qox, til, zex as wax, accessId, juv, Zan, ryq, bae } from "./module.test"
17
import { exported } from "./exports.test"
18
import defexport  from "./default-export.test"
19
import { E } from "./export-as.test"
20
import { __id, Context } from "./context.test"
21
import { log, getLogFiltered, resetLog, cleanDumpDirectory, checkDump } from "./util.test"
22
import { assert } from "chai"
23

24
const someId = "xxx"
25

26
suite("Function and callsite transformations", () => {
27
    cleanDumpDirectory()
28

29
    test("Can find the declaration through named import", () => {
30
        resetLog()
31

32
        /** @memo:entry */
33
        function start(__memo_context: Context, __memo_id: any) {
34
            wax(() => {
35
                log("wax lambda")
36
            })
37
        }
38
        start(new Context(), someId)
39

40
        assert.equal(
41
            getLogFiltered(),
42
`I'm zex
43
wax lambda
44
`
45
        )
46
    })
47
    test("A user argument is passed correctly", () => {
48
        resetLog()
49

50
        /** @memo:entry */
51
        function start(__memo_context: Context, __memo_id: any) {
52
            til("apple", () => {
53
                log("til lambda")
54
            })
55
        }
56
        start(new Context(), someId)
57

58
        assert.equal(
59
            getLogFiltered(),
60
`I'm til, I have an apple
61
til lambda
62
`
63
        )
64
    })
65

66
    test("Access to __id() intrinsic works", () => {
67
        resetLog()
68

69
        /** @memo:entry */
70
        function start(__memo_context: Context, __memo_id: any) {
71
            accessId("orange", () => {
72
                log("accessId lambda, I have an id on the call site: " + __id())
73
            })
74
        }
75
        start(new Context(), someId)
76

77
        assert.equal(
78
            getLogFiltered(),
79
`I'm accessId, I have an orange
80
accessId 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

85
    test("Events absence is allowed", () => {
86
        resetLog()
87

88
        /** @memo:entry */
89
        function start(__memo_context: Context, __memo_id: any) {
90
            qox("apple", () => {
91
                log("qox lambda")
92
            })
93
        }
94
        start(new Context(), someId)
95

96
        assert.equal(
97
            getLogFiltered(),
98
`I'm qox, I have an apple
99
qox lambda
100
`
101
        )
102
    })
103

104
    test("Compute transformation on a global", () => {
105
        resetLog()
106

107
        /** @memo:entry */
108
        function start(__memo_context: Context, __memo_id: any) {
109
            juv("plum", () => {
110
                log("juv lambda")
111
            })
112
        }
113
        start(new Context(), someId)
114

115
        assert.equal(
116
            getLogFiltered(),
117
`I'm juv, I have a plum
118
`
119
        )
120
    })
121

122
    test("Member call site compute transformation", () => {
123
        resetLog()
124

125
        /** @memo:entry */
126
        function start(__memo_context: Context, __memo_id: any) {
127
            const zan = new Zan()
128
            zan.rek("avocado")
129
        }
130
        start(new Context(), someId)
131

132
        assert.equal(
133
            getLogFiltered(),
134
`I'm rek the member. I have an avocado
135
`
136
        )
137
    })
138

139
    test("Member call site component transformation", () => {
140
        resetLog()
141

142
        /** @memo:entry */
143
        function start(__memo_context: Context, __memo_id: any) {
144
            const zan = new Zan()
145
            zan.cep("onion", () => {
146
                log("cep lambda")
147
            })
148
        }
149
        start(new Context(), someId)
150

151
        assert.equal(
152
            getLogFiltered(),
153
`I'm cep the member. I have an onion, false
154
cep lambda
155
`
156
        )
157
    })
158

159
    test("UI arrows work when passed as UI parameters", () => {
160
        resetLog()
161

162
        /** @memo:entry */
163
        function start(__memo_context: Context, __memo_id: any) {
164
            ryq("jumps", "thoughtfully")
165
        }
166
        start(new Context(), someId)
167

168
        assert.equal(
169
            getLogFiltered(),
170
`funny ui cow thoughtfully jumps
171
happy non-ui goat thoughtfully jumps
172
`
173
        )
174
    })
175

176
    test("UI function expressions work when passed as UI parameters", () => {
177
        resetLog()
178

179
        /** @memo:entry */
180
        function start(__memo_context: Context, __memo_id: any) {
181
            bae("dances", "brainlessly")
182
        }
183
        start(new Context(), someId)
184

185
        assert.equal(
186
            getLogFiltered(),
187
`funny ui pig brainlessly dances
188
happy non-ui horse brainlessly dances
189
`
190
        )
191
    })
192

193
    test("The real declaration is discoverable through explicit export", () => {
194
        resetLog()
195
        let x: number = 0
196
        /** @memo:entry */
197
        function start(__memo_context: Context, __memo_id: any) {
198
            x = exported(17)
199
        }
200
        start(new Context(), someId)
201
        assert.equal(x, 18)
202
    })
203

204
    test("The real declaration is discoverable through export as", () => {
205
        resetLog()
206
        let x: number = 0
207
        /** @memo:entry */
208
        function start(__memo_context: Context, __memo_id: any) {
209
            x = E(17)
210
        }
211
        start(new Context(), someId)
212
        assert.equal(x, 18)
213

214
    })
215

216
    test("Default export can be found", () => {
217
        resetLog()
218
        let x: number = 0
219
        /** @memo:entry */
220
        function start(__memo_context: Context, __memo_id: any) {
221
            x = defexport()
222
        }
223
        start(new Context(), someId)
224
        assert.equal(x, 29)
225
    })
226

227
    for (let name of ["accessId", "cep", "juv", "qox", "rek", "til", "zex", "kla", "ryq", "bae"]) {
228
        checkDump(name, "module")
229
    }
230

231
    for (let name of ["exported"]) {
232
        checkDump(name, "exported")
233
    }
234

235
    for (let name of ["intrinsicFunctionUsingThis"]) {
236
        checkDump(name, "receiver")
237
    }
238

239
    for (let name of ["functionUsingThis"]) {
240
        checkDump(name, "receiver")
241
    }
242

243
    for (let name of ["entry1", "entry2", "entry3", "entry4"]) {
244
        checkDump(name, "property")
245
    }
246
})
247

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.