@typespec/emitter-framework 0.11.0-dev.6 → 0.11.0-dev.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/core/components/index.js +2 -1
- package/dist/src/core/components/index.js.map +1 -0
- package/dist/src/core/components/output.js +2 -1
- package/dist/src/core/components/output.js.map +1 -0
- package/dist/src/core/components/overrides/component-overrides.js +2 -1
- package/dist/src/core/components/overrides/component-overrides.js.map +1 -0
- package/dist/src/core/components/overrides/config.js +2 -1
- package/dist/src/core/components/overrides/config.js.map +1 -0
- package/dist/src/core/components/overrides/context.js +2 -1
- package/dist/src/core/components/overrides/context.js.map +1 -0
- package/dist/src/core/context/index.js +2 -1
- package/dist/src/core/context/index.js.map +1 -0
- package/dist/src/core/context/name-policy-context.js +2 -1
- package/dist/src/core/context/name-policy-context.js.map +1 -0
- package/dist/src/core/context/tsp-context.js +2 -1
- package/dist/src/core/context/tsp-context.js.map +1 -0
- package/dist/src/core/index.js +2 -1
- package/dist/src/core/index.js.map +1 -0
- package/dist/src/core/transport-name-policy.js +2 -1
- package/dist/src/core/transport-name-policy.js.map +1 -0
- package/dist/src/core/write-output.js +2 -1
- package/dist/src/core/write-output.js.map +1 -0
- package/dist/src/csharp/components/class/declaration.d.ts.map +1 -1
- package/dist/src/csharp/components/class/declaration.js +9 -1
- package/dist/src/csharp/components/class/declaration.js.map +1 -0
- package/dist/src/csharp/components/class/declaration.test.js +62 -105
- package/dist/src/csharp/components/class/declaration.test.js.map +1 -0
- package/dist/src/csharp/components/enum/declaration.js +2 -1
- package/dist/src/csharp/components/enum/declaration.js.map +1 -0
- package/dist/src/csharp/components/enum/declaration.test.js +52 -88
- package/dist/src/csharp/components/enum/declaration.test.js.map +1 -0
- package/dist/src/csharp/components/index.js +2 -1
- package/dist/src/csharp/components/index.js.map +1 -0
- package/dist/src/csharp/components/property/property.d.ts.map +1 -1
- package/dist/src/csharp/components/property/property.js +31 -2
- package/dist/src/csharp/components/property/property.js.map +1 -0
- package/dist/src/csharp/components/property/property.test.js +91 -39
- package/dist/src/csharp/components/property/property.test.js.map +1 -0
- package/dist/src/csharp/components/type-expression.js +2 -1
- package/dist/src/csharp/components/type-expression.js.map +1 -0
- package/dist/src/csharp/components/type-expression.test.js +43 -74
- package/dist/src/csharp/components/type-expression.test.js.map +1 -0
- package/dist/src/csharp/components/utils/doc-comments.js +2 -1
- package/dist/src/csharp/components/utils/doc-comments.js.map +1 -0
- package/dist/src/csharp/components/utils/nullable-util.js +2 -1
- package/dist/src/csharp/components/utils/nullable-util.js.map +1 -0
- package/dist/src/csharp/components/utils/refkey.js +2 -1
- package/dist/src/csharp/components/utils/refkey.js.map +1 -0
- package/dist/src/csharp/index.js +2 -1
- package/dist/src/csharp/index.js.map +1 -0
- package/dist/src/lib.js +2 -1
- package/dist/src/lib.js.map +1 -0
- package/dist/src/testing/index.js +2 -1
- package/dist/src/testing/index.js.map +1 -0
- package/dist/src/testing/scenario-test/code-block-expectation.js +2 -1
- package/dist/src/testing/scenario-test/code-block-expectation.js.map +1 -0
- package/dist/src/testing/scenario-test/code-block-expectation.test.js +2 -1
- package/dist/src/testing/scenario-test/code-block-expectation.test.js.map +1 -0
- package/dist/src/testing/scenario-test/harness.js +2 -1
- package/dist/src/testing/scenario-test/harness.js.map +1 -0
- package/dist/src/testing/scenario-test/index.js +2 -1
- package/dist/src/testing/scenario-test/index.js.map +1 -0
- package/dist/src/testing/scenario-test/snippet-extractor.js +2 -1
- package/dist/src/testing/scenario-test/snippet-extractor.js.map +1 -0
- package/dist/src/typescript/components/array-expression.js +2 -1
- package/dist/src/typescript/components/array-expression.js.map +1 -0
- package/dist/src/typescript/components/arrow-function.js +2 -1
- package/dist/src/typescript/components/arrow-function.js.map +1 -0
- package/dist/src/typescript/components/class-method.js +2 -1
- package/dist/src/typescript/components/class-method.js.map +1 -0
- package/dist/src/typescript/components/enum-declaration.js +2 -1
- package/dist/src/typescript/components/enum-declaration.js.map +1 -0
- package/dist/src/typescript/components/function-declaration.js +2 -1
- package/dist/src/typescript/components/function-declaration.js.map +1 -0
- package/dist/src/typescript/components/function-expression.js +2 -1
- package/dist/src/typescript/components/function-expression.js.map +1 -0
- package/dist/src/typescript/components/function-type.js +2 -1
- package/dist/src/typescript/components/function-type.js.map +1 -0
- package/dist/src/typescript/components/index.js +2 -1
- package/dist/src/typescript/components/index.js.map +1 -0
- package/dist/src/typescript/components/interface-declaration.js +2 -1
- package/dist/src/typescript/components/interface-declaration.js.map +1 -0
- package/dist/src/typescript/components/interface-member.js +2 -1
- package/dist/src/typescript/components/interface-member.js.map +1 -0
- package/dist/src/typescript/components/interface-method.js +2 -1
- package/dist/src/typescript/components/interface-method.js.map +1 -0
- package/dist/src/typescript/components/record-expression.js +2 -1
- package/dist/src/typescript/components/record-expression.js.map +1 -0
- package/dist/src/typescript/components/static-serializers.js +2 -1
- package/dist/src/typescript/components/static-serializers.js.map +1 -0
- package/dist/src/typescript/components/type-alias-declaration.js +2 -1
- package/dist/src/typescript/components/type-alias-declaration.js.map +1 -0
- package/dist/src/typescript/components/type-declaration.js +2 -1
- package/dist/src/typescript/components/type-declaration.js.map +1 -0
- package/dist/src/typescript/components/type-expression.js +2 -1
- package/dist/src/typescript/components/type-expression.js.map +1 -0
- package/dist/src/typescript/components/type-transform.js +2 -1
- package/dist/src/typescript/components/type-transform.js.map +1 -0
- package/dist/src/typescript/components/union/declaration.js +2 -1
- package/dist/src/typescript/components/union/declaration.js.map +1 -0
- package/dist/src/typescript/components/union/declaration.test.js +2 -1
- package/dist/src/typescript/components/union/declaration.test.js.map +1 -0
- package/dist/src/typescript/components/union/expression.js +2 -1
- package/dist/src/typescript/components/union/expression.js.map +1 -0
- package/dist/src/typescript/components/union/expression.test.js +2 -1
- package/dist/src/typescript/components/union/expression.test.js.map +1 -0
- package/dist/src/typescript/components/value-expression.js +2 -1
- package/dist/src/typescript/components/value-expression.js.map +1 -0
- package/dist/src/typescript/index.js +2 -1
- package/dist/src/typescript/index.js.map +1 -0
- package/dist/src/typescript/lib.js +2 -1
- package/dist/src/typescript/lib.js.map +1 -0
- package/dist/src/typescript/utils/index.js +2 -1
- package/dist/src/typescript/utils/index.js.map +1 -0
- package/dist/src/typescript/utils/operation.js +2 -1
- package/dist/src/typescript/utils/operation.js.map +1 -0
- package/dist/src/typescript/utils/refkey.js +2 -1
- package/dist/src/typescript/utils/refkey.js.map +1 -0
- package/dist/test/test-host.js +2 -1
- package/dist/test/test-host.js.map +1 -0
- package/dist/test/testing/snippet-extractor-csharp.test.js +2 -1
- package/dist/test/testing/snippet-extractor-csharp.test.js.map +1 -0
- package/dist/test/testing/snippet-extractor-java.test.js +2 -1
- package/dist/test/testing/snippet-extractor-java.test.js.map +1 -0
- package/dist/test/testing/snippet-extractor-python.test.js +2 -1
- package/dist/test/testing/snippet-extractor-python.test.js.map +1 -0
- package/dist/test/testing/snippet-extractor-typescript.test.js +2 -1
- package/dist/test/testing/snippet-extractor-typescript.test.js.map +1 -0
- package/dist/test/typescript/components/arrow-function.test.js +9 -14
- package/dist/test/typescript/components/arrow-function.test.js.map +1 -0
- package/dist/test/typescript/components/component-override.test.js +2 -1
- package/dist/test/typescript/components/component-override.test.js.map +1 -0
- package/dist/test/typescript/components/enum-declaration.test.js +2 -1
- package/dist/test/typescript/components/enum-declaration.test.js.map +1 -0
- package/dist/test/typescript/components/function-declaration.test.js +2 -1
- package/dist/test/typescript/components/function-declaration.test.js.map +1 -0
- package/dist/test/typescript/components/function-expression.test.js +9 -14
- package/dist/test/typescript/components/function-expression.test.js.map +1 -0
- package/dist/test/typescript/components/function-type.test.js +9 -14
- package/dist/test/typescript/components/function-type.test.js.map +1 -0
- package/dist/test/typescript/components/interface-declaration.test.js +2 -1
- package/dist/test/typescript/components/interface-declaration.test.js.map +1 -0
- package/dist/test/typescript/components/interface-method.test.js +19 -29
- package/dist/test/typescript/components/interface-method.test.js.map +1 -0
- package/dist/test/typescript/components/member-expression.test.js +2 -1
- package/dist/test/typescript/components/member-expression.test.js.map +1 -0
- package/dist/test/typescript/components/type-alias-declaration.test.js +2 -1
- package/dist/test/typescript/components/type-alias-declaration.test.js.map +1 -0
- package/dist/test/typescript/components/type-transform.test.js +2 -1
- package/dist/test/typescript/components/type-transform.test.js.map +1 -0
- package/dist/test/typescript/components/value-expression.test.js +2 -1
- package/dist/test/typescript/components/value-expression.test.js.map +1 -0
- package/dist/test/typescript/test-host.js +2 -1
- package/dist/test/typescript/test-host.js.map +1 -0
- package/dist/test/typescript/utils.js +2 -1
- package/dist/test/typescript/utils.js.map +1 -0
- package/dist/test/utils.d.ts.map +1 -1
- package/dist/test/utils.js +5 -2
- package/dist/test/utils.js.map +1 -0
- package/dist/test/vitest.setup.js +2 -1
- package/dist/test/vitest.setup.js.map +1 -0
- package/package.json +7 -7
- package/src/csharp/components/class/declaration.test.tsx +61 -102
- package/src/csharp/components/class/declaration.tsx +6 -0
- package/src/csharp/components/enum/declaration.test.tsx +47 -78
- package/src/csharp/components/property/property.test.tsx +74 -35
- package/src/csharp/components/property/property.tsx +34 -1
- package/src/csharp/components/type-expression.test.tsx +41 -93
- package/test/typescript/components/arrow-function.test.tsx +10 -28
- package/test/typescript/components/function-expression.test.tsx +10 -28
- package/test/typescript/components/function-type.test.tsx +10 -28
- package/test/typescript/components/interface-method.test.tsx +25 -68
- package/test/utils.ts +3 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type Children } from "@alloy-js/core";
|
|
2
2
|
import * as cs from "@alloy-js/csharp";
|
|
3
3
|
import { Attribute } from "@alloy-js/csharp";
|
|
4
|
-
import { type ModelProperty, resolveEncodedName, type Type } from "@typespec/compiler";
|
|
4
|
+
import { getProperty, type ModelProperty, resolveEncodedName, type Type } from "@typespec/compiler";
|
|
5
5
|
import { useTsp } from "../../../core/index.js";
|
|
6
6
|
import { TypeExpression } from "../type-expression.jsx";
|
|
7
7
|
import { getDocComments } from "../utils/doc-comments.jsx";
|
|
@@ -20,11 +20,44 @@ export function Property(props: PropertyProps): Children {
|
|
|
20
20
|
const result = preprocessPropertyType(props.type);
|
|
21
21
|
const { $ } = useTsp();
|
|
22
22
|
|
|
23
|
+
let overrideType: "" | "override" | "new" = "";
|
|
24
|
+
let isVirtual = false;
|
|
25
|
+
if (props.type.model) {
|
|
26
|
+
if (props.type.model.baseModel) {
|
|
27
|
+
const base = props.type.model.baseModel;
|
|
28
|
+
const baseProperty = getProperty(base, props.type.name);
|
|
29
|
+
if (baseProperty) {
|
|
30
|
+
const baseResult = preprocessPropertyType(baseProperty);
|
|
31
|
+
if (baseResult.nullable === result.nullable && baseResult.type === result.type) {
|
|
32
|
+
overrideType = "override";
|
|
33
|
+
} else {
|
|
34
|
+
overrideType = "new";
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (
|
|
39
|
+
overrideType === "" &&
|
|
40
|
+
props.type.model.derivedModels &&
|
|
41
|
+
props.type.model.derivedModels.length > 0
|
|
42
|
+
) {
|
|
43
|
+
isVirtual = props.type.model.derivedModels.some((derived) => {
|
|
44
|
+
const derivedProperty = derived.properties.get(props.type.name);
|
|
45
|
+
if (derivedProperty) {
|
|
46
|
+
const derivedResult = preprocessPropertyType(derivedProperty);
|
|
47
|
+
return derivedResult.nullable === result.nullable && derivedResult.type === result.type;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
23
53
|
return (
|
|
24
54
|
<cs.Property
|
|
25
55
|
name={props.type.name}
|
|
26
56
|
type={<TypeExpression type={result.type} />}
|
|
57
|
+
override={overrideType === "override"}
|
|
58
|
+
new={overrideType === "new"}
|
|
27
59
|
public
|
|
60
|
+
virtual={isVirtual}
|
|
28
61
|
required={!props.type.optional}
|
|
29
62
|
nullable={result.nullable}
|
|
30
63
|
doc={getDocComments($, props.type)}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import { type Children
|
|
2
|
-
import {
|
|
3
|
-
import { Namespace, SourceFile } from "@alloy-js/csharp";
|
|
1
|
+
import { type Children } from "@alloy-js/core";
|
|
2
|
+
import { SourceFile } from "@alloy-js/csharp";
|
|
4
3
|
import type { Model, ModelProperty } from "@typespec/compiler";
|
|
5
4
|
import type { BasicTestRunner } from "@typespec/compiler/testing";
|
|
6
|
-
import { beforeEach, describe, it } from "vitest";
|
|
5
|
+
import { beforeEach, describe, expect, it } from "vitest";
|
|
7
6
|
import { createEmitterFrameworkTestRunner } from "../../../test/typescript/test-host.js";
|
|
8
|
-
import { assertFileContents } from "../../../test/utils.js";
|
|
9
7
|
import { Output } from "../../core/index.js";
|
|
10
8
|
import { ClassDeclaration } from "./class/declaration.js";
|
|
11
9
|
import { TypeExpression } from "./type-expression.jsx";
|
|
@@ -19,9 +17,7 @@ beforeEach(async () => {
|
|
|
19
17
|
function Wrapper(props: { children: Children }) {
|
|
20
18
|
return (
|
|
21
19
|
<Output program={runner.program}>
|
|
22
|
-
<
|
|
23
|
-
<SourceFile path="test.ts">{props.children}</SourceFile>
|
|
24
|
-
</Namespace>
|
|
20
|
+
<SourceFile path="test.ts">{props.children}</SourceFile>
|
|
25
21
|
</Output>
|
|
26
22
|
);
|
|
27
23
|
}
|
|
@@ -43,61 +39,37 @@ describe("map scalar to c# built-in types", () => {
|
|
|
43
39
|
["int64", "long"],
|
|
44
40
|
])("%s => %s", async (tspType, csType) => {
|
|
45
41
|
const type = await compileType(tspType);
|
|
46
|
-
|
|
42
|
+
expect(
|
|
47
43
|
<Wrapper>
|
|
48
44
|
<TypeExpression type={type} />
|
|
49
45
|
</Wrapper>,
|
|
50
|
-
)
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
res,
|
|
54
|
-
d`
|
|
55
|
-
namespace TestNamespace
|
|
56
|
-
{
|
|
57
|
-
${csType}
|
|
58
|
-
}
|
|
59
|
-
`,
|
|
60
|
-
);
|
|
46
|
+
).toRenderTo(`
|
|
47
|
+
${csType}
|
|
48
|
+
`);
|
|
61
49
|
});
|
|
62
50
|
});
|
|
63
51
|
|
|
64
52
|
it("maps array to c# array", async () => {
|
|
65
53
|
const type = await compileType("int32[]");
|
|
66
|
-
|
|
54
|
+
expect(
|
|
67
55
|
<Wrapper>
|
|
68
56
|
<TypeExpression type={type} />
|
|
69
57
|
</Wrapper>,
|
|
70
|
-
)
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
res,
|
|
74
|
-
d`
|
|
75
|
-
namespace TestNamespace
|
|
76
|
-
{
|
|
77
|
-
int[]
|
|
78
|
-
}
|
|
79
|
-
`,
|
|
80
|
-
);
|
|
58
|
+
).toRenderTo(`
|
|
59
|
+
int[]
|
|
60
|
+
`);
|
|
81
61
|
});
|
|
82
62
|
|
|
83
63
|
describe("Record map to IDictionary", () => {
|
|
84
64
|
it("for primitive types", async () => {
|
|
85
65
|
const type = await compileType("Record<int32>");
|
|
86
|
-
|
|
66
|
+
expect(
|
|
87
67
|
<Wrapper>
|
|
88
68
|
<TypeExpression type={type} />
|
|
89
69
|
</Wrapper>,
|
|
90
|
-
)
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
res,
|
|
94
|
-
d`
|
|
95
|
-
namespace TestNamespace
|
|
96
|
-
{
|
|
97
|
-
IDictionary<string, int>
|
|
98
|
-
}
|
|
99
|
-
`,
|
|
100
|
-
);
|
|
70
|
+
).toRenderTo(`
|
|
71
|
+
IDictionary<string, int>
|
|
72
|
+
`);
|
|
101
73
|
});
|
|
102
74
|
|
|
103
75
|
it("for models", async () => {
|
|
@@ -108,27 +80,19 @@ describe("Record map to IDictionary", () => {
|
|
|
108
80
|
@test model Pet {}
|
|
109
81
|
`)) as { test: ModelProperty; Pet: Model };
|
|
110
82
|
|
|
111
|
-
|
|
83
|
+
expect(
|
|
112
84
|
<Wrapper>
|
|
113
85
|
<ClassDeclaration type={Pet} />
|
|
114
86
|
<hbr />
|
|
115
87
|
<TypeExpression type={test.type} />
|
|
116
88
|
</Wrapper>,
|
|
117
|
-
)
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
class Pet
|
|
125
|
-
{
|
|
126
|
-
|
|
127
|
-
}
|
|
128
|
-
IDictionary<string, Pet>
|
|
129
|
-
}
|
|
130
|
-
`,
|
|
131
|
-
);
|
|
89
|
+
).toRenderTo(`
|
|
90
|
+
class Pet
|
|
91
|
+
{
|
|
92
|
+
|
|
93
|
+
}
|
|
94
|
+
IDictionary<string, Pet>
|
|
95
|
+
`);
|
|
132
96
|
});
|
|
133
97
|
});
|
|
134
98
|
|
|
@@ -140,24 +104,16 @@ describe("Nullable union", () => {
|
|
|
140
104
|
}
|
|
141
105
|
`)) as { Pet: Model };
|
|
142
106
|
|
|
143
|
-
|
|
107
|
+
expect(
|
|
144
108
|
<Wrapper>
|
|
145
109
|
<ClassDeclaration type={Pet} />
|
|
146
110
|
</Wrapper>,
|
|
147
|
-
)
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
{
|
|
154
|
-
class Pet
|
|
155
|
-
{
|
|
156
|
-
public required bool? name { get; set; }
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
`,
|
|
160
|
-
);
|
|
111
|
+
).toRenderTo(`
|
|
112
|
+
class Pet
|
|
113
|
+
{
|
|
114
|
+
public required bool? name { get; set; }
|
|
115
|
+
}
|
|
116
|
+
`);
|
|
161
117
|
});
|
|
162
118
|
});
|
|
163
119
|
|
|
@@ -172,26 +128,18 @@ describe("Literal types", () => {
|
|
|
172
128
|
}
|
|
173
129
|
`)) as { Pet: Model };
|
|
174
130
|
|
|
175
|
-
|
|
131
|
+
expect(
|
|
176
132
|
<Wrapper>
|
|
177
133
|
<ClassDeclaration type={Pet} />
|
|
178
134
|
</Wrapper>,
|
|
179
|
-
)
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
{
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
public required bool boolName { get; set; }
|
|
189
|
-
public required int intName { get; set; }
|
|
190
|
-
public required double doubleName { get; set; }
|
|
191
|
-
public required string stringName { get; set; }
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
`,
|
|
195
|
-
);
|
|
135
|
+
).toRenderTo(`
|
|
136
|
+
class Pet
|
|
137
|
+
{
|
|
138
|
+
public required bool boolName { get; set; }
|
|
139
|
+
public required int intName { get; set; }
|
|
140
|
+
public required double doubleName { get; set; }
|
|
141
|
+
public required string stringName { get; set; }
|
|
142
|
+
}
|
|
143
|
+
`);
|
|
196
144
|
});
|
|
197
145
|
});
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import { render } from "@alloy-js/core";
|
|
2
|
-
import { d } from "@alloy-js/core/testing";
|
|
3
1
|
import { SourceFile } from "@alloy-js/typescript";
|
|
4
2
|
import type { Operation } from "@typespec/compiler";
|
|
5
3
|
import type { BasicTestRunner } from "@typespec/compiler/testing";
|
|
6
|
-
import { beforeEach, describe, it } from "vitest";
|
|
4
|
+
import { beforeEach, describe, expect, it } from "vitest";
|
|
7
5
|
import { Output } from "../../../src/core/components/output.jsx";
|
|
8
6
|
import { ArrowFunction } from "../../../src/typescript/components/arrow-function.jsx";
|
|
9
|
-
import { assertFileContents } from "../../utils.js";
|
|
10
7
|
import { createEmitterFrameworkTestRunner } from "../test-host.js";
|
|
11
8
|
|
|
12
9
|
describe("arrow functions with a `type` prop", () => {
|
|
@@ -21,22 +18,17 @@ describe("arrow functions with a `type` prop", () => {
|
|
|
21
18
|
@test op getName(id: string): string;
|
|
22
19
|
`)) as { getName: Operation };
|
|
23
20
|
|
|
24
|
-
|
|
21
|
+
expect(
|
|
25
22
|
<Output program={runner.program}>
|
|
26
23
|
<SourceFile path="test.ts">
|
|
27
24
|
<ArrowFunction type={getName}>console.log("Hello!");</ArrowFunction>
|
|
28
25
|
</SourceFile>
|
|
29
26
|
</Output>,
|
|
30
|
-
)
|
|
31
|
-
|
|
32
|
-
assertFileContents(
|
|
33
|
-
res,
|
|
34
|
-
d`
|
|
27
|
+
).toRenderTo(`
|
|
35
28
|
(id: string): string => {
|
|
36
29
|
console.log("Hello!");
|
|
37
30
|
}
|
|
38
|
-
|
|
39
|
-
);
|
|
31
|
+
`);
|
|
40
32
|
});
|
|
41
33
|
|
|
42
34
|
it("creates an async function", async () => {
|
|
@@ -44,20 +36,15 @@ describe("arrow functions with a `type` prop", () => {
|
|
|
44
36
|
@test op getName(id: string): string;
|
|
45
37
|
`)) as { getName: Operation };
|
|
46
38
|
|
|
47
|
-
|
|
39
|
+
expect(
|
|
48
40
|
<Output program={runner.program}>
|
|
49
41
|
<SourceFile path="test.ts">
|
|
50
42
|
<ArrowFunction async type={getName} />
|
|
51
43
|
</SourceFile>
|
|
52
44
|
</Output>,
|
|
53
|
-
)
|
|
54
|
-
|
|
55
|
-
assertFileContents(
|
|
56
|
-
res,
|
|
57
|
-
d`
|
|
45
|
+
).toRenderTo(`
|
|
58
46
|
async (id: string): Promise<string> => {}
|
|
59
|
-
|
|
60
|
-
);
|
|
47
|
+
`);
|
|
61
48
|
});
|
|
62
49
|
|
|
63
50
|
it("can append extra parameters with raw params provided", async () => {
|
|
@@ -65,7 +52,7 @@ describe("arrow functions with a `type` prop", () => {
|
|
|
65
52
|
@test op getName(id: string): string;
|
|
66
53
|
`)) as { getName: Operation };
|
|
67
54
|
|
|
68
|
-
|
|
55
|
+
expect(
|
|
69
56
|
<Output program={runner.program}>
|
|
70
57
|
<SourceFile path="test.ts">
|
|
71
58
|
<ArrowFunction
|
|
@@ -74,13 +61,8 @@ describe("arrow functions with a `type` prop", () => {
|
|
|
74
61
|
/>
|
|
75
62
|
</SourceFile>
|
|
76
63
|
</Output>,
|
|
77
|
-
)
|
|
78
|
-
|
|
79
|
-
assertFileContents(
|
|
80
|
-
res,
|
|
81
|
-
d`
|
|
64
|
+
).toRenderTo(`
|
|
82
65
|
(additionalParam: number, id: string): string => {}
|
|
83
|
-
|
|
84
|
-
);
|
|
66
|
+
`);
|
|
85
67
|
});
|
|
86
68
|
});
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import { render } from "@alloy-js/core";
|
|
2
|
-
import { d } from "@alloy-js/core/testing";
|
|
3
1
|
import { SourceFile } from "@alloy-js/typescript";
|
|
4
2
|
import type { Operation } from "@typespec/compiler";
|
|
5
3
|
import type { BasicTestRunner } from "@typespec/compiler/testing";
|
|
6
|
-
import { beforeEach, describe, it } from "vitest";
|
|
4
|
+
import { beforeEach, describe, expect, it } from "vitest";
|
|
7
5
|
import { Output } from "../../../src/core/components/output.jsx";
|
|
8
6
|
import { FunctionExpression } from "../../../src/typescript/components/function-expression.jsx";
|
|
9
|
-
import { assertFileContents } from "../../utils.js";
|
|
10
7
|
import { createEmitterFrameworkTestRunner } from "../test-host.js";
|
|
11
8
|
|
|
12
9
|
describe("function expressions with a `type` prop", () => {
|
|
@@ -21,22 +18,17 @@ describe("function expressions with a `type` prop", () => {
|
|
|
21
18
|
@test op getName(id: string): string;
|
|
22
19
|
`)) as { getName: Operation };
|
|
23
20
|
|
|
24
|
-
|
|
21
|
+
expect(
|
|
25
22
|
<Output program={runner.program}>
|
|
26
23
|
<SourceFile path="test.ts">
|
|
27
24
|
<FunctionExpression type={getName}>console.log("Hello!");</FunctionExpression>
|
|
28
25
|
</SourceFile>
|
|
29
26
|
</Output>,
|
|
30
|
-
)
|
|
31
|
-
|
|
32
|
-
assertFileContents(
|
|
33
|
-
res,
|
|
34
|
-
d`
|
|
27
|
+
).toRenderTo(`
|
|
35
28
|
function (id: string): string {
|
|
36
29
|
console.log("Hello!");
|
|
37
30
|
}
|
|
38
|
-
|
|
39
|
-
);
|
|
31
|
+
`);
|
|
40
32
|
});
|
|
41
33
|
|
|
42
34
|
it("creates an async function", async () => {
|
|
@@ -44,20 +36,15 @@ describe("function expressions with a `type` prop", () => {
|
|
|
44
36
|
@test op getName(id: string): string;
|
|
45
37
|
`)) as { getName: Operation };
|
|
46
38
|
|
|
47
|
-
|
|
39
|
+
expect(
|
|
48
40
|
<Output program={runner.program}>
|
|
49
41
|
<SourceFile path="test.ts">
|
|
50
42
|
<FunctionExpression async type={getName} />
|
|
51
43
|
</SourceFile>
|
|
52
44
|
</Output>,
|
|
53
|
-
)
|
|
54
|
-
|
|
55
|
-
assertFileContents(
|
|
56
|
-
res,
|
|
57
|
-
d`
|
|
45
|
+
).toRenderTo(`
|
|
58
46
|
async function (id: string): Promise<string> {}
|
|
59
|
-
|
|
60
|
-
);
|
|
47
|
+
`);
|
|
61
48
|
});
|
|
62
49
|
|
|
63
50
|
it("can append extra parameters with raw params provided", async () => {
|
|
@@ -65,7 +52,7 @@ describe("function expressions with a `type` prop", () => {
|
|
|
65
52
|
@test op getName(id: string): string;
|
|
66
53
|
`)) as { getName: Operation };
|
|
67
54
|
|
|
68
|
-
|
|
55
|
+
expect(
|
|
69
56
|
<Output program={runner.program}>
|
|
70
57
|
<SourceFile path="test.ts">
|
|
71
58
|
<FunctionExpression
|
|
@@ -74,13 +61,8 @@ describe("function expressions with a `type` prop", () => {
|
|
|
74
61
|
/>
|
|
75
62
|
</SourceFile>
|
|
76
63
|
</Output>,
|
|
77
|
-
)
|
|
78
|
-
|
|
79
|
-
assertFileContents(
|
|
80
|
-
res,
|
|
81
|
-
d`
|
|
64
|
+
).toRenderTo(`
|
|
82
65
|
function (additionalParam: number, id: string): string {}
|
|
83
|
-
|
|
84
|
-
);
|
|
66
|
+
`);
|
|
85
67
|
});
|
|
86
68
|
});
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import { render } from "@alloy-js/core";
|
|
2
|
-
import { d } from "@alloy-js/core/testing";
|
|
3
1
|
import { SourceFile } from "@alloy-js/typescript";
|
|
4
2
|
import type { Operation } from "@typespec/compiler";
|
|
5
3
|
import type { BasicTestRunner } from "@typespec/compiler/testing";
|
|
6
|
-
import { beforeEach, describe, it } from "vitest";
|
|
4
|
+
import { beforeEach, describe, expect, it } from "vitest";
|
|
7
5
|
import { Output } from "../../../src/core/components/output.jsx";
|
|
8
6
|
import { FunctionType } from "../../../src/typescript/index.js";
|
|
9
|
-
import { assertFileContents } from "../../utils.js";
|
|
10
7
|
import { createEmitterFrameworkTestRunner } from "../test-host.js";
|
|
11
8
|
|
|
12
9
|
describe("function types with a `type` prop", () => {
|
|
@@ -21,20 +18,15 @@ describe("function types with a `type` prop", () => {
|
|
|
21
18
|
@test op getName(id: string): string;
|
|
22
19
|
`)) as { getName: Operation };
|
|
23
20
|
|
|
24
|
-
|
|
21
|
+
expect(
|
|
25
22
|
<Output program={runner.program}>
|
|
26
23
|
<SourceFile path="test.ts">
|
|
27
24
|
<FunctionType type={getName} />
|
|
28
25
|
</SourceFile>
|
|
29
26
|
</Output>,
|
|
30
|
-
)
|
|
31
|
-
|
|
32
|
-
assertFileContents(
|
|
33
|
-
res,
|
|
34
|
-
d`
|
|
27
|
+
).toRenderTo(`
|
|
35
28
|
(id: string) => string
|
|
36
|
-
|
|
37
|
-
);
|
|
29
|
+
`);
|
|
38
30
|
});
|
|
39
31
|
|
|
40
32
|
it("creates an async function type", async () => {
|
|
@@ -42,20 +34,15 @@ describe("function types with a `type` prop", () => {
|
|
|
42
34
|
@test op getName(id: string): string;
|
|
43
35
|
`)) as { getName: Operation };
|
|
44
36
|
|
|
45
|
-
|
|
37
|
+
expect(
|
|
46
38
|
<Output program={runner.program}>
|
|
47
39
|
<SourceFile path="test.ts">
|
|
48
40
|
<FunctionType async type={getName} />
|
|
49
41
|
</SourceFile>
|
|
50
42
|
</Output>,
|
|
51
|
-
)
|
|
52
|
-
|
|
53
|
-
assertFileContents(
|
|
54
|
-
res,
|
|
55
|
-
d`
|
|
43
|
+
).toRenderTo(`
|
|
56
44
|
(id: string) => Promise<string>
|
|
57
|
-
|
|
58
|
-
);
|
|
45
|
+
`);
|
|
59
46
|
});
|
|
60
47
|
|
|
61
48
|
it("can append extra parameters with raw params provided", async () => {
|
|
@@ -63,19 +50,14 @@ describe("function types with a `type` prop", () => {
|
|
|
63
50
|
@test op getName(id: string): string;
|
|
64
51
|
`)) as { getName: Operation };
|
|
65
52
|
|
|
66
|
-
|
|
53
|
+
expect(
|
|
67
54
|
<Output program={runner.program}>
|
|
68
55
|
<SourceFile path="test.ts">
|
|
69
56
|
<FunctionType type={getName} parameters={[{ name: "additionalParam", type: "number" }]} />
|
|
70
57
|
</SourceFile>
|
|
71
58
|
</Output>,
|
|
72
|
-
)
|
|
73
|
-
|
|
74
|
-
assertFileContents(
|
|
75
|
-
res,
|
|
76
|
-
d`
|
|
59
|
+
).toRenderTo(`
|
|
77
60
|
(additionalParam: number, id: string) => string
|
|
78
|
-
|
|
79
|
-
);
|
|
61
|
+
`);
|
|
80
62
|
});
|
|
81
63
|
});
|