idlize

Форк
0
121 строка · 4.1 Кб
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 { assert } from "chai"
17
import * as child from "child_process"
18
import * as path from "path"
19

20
function runTsc(file: string) {
21
    let npx = process.platform === "win32" ? "npx.cmd" : "npx"
22
    return child.spawnSync(npx, ["tsc", path.join('test', 'diagnostics', 'input', file)])
23
}
24

25
function diagnostics(name: string, file: string, message: string) {
26
    test(name, () => {
27
        const result = runTsc(file)
28
        console.log(result.stdout.toString())
29
        assert.include(result.stdout.toString(), message)
30
    }).timeout(30000);
31
}
32

33
function noDiagnostics(name: string, file: string, message: string) {
34
    test(name, () => {
35
        const result = runTsc(file)
36
        console.log(result.stdout.toString())
37
        assert.notInclude(result.stderr.toString(), message)
38
        assert.notInclude(result.stdout.toString(), message)
39
    }).timeout(30000);
40
}
41

42
suite("Memo in non-memo context", () => {
43
    diagnostics("Global memo",
44
        "global_memo.input.ts",
45
        'Calling a @memo function "foo" from a non-@memo context'
46
    )
47
    diagnostics("memo in handler",
48
        "memo_in_handler.input.ts",
49
        'Calling a @memo function "foo" from a non-@memo context'
50
    )
51
    diagnostics("memo in inner function",
52
        "memo_in_inner_function.input.ts",
53
        'Calling a @memo function "foo" from a non-@memo context'
54
    )
55
    noDiagnostics("memo with @memo:entry",
56
        "memo_entry.input.ts",
57
        'Calling a @memo function "foo" from a non-@memo context'
58
    )
59
    diagnostics("memo in non-memo stack",
60
        "no_memo_entry.input.ts",
61
        'Calling a @memo function "foo" from a non-@memo context'
62
    )
63
})
64

65
suite("Changing state in @memo", () => {
66
    noDiagnostics("BinaryCorrect",
67
        "BinaryCorrect.ts",
68
        'Changing state "y" in @memo context is not allowed'
69
    )
70
    diagnostics("BinaryIncorrect",
71
        "BinaryIncorrect.ts",
72
        'Changing state "y" in @memo context is not allowed'
73
    )
74
    noDiagnostics("BinaryNoChange",
75
        "BinaryNoChange.ts",
76
        'Changing state "y" in @memo context is not allowed'
77
    )
78
    noDiagnostics("UnaryCorrect",
79
        "UnaryCorrect.ts",
80
        'Changing state "y" in @memo context is not allowed'
81
    )
82
    diagnostics("UnaryIncorrect",
83
        "UnaryIncorrect.ts",
84
        'Changing state "y" in @memo context is not allowed'
85
    )
86
    noDiagnostics("UnaryNoChange",
87
        "UnaryNoChange.ts",
88
        'Changing state "y" in @memo context is not allowed'
89
    )
90
    diagnostics("Assignment to parameters",
91
        "ParameterAssignment.ts",
92
        "Can not assign to memo function parameter: x"
93
    )
94
    noDiagnostics("Assignment to non-memo parameters",
95
        "NonmemoParameterAssignment.ts",
96
        "Can not assign to memo function parameter: x"
97
    )
98
})
99

100
suite("Function declaration with @memo initializer", () => {
101
    noDiagnostics("NonMemoArgument",
102
        "NonMemoArgument.ts",
103
        'Can not call @memo "bar" in parameter "x" default value expression'
104
    )
105
    diagnostics("MemoArgument",
106
        "MemoArgument.ts",
107
        'Can not call @memo "bar" in parameter "x" default value expression'
108
    )
109
    diagnostics("MemoComplexArgument",
110
        "MemoComplexArgument.ts",
111
        'Can not call @memo "bar" in parameter "x" default value expression'
112
    )
113
    diagnostics("MemoArgumentInArrow",
114
        "MemoArgumentInArrow.ts",
115
        'Can not call @memo "bar" in parameter "x" default value expression'
116
    )
117
    noDiagnostics("NonMemoArgumentInArrow",
118
        "NonMemoArgumentInArrow.ts",
119
        'Can not call @memo "bar" in parameter "x" default value expression'
120
    )
121
})
122

123

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

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

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

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