idlize

Форк
0
75 строк · 2.2 Кб
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 { Context } from "./context.test"
17
import { log, getLogFiltered, resetLog } from "./util.test"
18
import { assert } from "chai"
19

20
const someId = "xxx"
21

22
suite("Deduce annotation by assignment destination", () => {
23

24
    test("Direct initializer of annotated variable", () => {
25
        resetLog()
26
        let q = 11
27
        /** @memo:entry */
28
        function start(__memo_context: Context, __memo_id: any) {
29
            let
30
            /** @memo */
31
            p: ((k: number)=>number) =
32
                (n:number):number => n+1
33

34
            q = p(17)
35
        }
36
        start(new Context(), someId)
37
        assert.equal(q, 18)
38
    })
39

40
    test("Direct initializer of annotated variable v.2", () => {
41
        resetLog()
42
        let q = 11
43
        /** @memo:entry */
44
        function start(__memo_context: Context, __memo_id: any) {
45
            let
46
            /** @memo */
47
            p: ((k: number, x:()=>void)=>number) =
48
                (n, y):number => n+1
49

50
            q = p(17, ()=>{})
51
        }
52
        start(new Context(), someId)
53
        assert.equal(q, 18)
54
    })
55

56
    test("Direct argument of annotated parameter", () => {
57
        resetLog()
58
        function start(__memo_context: Context, __memo_id: any) {
59
            /** @memo:entry */
60
            function foo(
61
                a: number,
62
                /** @memo */
63
                p: (x: number) => void
64
            ) {
65
                p(a)
66
            }
67

68
            foo(17, (x: number) => {
69
                log("got: " + x)
70
            })
71
        }
72
        start(new Context(), someId)
73
        assert.equal(getLogFiltered(), "got: 17\n")
74
    })
75
})
76

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

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

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

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