idlize
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
16import { Context } from "./context.test"
17import { log, getLogFiltered, resetLog } from "./util.test"
18import { assert } from "chai"
19
20const someId = "xxx"
21
22suite("Deduce annotation by assignment destination", () => {
23
24test("Direct initializer of annotated variable", () => {
25resetLog()
26let q = 11
27/** @memo:entry */
28function start(__memo_context: Context, __memo_id: any) {
29let
30/** @memo */
31p: ((k: number)=>number) =
32(n:number):number => n+1
33
34q = p(17)
35}
36start(new Context(), someId)
37assert.equal(q, 18)
38})
39
40test("Direct initializer of annotated variable v.2", () => {
41resetLog()
42let q = 11
43/** @memo:entry */
44function start(__memo_context: Context, __memo_id: any) {
45let
46/** @memo */
47p: ((k: number, x:()=>void)=>number) =
48(n, y):number => n+1
49
50q = p(17, ()=>{})
51}
52start(new Context(), someId)
53assert.equal(q, 18)
54})
55
56test("Direct argument of annotated parameter", () => {
57resetLog()
58function start(__memo_context: Context, __memo_id: any) {
59/** @memo:entry */
60function foo(
61a: number,
62/** @memo */
63p: (x: number) => void
64) {
65p(a)
66}
67
68foo(17, (x: number) => {
69log("got: " + x)
70})
71}
72start(new Context(), someId)
73assert.equal(getLogFiltered(), "got: 17\n")
74})
75})
76