@typespec/emitter-framework 0.9.0-dev.2 → 0.9.0-dev.6
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/csharp/components/class/declaration.d.ts +13 -0
- package/dist/src/csharp/components/class/declaration.d.ts.map +1 -0
- package/dist/src/csharp/components/{class-declaration.js → class/declaration.js} +35 -41
- package/dist/src/csharp/components/class/declaration.test.d.ts +2 -0
- package/dist/src/csharp/components/class/declaration.test.d.ts.map +1 -0
- package/dist/src/csharp/components/class/declaration.test.js +392 -0
- package/dist/src/csharp/components/enum-declaration.d.ts +1 -1
- package/dist/src/csharp/components/enum-declaration.d.ts.map +1 -1
- package/dist/src/csharp/components/enum-declaration.js +12 -9
- package/dist/src/csharp/components/index.d.ts +3 -1
- package/dist/src/csharp/components/index.d.ts.map +1 -1
- package/dist/src/csharp/components/index.js +4 -2
- package/dist/src/csharp/components/property/property.d.ts +15 -0
- package/dist/src/csharp/components/property/property.d.ts.map +1 -0
- package/dist/src/csharp/components/property/property.js +85 -0
- package/dist/src/csharp/components/property/property.test.d.ts +2 -0
- package/dist/src/csharp/components/property/property.test.d.ts.map +1 -0
- package/dist/src/csharp/components/property/property.test.js +117 -0
- package/dist/src/csharp/components/type-expression.d.ts.map +1 -1
- package/dist/src/csharp/components/type-expression.js +15 -1
- package/dist/src/csharp/components/type-expression.test.d.ts +2 -0
- package/dist/src/csharp/components/type-expression.test.d.ts.map +1 -0
- package/dist/src/csharp/components/type-expression.test.js +128 -0
- package/dist/src/csharp/components/utils/doc-comments.d.ts +14 -0
- package/dist/src/csharp/components/utils/doc-comments.d.ts.map +1 -0
- package/dist/src/csharp/components/utils/doc-comments.js +67 -0
- package/dist/src/typescript/components/arrow-function.d.ts +1 -1
- package/dist/src/typescript/components/arrow-function.d.ts.map +1 -1
- package/dist/src/typescript/components/arrow-function.js +2 -1
- package/dist/src/typescript/components/function-expression.d.ts +1 -1
- package/dist/src/typescript/components/function-expression.d.ts.map +1 -1
- package/dist/src/typescript/components/function-expression.js +2 -1
- package/dist/src/typescript/components/function-type.d.ts +1 -1
- package/dist/src/typescript/components/function-type.d.ts.map +1 -1
- package/dist/src/typescript/components/function-type.js +2 -1
- package/dist/test/csharp/components/enum-declaration.test.js +57 -9
- package/dist/test/test-host.d.ts +2 -0
- package/dist/test/test-host.d.ts.map +1 -0
- package/dist/test/test-host.js +5 -0
- package/dist/test/vitest.setup.d.ts +2 -0
- package/dist/test/vitest.setup.d.ts.map +1 -0
- package/dist/test/vitest.setup.js +1 -0
- package/package.json +13 -7
- package/src/csharp/components/class/declaration.test.tsx +401 -0
- package/src/csharp/components/class/declaration.tsx +86 -0
- package/src/csharp/components/enum-declaration.tsx +23 -15
- package/src/csharp/components/index.ts +3 -1
- package/src/csharp/components/property/property.test.tsx +97 -0
- package/src/csharp/components/property/property.tsx +62 -0
- package/src/csharp/components/type-expression.test.tsx +133 -0
- package/src/csharp/components/type-expression.tsx +10 -3
- package/src/csharp/components/utils/doc-comments.tsx +58 -0
- package/src/typescript/components/arrow-function.tsx +1 -1
- package/src/typescript/components/function-expression.tsx +1 -1
- package/src/typescript/components/function-type.tsx +1 -1
- package/test/csharp/components/enum-declaration.test.tsx +50 -9
- package/test/test-host.ts +4 -0
- package/test/vitest.setup.ts +1 -0
- package/tsconfig.json +2 -1
- package/vitest.config.ts +2 -1
- package/dist/src/csharp/components/class-declaration.d.ts +0 -9
- package/dist/src/csharp/components/class-declaration.d.ts.map +0 -1
- package/dist/test/csharp/components/class-declaration.test.d.ts +0 -2
- package/dist/test/csharp/components/class-declaration.test.d.ts.map +0 -1
- package/dist/test/csharp/components/class-declaration.test.js +0 -421
- package/src/csharp/components/class-declaration.tsx +0 -87
- package/test/csharp/components/class-declaration.test.tsx +0 -344
|
@@ -1,344 +0,0 @@
|
|
|
1
|
-
import { render } from "@alloy-js/core";
|
|
2
|
-
import { d } from "@alloy-js/core/testing";
|
|
3
|
-
import * as cs from "@alloy-js/csharp";
|
|
4
|
-
import { Namespace, SourceFile } from "@alloy-js/csharp";
|
|
5
|
-
import { Enum, Interface, Model } from "@typespec/compiler";
|
|
6
|
-
import { BasicTestRunner } from "@typespec/compiler/testing";
|
|
7
|
-
import { beforeEach, describe, it } from "vitest";
|
|
8
|
-
import { Output } from "../../../src/core/index.js";
|
|
9
|
-
import { ClassDeclaration, EnumDeclaration } from "../../../src/csharp/index.js";
|
|
10
|
-
import { createEmitterFrameworkTestRunner } from "../test-host.js";
|
|
11
|
-
import { assertFileContents } from "../utils.js";
|
|
12
|
-
|
|
13
|
-
let runner: BasicTestRunner;
|
|
14
|
-
|
|
15
|
-
beforeEach(async () => {
|
|
16
|
-
runner = await createEmitterFrameworkTestRunner();
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it("renders an empty class declaration", async () => {
|
|
20
|
-
const { TestModel } = (await runner.compile(`
|
|
21
|
-
@test model TestModel {}
|
|
22
|
-
`)) as { TestModel: Model };
|
|
23
|
-
|
|
24
|
-
const res = render(
|
|
25
|
-
<Output program={runner.program}>
|
|
26
|
-
<Namespace name="TestNamespace">
|
|
27
|
-
<SourceFile path="test.cs">
|
|
28
|
-
<ClassDeclaration type={TestModel} />
|
|
29
|
-
</SourceFile>
|
|
30
|
-
</Namespace>
|
|
31
|
-
</Output>,
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
assertFileContents(
|
|
35
|
-
res,
|
|
36
|
-
d`
|
|
37
|
-
namespace TestNamespace
|
|
38
|
-
{
|
|
39
|
-
class TestModel
|
|
40
|
-
{
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
`,
|
|
45
|
-
);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it("renders a class declaration with properties", async () => {
|
|
49
|
-
const { TestModel } = (await runner.compile(`
|
|
50
|
-
@test model TestModel {
|
|
51
|
-
@test Prop1: string;
|
|
52
|
-
@test Prop2: int32;
|
|
53
|
-
}
|
|
54
|
-
`)) as { TestModel: Model };
|
|
55
|
-
|
|
56
|
-
const res = render(
|
|
57
|
-
<Output program={runner.program}>
|
|
58
|
-
<Namespace name="TestNamespace">
|
|
59
|
-
<SourceFile path="test.cs">
|
|
60
|
-
<ClassDeclaration type={TestModel} />
|
|
61
|
-
</SourceFile>
|
|
62
|
-
</Namespace>
|
|
63
|
-
</Output>,
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
assertFileContents(
|
|
67
|
-
res,
|
|
68
|
-
d`
|
|
69
|
-
namespace TestNamespace
|
|
70
|
-
{
|
|
71
|
-
class TestModel
|
|
72
|
-
{
|
|
73
|
-
public string Prop1
|
|
74
|
-
{
|
|
75
|
-
get;
|
|
76
|
-
set;
|
|
77
|
-
}
|
|
78
|
-
public int Prop2
|
|
79
|
-
{
|
|
80
|
-
get;
|
|
81
|
-
set;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
`,
|
|
86
|
-
);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it("can override class name", async () => {
|
|
90
|
-
const { TestModel } = (await runner.compile(`
|
|
91
|
-
@test model TestModel {}
|
|
92
|
-
`)) as { TestModel: Model };
|
|
93
|
-
|
|
94
|
-
const res = render(
|
|
95
|
-
<Output program={runner.program}>
|
|
96
|
-
<Namespace name="TestNamespace">
|
|
97
|
-
<SourceFile path="test.cs">
|
|
98
|
-
<ClassDeclaration type={TestModel} name="CustomClassName" />
|
|
99
|
-
</SourceFile>
|
|
100
|
-
</Namespace>
|
|
101
|
-
</Output>,
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
assertFileContents(
|
|
105
|
-
res,
|
|
106
|
-
d`
|
|
107
|
-
namespace TestNamespace
|
|
108
|
-
{
|
|
109
|
-
class CustomClassName
|
|
110
|
-
{
|
|
111
|
-
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
`,
|
|
115
|
-
);
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it("renders a class with access modifiers", async () => {
|
|
119
|
-
const { TestModel } = (await runner.compile(`
|
|
120
|
-
@test model TestModel {
|
|
121
|
-
}
|
|
122
|
-
`)) as { TestModel: Model };
|
|
123
|
-
|
|
124
|
-
const res = render(
|
|
125
|
-
<Output program={runner.program}>
|
|
126
|
-
<Namespace name="TestNamespace">
|
|
127
|
-
<SourceFile path="test.cs">
|
|
128
|
-
<ClassDeclaration type={TestModel} accessModifier="protected" />
|
|
129
|
-
</SourceFile>
|
|
130
|
-
</Namespace>
|
|
131
|
-
</Output>,
|
|
132
|
-
);
|
|
133
|
-
|
|
134
|
-
assertFileContents(
|
|
135
|
-
res,
|
|
136
|
-
d`
|
|
137
|
-
namespace TestNamespace
|
|
138
|
-
{
|
|
139
|
-
protected class TestModel
|
|
140
|
-
{
|
|
141
|
-
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
`,
|
|
145
|
-
);
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
describe("from an interface", () => {
|
|
149
|
-
it("renders an empty class", async () => {
|
|
150
|
-
const { TestInterface } = (await runner.compile(`
|
|
151
|
-
@test interface TestInterface {
|
|
152
|
-
}
|
|
153
|
-
`)) as { TestInterface: Interface };
|
|
154
|
-
|
|
155
|
-
const res = render(
|
|
156
|
-
<Output program={runner.program}>
|
|
157
|
-
<Namespace name="TestNamespace">
|
|
158
|
-
<SourceFile path="test.cs">
|
|
159
|
-
<ClassDeclaration type={TestInterface} />
|
|
160
|
-
</SourceFile>
|
|
161
|
-
</Namespace>
|
|
162
|
-
</Output>,
|
|
163
|
-
);
|
|
164
|
-
|
|
165
|
-
assertFileContents(
|
|
166
|
-
res,
|
|
167
|
-
d`
|
|
168
|
-
namespace TestNamespace
|
|
169
|
-
{
|
|
170
|
-
class TestInterface
|
|
171
|
-
{
|
|
172
|
-
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
`,
|
|
176
|
-
);
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
it("renders a class with operations", async () => {
|
|
180
|
-
const { TestInterface } = (await runner.compile(`
|
|
181
|
-
@test interface TestInterface {
|
|
182
|
-
op getName(id: string): string;
|
|
183
|
-
}
|
|
184
|
-
`)) as { TestInterface: Interface };
|
|
185
|
-
|
|
186
|
-
const res = render(
|
|
187
|
-
<Output program={runner.program} namePolicy={cs.createCSharpNamePolicy()}>
|
|
188
|
-
<Namespace name="TestNamespace">
|
|
189
|
-
<SourceFile path="test.cs">
|
|
190
|
-
<ClassDeclaration type={TestInterface} />
|
|
191
|
-
</SourceFile>
|
|
192
|
-
</Namespace>
|
|
193
|
-
</Output>,
|
|
194
|
-
);
|
|
195
|
-
|
|
196
|
-
assertFileContents(
|
|
197
|
-
res,
|
|
198
|
-
d`
|
|
199
|
-
namespace TestNamespace
|
|
200
|
-
{
|
|
201
|
-
class TestInterface
|
|
202
|
-
{
|
|
203
|
-
public abstract string GetName(string id) {}
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
`,
|
|
207
|
-
);
|
|
208
|
-
});
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
it("renders a class with model members", async () => {
|
|
212
|
-
const { TestModel, TestReference } = (await runner.compile(`
|
|
213
|
-
@test model TestReference {
|
|
214
|
-
}
|
|
215
|
-
@test model TestModel {
|
|
216
|
-
@test prop1: TestReference;
|
|
217
|
-
}
|
|
218
|
-
`)) as { TestModel: Model; TestReference: Model };
|
|
219
|
-
|
|
220
|
-
const res = render(
|
|
221
|
-
<Output program={runner.program} namePolicy={cs.createCSharpNamePolicy()}>
|
|
222
|
-
<Namespace name="TestNamespace">
|
|
223
|
-
<SourceFile path="test.cs">
|
|
224
|
-
<ClassDeclaration type={TestReference} />
|
|
225
|
-
<hbr />
|
|
226
|
-
<ClassDeclaration type={TestModel} />
|
|
227
|
-
</SourceFile>
|
|
228
|
-
</Namespace>
|
|
229
|
-
</Output>,
|
|
230
|
-
);
|
|
231
|
-
|
|
232
|
-
assertFileContents(
|
|
233
|
-
res,
|
|
234
|
-
d`
|
|
235
|
-
namespace TestNamespace
|
|
236
|
-
{
|
|
237
|
-
class TestReference
|
|
238
|
-
{
|
|
239
|
-
|
|
240
|
-
}
|
|
241
|
-
class TestModel
|
|
242
|
-
{
|
|
243
|
-
public TestReference Prop1
|
|
244
|
-
{
|
|
245
|
-
get;
|
|
246
|
-
set;
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
`,
|
|
251
|
-
);
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
it("renders a class with enum members", async () => {
|
|
255
|
-
const { TestModel, TestEnum } = (await runner.compile(`
|
|
256
|
-
@test enum TestEnum {
|
|
257
|
-
Value1;
|
|
258
|
-
Value2;
|
|
259
|
-
}
|
|
260
|
-
@test model TestModel {
|
|
261
|
-
@test prop1: TestEnum;
|
|
262
|
-
}
|
|
263
|
-
`)) as { TestModel: Model; TestEnum: Enum };
|
|
264
|
-
|
|
265
|
-
const res = render(
|
|
266
|
-
<Output program={runner.program} namePolicy={cs.createCSharpNamePolicy()}>
|
|
267
|
-
<Namespace name="TestNamespace">
|
|
268
|
-
<SourceFile path="test.cs">
|
|
269
|
-
<EnumDeclaration type={TestEnum} />
|
|
270
|
-
<hbr />
|
|
271
|
-
<ClassDeclaration type={TestModel} />
|
|
272
|
-
</SourceFile>
|
|
273
|
-
</Namespace>
|
|
274
|
-
</Output>,
|
|
275
|
-
);
|
|
276
|
-
|
|
277
|
-
assertFileContents(
|
|
278
|
-
res,
|
|
279
|
-
d`
|
|
280
|
-
namespace TestNamespace
|
|
281
|
-
{
|
|
282
|
-
public enum TestEnum
|
|
283
|
-
{
|
|
284
|
-
Value1,
|
|
285
|
-
Value2
|
|
286
|
-
}
|
|
287
|
-
class TestModel
|
|
288
|
-
{
|
|
289
|
-
public TestEnum Prop1
|
|
290
|
-
{
|
|
291
|
-
get;
|
|
292
|
-
set;
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
`,
|
|
297
|
-
);
|
|
298
|
-
});
|
|
299
|
-
|
|
300
|
-
it("renders a class with string enums", async () => {
|
|
301
|
-
const { TestModel, TestEnum } = (await runner.compile(`
|
|
302
|
-
@test enum TestEnum {
|
|
303
|
-
Value1;
|
|
304
|
-
Value2;
|
|
305
|
-
}
|
|
306
|
-
@test model TestModel {
|
|
307
|
-
@test prop1: TestEnum;
|
|
308
|
-
}
|
|
309
|
-
`)) as { TestModel: Model; TestEnum: Enum };
|
|
310
|
-
|
|
311
|
-
const res = render(
|
|
312
|
-
<Output program={runner.program} namePolicy={cs.createCSharpNamePolicy()}>
|
|
313
|
-
<Namespace name="TestNamespace">
|
|
314
|
-
<SourceFile path="test.cs">
|
|
315
|
-
<EnumDeclaration type={TestEnum} />
|
|
316
|
-
<hbr />
|
|
317
|
-
<ClassDeclaration type={TestModel} />
|
|
318
|
-
</SourceFile>
|
|
319
|
-
</Namespace>
|
|
320
|
-
</Output>,
|
|
321
|
-
);
|
|
322
|
-
|
|
323
|
-
assertFileContents(
|
|
324
|
-
res,
|
|
325
|
-
d`
|
|
326
|
-
namespace TestNamespace
|
|
327
|
-
{
|
|
328
|
-
public enum TestEnum
|
|
329
|
-
{
|
|
330
|
-
Value1,
|
|
331
|
-
Value2
|
|
332
|
-
}
|
|
333
|
-
class TestModel
|
|
334
|
-
{
|
|
335
|
-
public TestEnum Prop1
|
|
336
|
-
{
|
|
337
|
-
get;
|
|
338
|
-
set;
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
`,
|
|
343
|
-
);
|
|
344
|
-
});
|