@typespec/emitter-framework 0.11.0-dev.7 → 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.js +2 -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.js +2 -1
- package/dist/src/csharp/components/property/property.js.map +1 -0
- package/dist/src/csharp/components/property/property.test.js +48 -73
- 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/enum/declaration.test.tsx +47 -78
- package/src/csharp/components/property/property.test.tsx +44 -67
- 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,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
|
});
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import { render } from "@alloy-js/core";
|
|
2
|
-
import { d } from "@alloy-js/core/testing";
|
|
3
1
|
import { InterfaceDeclaration, 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 { InterfaceMethod } from "../../../src/typescript/components/interface-method.jsx";
|
|
9
|
-
import { assertFileContents } from "../../utils.js";
|
|
10
7
|
import { createEmitterFrameworkTestRunner, getProgram } from "../test-host.js";
|
|
11
8
|
|
|
12
9
|
describe("interface methods with a `type` prop", () => {
|
|
@@ -21,7 +18,7 @@ describe("interface methods 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
|
<InterfaceDeclaration name="basicInterface">
|
|
@@ -29,16 +26,11 @@ describe("interface methods with a `type` prop", () => {
|
|
|
29
26
|
</InterfaceDeclaration>
|
|
30
27
|
</SourceFile>
|
|
31
28
|
</Output>,
|
|
32
|
-
)
|
|
33
|
-
|
|
34
|
-
assertFileContents(
|
|
35
|
-
res,
|
|
36
|
-
d`
|
|
29
|
+
).toRenderTo(`
|
|
37
30
|
interface basicInterface {
|
|
38
31
|
getName(id: string): string
|
|
39
32
|
}
|
|
40
|
-
|
|
41
|
-
);
|
|
33
|
+
`);
|
|
42
34
|
});
|
|
43
35
|
|
|
44
36
|
it("creates an async interface function", async () => {
|
|
@@ -46,7 +38,7 @@ describe("interface methods with a `type` prop", () => {
|
|
|
46
38
|
@test op getName(id: string): string;
|
|
47
39
|
`)) as { getName: Operation };
|
|
48
40
|
|
|
49
|
-
|
|
41
|
+
expect(
|
|
50
42
|
<Output program={runner.program}>
|
|
51
43
|
<SourceFile path="test.ts">
|
|
52
44
|
<InterfaceDeclaration name="basicInterface">
|
|
@@ -54,16 +46,11 @@ describe("interface methods with a `type` prop", () => {
|
|
|
54
46
|
</InterfaceDeclaration>
|
|
55
47
|
</SourceFile>
|
|
56
48
|
</Output>,
|
|
57
|
-
)
|
|
58
|
-
|
|
59
|
-
assertFileContents(
|
|
60
|
-
res,
|
|
61
|
-
d`
|
|
49
|
+
).toRenderTo(`
|
|
62
50
|
interface basicInterface {
|
|
63
51
|
getName(id: string): Promise<string>
|
|
64
52
|
}
|
|
65
|
-
|
|
66
|
-
);
|
|
53
|
+
`);
|
|
67
54
|
});
|
|
68
55
|
|
|
69
56
|
it("can append extra parameters with raw params provided", async () => {
|
|
@@ -71,7 +58,7 @@ describe("interface methods with a `type` prop", () => {
|
|
|
71
58
|
@test op getName(id: string): string;
|
|
72
59
|
`)) as { getName: Operation };
|
|
73
60
|
|
|
74
|
-
|
|
61
|
+
expect(
|
|
75
62
|
<Output program={runner.program}>
|
|
76
63
|
<SourceFile path="test.ts">
|
|
77
64
|
<InterfaceDeclaration name="basicInterface">
|
|
@@ -83,16 +70,11 @@ describe("interface methods with a `type` prop", () => {
|
|
|
83
70
|
</InterfaceDeclaration>
|
|
84
71
|
</SourceFile>
|
|
85
72
|
</Output>,
|
|
86
|
-
)
|
|
87
|
-
|
|
88
|
-
assertFileContents(
|
|
89
|
-
res,
|
|
90
|
-
d`
|
|
73
|
+
).toRenderTo(`
|
|
91
74
|
interface basicInterface {
|
|
92
75
|
getName(id: string, foo: string): string
|
|
93
76
|
}
|
|
94
|
-
|
|
95
|
-
);
|
|
77
|
+
`);
|
|
96
78
|
});
|
|
97
79
|
|
|
98
80
|
it("can prepend extra parameters with raw params provided", async () => {
|
|
@@ -100,7 +82,7 @@ describe("interface methods with a `type` prop", () => {
|
|
|
100
82
|
@test op getName(id: string): string;
|
|
101
83
|
`)) as { getName: Operation };
|
|
102
84
|
|
|
103
|
-
|
|
85
|
+
expect(
|
|
104
86
|
<Output program={runner.program}>
|
|
105
87
|
<SourceFile path="test.ts">
|
|
106
88
|
<InterfaceDeclaration name="basicInterface">
|
|
@@ -112,16 +94,11 @@ describe("interface methods with a `type` prop", () => {
|
|
|
112
94
|
</InterfaceDeclaration>
|
|
113
95
|
</SourceFile>
|
|
114
96
|
</Output>,
|
|
115
|
-
)
|
|
116
|
-
|
|
117
|
-
assertFileContents(
|
|
118
|
-
res,
|
|
119
|
-
d`
|
|
97
|
+
).toRenderTo(`
|
|
120
98
|
interface basicInterface {
|
|
121
99
|
getName(foo: string, id: string): string
|
|
122
100
|
}
|
|
123
|
-
|
|
124
|
-
);
|
|
101
|
+
`);
|
|
125
102
|
});
|
|
126
103
|
|
|
127
104
|
it("can replace parameters with raw params provided", async () => {
|
|
@@ -129,7 +106,7 @@ describe("interface methods with a `type` prop", () => {
|
|
|
129
106
|
@test op getName(id: string): string;
|
|
130
107
|
`)) as { getName: Operation };
|
|
131
108
|
|
|
132
|
-
|
|
109
|
+
expect(
|
|
133
110
|
<Output program={runner.program}>
|
|
134
111
|
<SourceFile path="test.ts">
|
|
135
112
|
<InterfaceDeclaration name="basicInterface">
|
|
@@ -144,16 +121,11 @@ describe("interface methods with a `type` prop", () => {
|
|
|
144
121
|
</InterfaceDeclaration>
|
|
145
122
|
</SourceFile>
|
|
146
123
|
</Output>,
|
|
147
|
-
)
|
|
148
|
-
|
|
149
|
-
assertFileContents(
|
|
150
|
-
res,
|
|
151
|
-
d`
|
|
124
|
+
).toRenderTo(`
|
|
152
125
|
interface basicInterface {
|
|
153
126
|
getName(foo: string, bar: number): string
|
|
154
127
|
}
|
|
155
|
-
|
|
156
|
-
);
|
|
128
|
+
`);
|
|
157
129
|
});
|
|
158
130
|
|
|
159
131
|
it("can override return type", async () => {
|
|
@@ -161,7 +133,7 @@ describe("interface methods with a `type` prop", () => {
|
|
|
161
133
|
@test op getName(id: string): string;
|
|
162
134
|
`)) as { getName: Operation };
|
|
163
135
|
|
|
164
|
-
|
|
136
|
+
expect(
|
|
165
137
|
<Output program={runner.program}>
|
|
166
138
|
<SourceFile path="test.ts">
|
|
167
139
|
<InterfaceDeclaration name="basicInterface">
|
|
@@ -169,16 +141,11 @@ describe("interface methods with a `type` prop", () => {
|
|
|
169
141
|
</InterfaceDeclaration>
|
|
170
142
|
</SourceFile>
|
|
171
143
|
</Output>,
|
|
172
|
-
)
|
|
173
|
-
|
|
174
|
-
assertFileContents(
|
|
175
|
-
res,
|
|
176
|
-
d`
|
|
144
|
+
).toRenderTo(`
|
|
177
145
|
interface basicInterface {
|
|
178
146
|
getName(id: string): Promise<Record<string, unknown>>
|
|
179
147
|
}
|
|
180
|
-
|
|
181
|
-
);
|
|
148
|
+
`);
|
|
182
149
|
});
|
|
183
150
|
|
|
184
151
|
it("can override method name", async () => {
|
|
@@ -186,7 +153,7 @@ describe("interface methods with a `type` prop", () => {
|
|
|
186
153
|
@test op getName(id: string): string;
|
|
187
154
|
`)) as { getName: Operation };
|
|
188
155
|
|
|
189
|
-
|
|
156
|
+
expect(
|
|
190
157
|
<Output program={runner.program}>
|
|
191
158
|
<SourceFile path="test.ts">
|
|
192
159
|
<InterfaceDeclaration name="basicInterface">
|
|
@@ -194,23 +161,18 @@ describe("interface methods with a `type` prop", () => {
|
|
|
194
161
|
</InterfaceDeclaration>
|
|
195
162
|
</SourceFile>
|
|
196
163
|
</Output>,
|
|
197
|
-
)
|
|
198
|
-
|
|
199
|
-
assertFileContents(
|
|
200
|
-
res,
|
|
201
|
-
d`
|
|
164
|
+
).toRenderTo(`
|
|
202
165
|
interface basicInterface {
|
|
203
166
|
getNameCustom(id: string): string
|
|
204
167
|
}
|
|
205
|
-
|
|
206
|
-
);
|
|
168
|
+
`);
|
|
207
169
|
});
|
|
208
170
|
});
|
|
209
171
|
|
|
210
172
|
describe("interface methods without a `type` prop", () => {
|
|
211
173
|
it("renders a plain interface method", async () => {
|
|
212
174
|
const program = await getProgram("");
|
|
213
|
-
|
|
175
|
+
expect(
|
|
214
176
|
<Output program={program}>
|
|
215
177
|
<SourceFile path="test.ts">
|
|
216
178
|
<InterfaceDeclaration name="basicInterface">
|
|
@@ -222,15 +184,10 @@ describe("interface methods without a `type` prop", () => {
|
|
|
222
184
|
</InterfaceDeclaration>
|
|
223
185
|
</SourceFile>
|
|
224
186
|
</Output>,
|
|
225
|
-
)
|
|
226
|
-
|
|
227
|
-
assertFileContents(
|
|
228
|
-
res,
|
|
229
|
-
d`
|
|
187
|
+
).toRenderTo(`
|
|
230
188
|
interface basicInterface {
|
|
231
189
|
plainMethod(param1: string): number
|
|
232
190
|
}
|
|
233
|
-
|
|
234
|
-
);
|
|
191
|
+
`);
|
|
235
192
|
});
|
|
236
193
|
});
|